Esempio n. 1
0
 def delete_song(self, event):
     if event.songdbid == self.id:
         try:
             self._delete_song(event.song)
         except:
             log.debug_traceback()
             pass
Esempio n. 2
0
 def _receiveobject(self):
     line = self.rfile.readline()
     # atype = type
     if not line: return None, None
     try:
         log.debug("server: request type received")
         type, bytes = line.split()
         bytes = int(bytes)
         log.debug("type=%s, bytes=%d" % (type, bytes))
         if type != _SENDFILE:
             objbytes = self.rfile.read(bytes + 2)
             log.debug(str(objbytes.__class__))
             objbytes = objbytes[:-2]
             log.debug("server: object received")
             obj = loads(objbytes)
             log.debug("server receive: type=%s object=%s" %
                       (type, repr(obj)))
             return (type, obj)
         else:
             # we handle send file requests separately
             filename = self.rfile.readline()
             tmpfilename = tempfile.mktemp()
             bytes = bytes - len(filename) - 2
             tmpfile = open(tmpfilename, "w")
             while bytes > 2:
                 rbytes = min(bytes, 4096)
                 tmpfile.write(self.rfile.read(rbytes))
                 bytes -= rbytes
             self.rfile.read(2)
             return (type, tmpfilename)
     except Exception as e:
         log.debug("exception '%s' occured during _receiveobject" % e)
         log.debug_traceback()
         return (None, None)
Esempio n. 3
0
 def opendevice(self):
     errorlogged = False
     while self.audiodev is None:
         try:
             if self.aodevice == "oss":
                 if ossaudiodev_present:
                     self.audiodev = ossaudiodev(self.aooptions["dsp"],
                                                 self.rate)
                     log.debug("ossaudiodev audio device opened")
                 else:
                     self.audiodev = aoaudiodev(self.aodevice,
                                                rate=self.rate,
                                                options=self.aooptions)
                     log.debug("ao audio device opened")
             else:
                 self.audiodev = aoaudiodev(self.aodevice,
                                            rate=self.rate,
                                            options=self.aooptions)
                 log.debug("ao audio device opened")
         except Exception as e:
             if not errorlogged:
                 log.debug_traceback()
                 log.error(_('cannot open audio device: error "%s"') % e)
                 errorlogged = True
             time.sleep(1)
Esempio n. 4
0
 def _receiveobject(self):
     line = self.rfile.readline()
     # atype = type
     if not line: return None, None
     try:
         log.debug("server: request type received")
         type, bytes = line.split()
         bytes = int(bytes)
         log.debug("type=%s, bytes=%d" %( type, bytes))
         if type != _SENDFILE:
             objbytes = self.rfile.read(bytes+2)
             log.debug(str(objbytes.__class__))
             objbytes = objbytes[:-2]
             log.debug("server: object received")
             obj = loads(objbytes)
             log.debug("server receive: type=%s object=%s" % (type, repr(obj)))
             return (type, obj)
         else:
             # we handle send file requests separately
             filename = self.rfile.readline()
             tmpfilename = tempfile.mktemp()
             bytes = bytes-len(filename)-2
             tmpfile = open(tmpfilename, "w")
             while bytes>2:
                 rbytes = min(bytes, 4096)
                 tmpfile.write(self.rfile.read(rbytes))
                 bytes -= rbytes
             self.rfile.read(2)
             return (type, tmpfilename)
     except Exception as e:
         log.debug("exception '%s' occured during _receiveobject" % e)
         log.debug_traceback()
         return (None, None)
Esempio n. 5
0
 def add_song(self, event):
     if event.songdbid == self.id:
         try:
             self._add_song(event.song)
         except KeyError:
             log.debug_traceback()
             pass
Esempio n. 6
0
 def gettag_id(self, request):
     if self.id != request.songdbid:
         raise hub.DenyRequest
     try:
         return self._gettag_id(request.tag_name)
     except:
         log.debug_traceback()
         return None
