示例#1
0
    def saveplaylisthandler(self, name, key):
        name = name.strip()
        if key == ord("\n") and name != "" and self.items:
            songs = [
                item.song for item in self.items
                if item.song.songdbid == self.songdbid
            ]
            hub.notify(events.add_playlist(self.songdbid, name, songs))

            # also write playlist to filesystem
            if name[-4:] != ".m3u":
                name = name + ".m3u"
            try:
                name = os.path.join(config.general.playlistdir, name)
                file = open(name, "w", encoding="utf-8")
                for item in self.items:
                    if item.song.url.startswith("file://"):
                        dbstats = hub.request(
                            requests.getdatabasestats(item.song.songdbid))
                        path = os.path.join(dbstats.basedir, item.song.url[7:])
                    else:
                        path = item.song.url
                    file.write("%s\n" % path)
                file.close()
            except (IOError, OSError):
                pass
示例#2
0
文件: item.py 项目: indera/PyTone
 def __init__(self, songdbids, afilters=None, rootdir=False):
     # XXX: as a really dirty hack, we cache the result of getdatabasestats for
     # all databases because we cannot call this request safely later on
     # (we might be handling another request which calls the basedir constructor)
     global _dbstats
     if _dbstats is None:
         _dbstats = {}
         for songdbid in songdbids:
             _dbstats[songdbid] = hub.request(requests.getdatabasestats(songdbid))
     self.name =  _("Song Database")
     self.songdbids = songdbids
     if len(songdbids) == 1:
         self.songdbid = songdbids[0]
         self.type = _dbstats[self.songdbid].type
         self.basedir = _dbstats[self.songdbid].basedir
     else:
         self.songdbid = None
         self.type = "virtual"
         self.basedir = None
     self.id = "basedir"
     if afilters is None:
         # add default filters
         self.filters = filters((podcastfilter(inverted=True),
                                 deletedfilter(inverted=True)))
     else:
         self.filters = afilters
     self.rootdir = rootdir
     self.maxnr = 100
     self.nrartists = None
     self.nrsongs = None
     self._initvirtdirs()
示例#3
0
    def _checksong(self, song):
        # it is ok if the song is contained in a local song database, so we first
        # check whether this is the case.
        # XXX make this behaviour configurable?
        stats = hub.request(requests.getdatabasestats(song.songdbid))
        if isinstance(song, item.song):
            if stats.type == "local":
                return song

        return song

        # XXX do we really need this
        # currently it does not work anymore
        if os.path.isfile(song.path):
            # first we try to access the song via its filesystem path
            return hub.request(
                requests.queryregistersong(self.songdbid, song.path))

        if song.artist != dbitem.UNKNOWN and song.album != dbitem.UNKNOWN:
            # otherwise we use the artist and album tags and try to obtain the song via
            # the database
            songs = hub.request(
                requests.getsongs(self.songdbid,
                                  artist=song.artist,
                                  album=song.album))
            for asong in songs:
                if asong.title == song.title:
                    return asong

        # song not found
        # XXX start transmitting song
        return
示例#4
0
    def _checksong(self, song):
        # it is ok if the song is contained in a local song database, so we first
        # check whether this is the case.
        # XXX make this behaviour configurable?
        stats = hub.request(requests.getdatabasestats(song.songdbid))
        if isinstance(song, item.song):
            if stats.type == "local":
                return song

        return song

        # XXX do we really need this
        # currently it does not work anymore
        if os.path.isfile(song.path):
            # first we try to access the song via its filesystem path
            return hub.request(requests.queryregistersong(self.songdbid, song.path))

        if song.artist != dbitem.UNKNOWN and song.album != dbitem.UNKNOWN:
            # otherwise we use the artist and album tags and try to obtain the song via
            # the database
            songs = hub.request(requests.getsongs(self.songdbid,
                                                  artist=song.artist, album=song.album))
            for asong in songs:
                if asong.title == song.title:
                    return asong

        # song not found
        # XXX start transmitting song
        return
示例#5
0
 def __init__(self, songdbids, afilters=None, rootdir=False):
     # XXX: as a really dirty hack, we cache the result of getdatabasestats for
     # all databases because we cannot call this request safely later on
     # (we might be handling another request which calls the basedir constructor)
     global _dbstats
     if _dbstats is None:
         _dbstats = {}
         for songdbid in songdbids:
             _dbstats[songdbid] = hub.request(
                 requests.getdatabasestats(songdbid))
     self.name = _("Song Database")
     self.songdbids = songdbids
     if len(songdbids) == 1:
         self.songdbid = songdbids[0]
         self.type = _dbstats[self.songdbid].type
         self.basedir = _dbstats[self.songdbid].basedir
     else:
         self.songdbid = None
         self.type = "virtual"
         self.basedir = None
     self.id = "basedir"
     if afilters is None:
         # add default filters
         self.filters = filters(
             (podcastfilter(inverted=True), deletedfilter(inverted=True)))
     else:
         self.filters = afilters
     self.rootdir = rootdir
     self.maxnr = 100
     self.nrartists = None
     self.nrsongs = None
     self._initvirtdirs()
示例#6
0
文件: songdb.py 项目: indera/PyTone
 def getsongdbmanagerstats(self, request):
     songdbsstats = []
     for songdbid in self.songdbids:
         songdbsstats.append(self.songdbhub.request(requests.getdatabasestats(songdbid)))
     return songdbmanagerstats(songdbsstats,
                               self.requestcachesize, self.requestcachemaxsize,
                               len(self.requestcache),
                               self.requestcachehits, self.requestcachemisses)
示例#7
0
 def getsongdbmanagerstats(self, request):
     songdbsstats = []
     for songdbid in self.songdbids:
         songdbsstats.append(
             self.songdbhub.request(requests.getdatabasestats(songdbid)))
     return songdbmanagerstats(songdbsstats, self.requestcachesize,
                               self.requestcachemaxsize,
                               len(self.requestcache),
                               self.requestcachehits,
                               self.requestcachemisses)
示例#8
0
文件: mpg123.py 项目: indera/PyTone
 def _playsong(self, playlistitemorsong, manual):
     """play event.song next"""
     path = None
     if isinstance( playlistitemorsong, services.playlist.playlistitem ):
         url = playlistitemorsong.song.url
         if url.startswith("file://"):
             dbstats = hub.request(requests.getdatabasestats(playlistitemorsong.song.songdbid))
             path = os.path.join(dbstats.basedir, url[7:])
         else:
             path = url
     else:
         log.warning("mpg123 player: song %s not a playlistitem. Not added!" % repr( playlistitemorsong) )
         return
     self.sendmpg123("L %s" % path)
     self.framespersecond = None
     self.playbackinfo.updatesong(song)
示例#9
0
 def _playsong(self, playlistitemorsong, manual):
     """play event.song next"""
     path = None
     if isinstance( playlistitemorsong, services.playlist.playlistitem ):
         url = playlistitemorsong.song.url
         if url.startswith("file://"):
             dbstats = hub.request(requests.getdatabasestats(playlistitemorsong.song.songdbid))
             path = os.path.join(dbstats.basedir, url[7:])
         else:
             path = url
     else:
         log.warning("mpg123 player: song %s not a playlistitem. Not added!" % repr( playlistitemorsong) )
         return
     self.sendmpg123("L %s" % path)
     self.framespersecond = None
     self.playbackinfo.updatesong(song)
示例#10
0
    def __init__(self, song, outrate):
        self.outrate = outrate
        self.default_rate = outrate

        try:
            decoder = getdecoder(song.type)
        except:
            log.error("No decoder for song type '%r' registered " % song.type)
            raise RuntimeError("No decoder for song type '%r' registered " %
                               song.type)

        url = encoding.encode_path(song.url)
        if url.startswith("file://"):
            dbstats = hub.request(requests.getdatabasestats(song.songdbid))
            if not dbstats.basedir:
                log.error(
                    "Currently only support for locally stored songs available"
                )
                raise RuntimeError(
                    "Currently only support for locally stored songs available"
                )
            path = os.path.join(dbstats.basedir, url[7:])
            self.decodedfile = decoder(path)
        else:
            log.error(
                "Currently only support for locally stored songs available")
            raise RuntimeError(
                "Currently only support for locally stored songs available")

        # Use the total time given by the decoder library and not the one
        # stored in the database. The former one turns out to be more precise
        # for some VBR songs.
        self.ttime = max(self.decodedfile.ttime(), song.length)

        # sometimes the mad library seems to report a wrong sample rate,
        # so use the one stored in the database
        if song.samplerate:
            self.samplerate = song.samplerate
        else:
            self.samplerate = self.decodedfile.samplerate()

        self.buff = self.last_l = self.last_r = None
        self.buffpos = 0
        self.ptime = 0
示例#11
0
    def saveplaylisthandler(self, name, key):
        name = name.strip()
        if key == ord("\n") and name != "" and self.items:
            songs = [item.song for item in self.items if item.song.songdbid == self.songdbid ]
            hub.notify(events.add_playlist(self.songdbid, name, songs))

            # also write playlist to filesystem
            if name[-4:] != ".m3u":
                name = name + ".m3u"
            try:
                name = os.path.join(config.general.playlistdir, name)
                file = open(name, "w", encoding="utf-8")
                for item in self.items:
                    if item.song.url.startswith("file://"):
                        dbstats = hub.request(requests.getdatabasestats(item.song.songdbid))
                        path = os.path.join(dbstats.basedir, item.song.url[7:])
                    else:
                        path = item.song.url
                    file.write("%s\n" % path)
                file.close()
            except (IOError, OSError):
                pass
示例#12
0
文件: decoder.py 项目: indera/PyTone
    def __init__(self, song, outrate):
        self.outrate = outrate
        self.default_rate = outrate

        try:
            decoder = getdecoder(song.type)
        except:
            log.error("No decoder for song type '%r' registered "% song.type)
            raise RuntimeError("No decoder for song type '%r' registered "% song.type)

        url = encoding.encode_path(song.url)
        if url.startswith("file://"):
            dbstats = hub.request(requests.getdatabasestats(song.songdbid))
            if not dbstats.basedir:
                log.error("Currently only support for locally stored songs available")
                raise RuntimeError("Currently only support for locally stored songs available")
            path = os.path.join(dbstats.basedir, url[7:])
            self.decodedfile = decoder(path)
        else:
            log.error("Currently only support for locally stored songs available")
            raise RuntimeError("Currently only support for locally stored songs available")

        # Use the total time given by the decoder library and not the one
        # stored in the database. The former one turns out to be more precise
        # for some VBR songs.
        self.ttime = max(self.decodedfile.ttime(), song.length)

        # sometimes the mad library seems to report a wrong sample rate,
        # so use the one stored in the database
        if song.samplerate:
            self.samplerate = song.samplerate
        else:
            self.samplerate = self.decodedfile.samplerate()

        self.buff = self.last_l = self.last_r = None
        self.buffpos = 0
        self.ptime = 0