Esempio n. 7
0
 def _sendobject(self, type, obj):
     log.debug("client send: type=%s object=%s" % (type, obj))
     try:
         objbytes = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
     except Exception as e:
         log.debug_traceback()
     self.wfile.write(b"%b %d\r\n%b\r\n" % (type, len(objbytes), objbytes))
     self.wfile.flush()
Esempio n. 8
0
 def getalbums(self, request):
     if self.id != request.songdbid:
         raise hub.DenyRequest
     try:
         return self._getalbums(request.filters)
     except KeyError:
         log.debug_traceback()
         return []
Esempio n. 9
0
 def _sendobject(self, type, obj):
     log.debug("client send: type=%s object=%s" % (type, obj))
     try:
         objbytes = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
     except Exception as e:
         log.debug_traceback()
     self.wfile.write(b"%b %d\r\n%b\r\n" % (type, len(objbytes), objbytes))
     self.wfile.flush()
Esempio n. 10
0
 def getsongs(self, request):
     if self.id != request.songdbid:
         raise hub.DenyRequest
     try:
         return self._getsongs(request.sort, request.filters)
     except (KeyError, AttributeError, TypeError):
         log.debug_traceback()
         return []
Esempio n. 11
0
 def run(self):
     # main loop of the service
     while not self.done:
         # process events and catch all unhandled exceptions
         try:
             self.work()
         except Exception, e:
             log.debug_traceback()
             self.resetafterexception()
Esempio n. 12
0
def metadata_from_file(relpath, basedir, tracknrandtitlere, postprocessors):
    """ create song metadata from given file with relative (to basedir) path 
    relpath applying the given list of postprocessors"""

    path = os.path.normpath(os.path.join(basedir, relpath))
    if not os.access(path, os.R_OK):
        raise IOError("cannot read song")

    md = song_metadata()
    md.size = os.stat(path).st_size
    md.type = gettype(os.path.splitext(path)[1])

    read_path_metadata(md, relpath, tracknrandtitlere)

    try:
        metadatadecoder = getmetadatadecoder(md.type)
    except:
        raise RuntimeError("Support for %s songs not enabled" % md.type)

    try:
        log.debug("reading metadata for %r" % path)
        metadatadecoder(md, path)
        log.debug("metadata for %r read successfully" % path)
    except:
        log.warning("could not read metadata for %r" % path)
        log.debug_traceback()

    # strip leading and trailing whitespace
    if md.title:
        md.title = md.title.strip()
    if md.artist:
        md.artist = md.artist.strip()
    if md.album:
        md.album = md.album.strip()

    if md.length is None:
        log.warning("could not read length of song %r" % path)
        raise RuntimeError("could not read length of song %r" % path)

    for postprocessor_name in postprocessors:
        try:
            get_metadata_postprocessor(postprocessor_name)(md)
        except:
            log.warning("Postprocessing of song %r metadata with '%r' failed" % (path, postprocessor_name))
            log.debug_traceback()

    # set album_artist if not present
    if md.album_artist is None:
        if md.compilation: 
            md.album_artist = VARIOUS
        else:
            md.album_artist = md.artist

    return md
Esempio n. 13
0
 def run(self):
     while not self.done:
         try:
             if self.ispaused:
                 self.restart.wait()
                 self.restart.clear()
             buff, bytes = self.queue.get(1)
             if buff != 0 and bytes != 0:
                 audiodev = self.audiodev
                 while audiodev is None:
                     self.opendevice()
                     audiodev = self.audiodev
                 audiodev.play(buff, bytes)
         except:
             log.warning("exception occured in bufferedaudiodev")
             log.debug_traceback()
Esempio n. 14
0
 def run(self):
     while not self.done:
         try:
             if self.ispaused:
                 self.restart.wait()
                 self.restart.clear()
             buff, bytes = self.queue.get(1)
             if buff != 0 and bytes != 0:
                 audiodev = self.audiodev
                 while audiodev is None:
                     self.opendevice()
                     audiodev = self.audiodev
                 audiodev.play(buff, bytes)
         except:
             log.warning("exception occured in bufferedaudiodev")
             log.debug_traceback()
Esempio n. 15
0
 def opendevice(self):
     errorlogged = False
     while self.audiodev is None:
         try:
             if self.aodevice=="oss":
                 if ossaudiodev_present:
                     self.audiodev = ossaudiodev(self.aooptions["dsp"], self.rate)
                     log.debug("ossaudiodev audio device opened")
                 else:
                     self.audiodev = aoaudiodev(self.aodevice, rate=self.rate, options=self.aooptions)
                     log.debug("ao audio device opened")
             else:
                 self.audiodev = aoaudiodev(self.aodevice, rate=self.rate, options=self.aooptions)
                 log.debug("ao audio device opened")
         except Exception, e:
             if not errorlogged:
                 log.debug_traceback()
                 log.error(_('cannot open audio device: error "%s"') % e)
                 errorlogged = True
             time.sleep(1)
Esempio n. 16
0
    def _getsong_metadata(self, song_id):
        """return song entry with given song_id"""
        log.debug("Querying song metadata for id=%r" % song_id)
        try:
            r = self.con.execute(self._song_select, [song_id]).fetchone()
            if r:
                # fetch album artist
                if r["album_artist_id"] is not None:
                    select = """SELECT name FROM artists WHERE id = ?"""
                    album_artist = self.con.execute(select, (r["album_artist_id"],)).fetchone()["name"]
                else:
                    album_artist = None

                # fetch tags
                tags = []
                for tr in self.con.execute(self._song_tags_select, [song_id]):
                    tags.append(tr["name"])

                # fetch playstats
                dates_played = []
                for tr in self.con.execute(self._song_playstats_select, [song_id]):
                    dates_played.append(tr["date_played"])

                # generate and populate metadata
                md = metadata.song_metadata()
                for field in songcolumns_plain:
                    md[field] = r[field]
                md.album = r["album"]
                md.artist = r["artist"]
                md.album_artist = album_artist
                md.tags = tags
                md.comments = loads(r["comments"])
                md.lyrics = loads(r["lyrics"])
                md.dates_played = dates_played
                return md
            else:
                log.debug("Song '%d' not found in database" % song_id)
                return None
        except:
            log.debug_traceback()
            return None
Esempio n. 17
0
 def rescansong(self, song, force):
     if song.songdbid != self.songdbid:
         log.debug("Trying to rescan song in wrong database")
         return
     if song.song_metadata is None:
         song.song_metadata = self._request(requests.getsong_metadata(self.songdbid, song.id))
         if song.song_metadata is None:
             log.debug("Song not found in database")
             return
     if not song.url.startswith("file://"):
         log.debug("Can only rescan local files")
         return
     relpath = encoding.encode_path(song.url[7:])
     path = os.path.join(self.basedir, relpath)
     try:
         if force or song_metadata.date_updated < os.stat(path).st_mtime:
             newsong_metadata = metadata.metadata_from_file(relpath, self.basedir, self.tracknrandtitlere, self.postprocessors)
             song.song_metadata.update(newsong_metadata)
             self._notify(events.update_song(self.songdbid, song))
     except (IOError, OSError):
         log.debug_traceback()
         # if anything goes wrong, we delete the song from the database
         self._notify(events.delete_song(self.songdbid, song))
Esempio n. 18
0
            # to the two possible locations. Setting sys.path correspondingly
            # would not work, however, since then the plugin could not
            # import its needed modules. 
            fp, pathname, description = imp.find_module(name, pluginpath)
            pluginmodule = imp.load_module(name, fp, pathname, description)
            # 
            # process configuration of plugin
            pluginconfig = pluginmodule.config
            if pluginconfig is not None:
                config.readconfigsection("plugin.%s" % name, pluginconfig)
                config.finishconfigsection(pluginconfig)
                pluginconfig = pluginconfig()
            plugins.append((pluginmodule, pluginconfig))
        except Exception, e:
             log.error(_("Cannot load plugin '%s': %s") % (name, e))
             log.debug_traceback()

    # initialize song database manager and start it immediately so
    # that it can propagate quit events in case something goes wrong
    # when setting up the databases
    songdbmanager = services.songdb.songdbmanager()
    songdbmanager.start()

    # song databases
    songdbids = []
    for songdbname in config.database.getsubsections():
        try:
            songdbid = songdbmanager.addsongdb(songdbname, config.database[songdbname])
            if songdbid:
                songdbids.append(songdbid)
        except Exception, e:
Esempio n. 19
0
 def _sendobject(self, type, obj):
     log.debug("client send: type=%s object=%s" % (type, obj))
     try:
         objstring = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL)
     except Exception, e:
         log.debug_traceback()
Esempio n. 20
0
                    break
            else:
                log.error(_("Cannot find plugin '%s'") % name)
                continue

            # process configuration of plugin
            pluginconfig = pluginmodule.config
            if pluginconfig is not None:
                config.readconfigsection("plugin.%s" % name, pluginconfig)
                config.finishconfigsection(pluginconfig)
                pluginconfig = pluginconfig()
            plugins.append((pluginmodule, pluginconfig))
            log.info(_("Plugin '%s' loaded" % name))
        except Exception as e:
            log.error(_("Cannot load plugin '%s': %s") % (name, e))
            log.debug_traceback()

    # initialize song database manager and start it immediately so
    # that it can propagate quit events in case something goes wrong
    # when setting up the databases
    songdbmanager = services.songdb.songdbmanager()
    songdbmanager.start()

    # song databases
    songdbids = []
    for songdbname in config.database.getsubsections():
        try:
            songdbid = songdbmanager.addsongdb(songdbname,
                                               config.database[songdbname])
            if songdbid:
                songdbids.append(songdbid)
Esempio n. 21
0
def initplayer(id, config):
    """ initialize player with id defined by config
    return id (or None if player is turned off)
    """

    # only the first player has a playlist
    if id == "main":
        playlistid = "main"
    else:
        playlistid = None

    type = config.type
    if type=="off":
        return None
    elif type=="internal":
        import players.internal
        driver = config.driver
        if driver in ("alsa09", "alsa"):
            aooptions = {"dev": config.device}
        elif driver=="oss":
            aooptions = {"dsp": config.device}
        elif driver=="sun":
            aooptions = {"dev": config.device}
        else:
            aooptions = {}
        # add options given by user in config file
        for aooption in config.aooptions.split():
            key, value = aooption.split("=")
            aooptions[key] = value
        try:
            p = players.internal.player(id,
                                        playlistid,
                                        autoplay=config.autoplay,
                                        aodevice=driver,
                                        aooptions=aooptions,
                                        bufsize=config.bufsize,
                                        crossfading=config.crossfading,
                                        crossfadingstart=config.crossfadingstart,
                                        crossfadingduration=config.crossfadingduration,
                                        )
        except:
            log.debug_traceback()
            raise RuntimeError("Cannot initialize %s player: type=internal, device=%s" % (id, config.device))
    elif type=="xmms":
        import players.xmmsplayer
        try:
            p = players.xmmsplayer.player(id,
                                          playlistid,
                                          autoplay=config.autoplay,
                                          session=config.session,
                                          noqueue=config.noqueue)
        except:
            log.debug_traceback()
            raise RuntimeError("Cannot initialize %s player: type=xmms, session=%d" % (id, config.session))
    elif type=="mpg123":
        import players.mpg123
        try:
            p = players.mpg123.player(id,
                                      playlistid,
                                      autoplay=config.autoplay,
                                      cmdline=config.cmdline)

        except:
            log.debug_traceback()
            raise RuntimeError("Cannot initialize %s player: type=mpg123, cmdline=%s" % (id, config.cmdline))
    elif type=="remote":
        import players.remote
        try:
            p = players.remote.player(id, playlistid, config.networklocation)
        except:
            log.debug_traceback()
            raise RuntimeError("Cannot initialize %s player: type=remote, location=%s" % (id, config.networklocation))

    p.setName("player thread (id=%s)" % id)

    if type != "remote" and id == "main":
        services.playlist.initplaylist(id, id, id)

    # start player only after the playlist service has been started since
    # playlist requests may already be issued during the player startup
    p.start()

    return id