Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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()
Exemplo n.º 4
0
    def rescanplaylists(self):
        # we rescan by deleting all playlist first and then reading them in again
        for playlist in hub.request(requests.getplaylists(self.songdbid)):
            log.debug("deleting playlist: %s" % playlist.name)
            self._notify(events.delete_playlist(self.songdbid, playlist))

        self.rescanplaylists_dirtree(configmodule.general.playlistdir or ".")
Exemplo n.º 5
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
Exemplo n.º 6
0
 def getname(self):
     if self.nrsongs is None:
         self.nrsongs = hub.request(requests.getnumberofsongs(self.songdbid, filters=self.filters))
     if self.basedir:
         return  _("[Database: %s (%d)]") % (self.basedir, self.nrsongs)
     else:
         return _("%d databases (%d)") % (len(self.songdbids), self.nrsongs)
Exemplo n.º 7
0
    def run(self):
        # process events, request and subscription requests coming from
        # the client
	while not self.done:
	    type, obj = self._receiveobject()
	    if type == _EVENT:
                log.debug("server: client sends event '%s'" % obj)
		hub.notify(obj, priority=-50)
	    elif type == _REQUEST:
                log.debug("server: requesting %s for client" % `obj`)
		# extract id
		rid, obj = obj
		result = hub.request(obj, priority=-50)
		log.debug("server: got answer %s" % `result`)
		# be careful, handler may not exist anymore?
		try:
		    self.handler._sendobject(_RESULT, (rid, result))
		except:
		    pass
	    elif type == _SUBSCRIBE:
		log.debug("server: client requests subscription for '%s'" % `obj`)
		# be careful, maybe handler does not exists anymore?
		try:
		    self.handler.subscribe(obj)
		except:
		    pass
	    else:
                log.debug("server: servernetworkreceiver exits: type=%s" % type)
		self.done = True
		self.handler.done = True
Exemplo n.º 8
0
    def autoregistersongs(self, event):
        if self.songdbid == event.songdbid:
            oldsongs = set(hub.request(requests.getsongs(self.songdbid)))
            log.info(_("database %r: scanning for songs in %r (currently %d songs registered)") % (self.songdbid, self.basedir, len(oldsongs)))

            # scan for all songs in the filesystem
            log.debug("database %r: searching for new songs" % self.songdbid)
            self.registerdirtree(self.basedir, oldsongs, event.force)

            # remove songs which have not yet been scanned and thus are not accesible anymore
            log.info(_("database %r: removing %d stale songs") % (self.songdbid, len(oldsongs)))
            for song in oldsongs:
                self._notify(events.delete_song(self.songdbid, song))

            nrsongs = hub.request(requests.getnumberofsongs(self.songdbid))
            log.info(_("database %r: rescan finished (%d songs registered)") % (self.songdbid, nrsongs))
Exemplo n.º 9
0
 def getcontentsrecursivesorted(self):
     albums = hub.request(
         requests.getalbums(self.songdbid, filters=self.filters))
     result = []
     for aalbum in albums:
         result.extend(aalbum.getcontentsrecursivesorted())
     return result
Exemplo n.º 10
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()
Exemplo n.º 11
0
 def getcontents(self):
     songs = hub.request(
         requests.getsongs(self.songdbid,
                           filters=self.filters,
                           sort=self.order))
     self.nrsongs = len(songs)
     return songs
Exemplo n.º 12
0
 def getname(self):
     if self.nrsongs is None:
         self.nrsongs = hub.request(
             requests.getnumberofsongs(self.songdbid, filters=self.filters))
     if self.basedir:
         return _("[Database: %s (%d)]") % (self.basedir, self.nrsongs)
     else:
         return _("%d databases (%d)") % (len(self.songdbids), self.nrsongs)
Exemplo n.º 13
0
 def getname(self):
     # XXX make this configurable (note that showing the numbers by default is rather costly)
     if 1:
         return "%s/" % self.description
     else:
         if self.nrsongs is None:
             self.nrsongs = hub.request(requests.getnumberofsongs(self.songdbid, filters=self.filters))
         return "%s (%d)/" % (self.description, self.nrsongs)
Exemplo n.º 14
0
 def getcontentsrecursivesorted(self):
     # we cannot rely on the default implementation since we don't want
     # to have the albums and songs included trice
     artists = hub.request(requests.getartists(self.songdbid, filters=self.filters))
     result = []
     for aartist in artists:
         result.extend(aartist.getcontentsrecursivesorted())
     return result
Exemplo n.º 15
0
 def getcontentsrecursivesorted(self):
     # we cannot rely on the default implementation since we don't want
     # to have the albums and songs included trice
     artists = hub.request(
         requests.getartists(self.songdbid, filters=self.filters))
     result = []
     for aartist in artists:
         result.extend(aartist.getcontentsrecursivesorted())
     return result
Exemplo n.º 16
0
 def getcontents(self):
     songs = []
     while len(songs)<self.maxnr:
         newsongs = hub.request(requests.getsongs(self.songdbid, filters=self.filters, random=True))
         if len(newsongs) > 0:
             songs.extend(newsongs)
         else:
             break
     return songs[:self.maxnr]
Exemplo n.º 17
0
 def getname(self):
     # XXX make this configurable (note that showing the numbers by default is rather costly)
     if 1:
         return "%s/" % self.description
     else:
         if self.nrsongs is None:
             self.nrsongs = hub.request(
                 requests.getnumberofsongs(self.songdbid,
                                           filters=self.filters))
         return "%s (%d)/" % (self.description, self.nrsongs)
Exemplo n.º 18
0
    def __init__(self, win, playerid):
        slist.slist.__init__(self, win, config.playlistwindow.scrollmode=="page")
        self.playerid = playerid
        self.songdbid = "main"
        items, self.ptime, self.ttime, self.autoplaymode, self.playingitem = \
               hub.request(requests.playlistgetcontents())
        self.set(items)
        self._recenter()

        self.win.channel.subscribe(events.playlistchanged, self.playlistchanged)
Exemplo n.º 19
0
 def getcontents(self):
     # do not show artists which only appear in compilations
     filters = self.filters.added(compilationfilter(False))
     aartists = hub.request(requests.getartists(self.songdbid, filters=filters))
     self.nrartists = len(aartists)
     # reset cached value
     self.nrsongs = None
     if config.filelistwindow.virtualdirectoriesattop:
         return self.virtdirs + aartists
     else:
         return aartists + self.virtdirs
Exemplo n.º 20
0
    def showitems(self):
        lines = []
        stats = hub.request(requests.getsongdbmanagerstats())
        indent = " " * 3
        for songdbstats in stats.songdbsstats:
            dbidstring = _("Database %s") % songdbstats.id + ":"
            dbstatstring = _("%d songs, %d albums, %d artists, %d tags") % (
                songdbstats.numberofsongs, songdbstats.numberofalbums,
                songdbstats.numberofartists, songdbstats.numberoftags)

            lines.append((dbidstring, dbstatstring))
            if songdbstats.type == "local":
                dbtypestring = _("local database (db file: %s)") % (
                    songdbstats.dbfile)
            else:
                dbtypestring = _("remote database (server: %s)") % (
                    songdbstats.location)
            lines.append((indent + _("type") + ":", dbtypestring))
            lines.append(
                (indent + _("base directory") + ":", songdbstats.basedir))
            dbcachesizestring = "%dkB" % songdbstats.cachesize
            lines.append((indent + _("cache size") + ":", dbcachesizestring))

        lines.append(("", ""))
        cachestatsstring = _("%d requests, %d / %d objects") % (
            stats.requestcacherequests, stats.requestcachesize,
            stats.requestcachemaxsize)
        if stats.requestcachemaxsize != 0:
            cachestatsstring = cachestatsstring + " (%d%%)" % (
                100 * stats.requestcachesize // stats.requestcachemaxsize)
        lines.append((_("Request cache size") + ":", cachestatsstring))
        totalrequests = stats.requestcachehits + stats.requestcachemisses
        if totalrequests != 0:
            percentstring = " (%d%%)" % (100 * stats.requestcachehits //
                                         totalrequests)
        else:
            percentstring = ""
        lines.append(
            (_("Request cache stats") + ":",
             (_("%d hits / %d requests") %
              (stats.requestcachehits, totalrequests)) + percentstring))

        wc1 = max([len(lc) for lc, rc in lines]) + 1
        if wc1 > 0.6 * self.iw:
            wc1 = int(0.6 * self.iw)
        wc2 = self.iw - wc1
        y = self.iy
        for lc, rc in lines:
            self.move(y, self.ix)
            self.addstr(
                encoding.encode(lc).ljust(wc1)[:wc1], self.colors.description)
            self.addstr(
                encoding.encode(rc).ljust(wc2)[:wc2], self.colors.content)
            y += 1
Exemplo n.º 21
0
 def __getattr__(self, attr):
     # we refuse to fetch the song metadata if an "internal" method name is queried.
     # Thus, we do not interfere with pickling of song instances, etc.
     if attr.startswith("__"):
         raise AttributeError
     if not self.song_metadata:
         self.song_metadata = hub.request(requests.getsong_metadata(self.songdbid, self.id))
     # return metadata if we have been able to fetch it, otherwise return None
     if self.song_metadata:
         return getattr(self.song_metadata, attr)
     else:
         return None
Exemplo n.º 22
0
 def getcontents(self):
     songs = []
     while len(songs) < self.maxnr:
         newsongs = hub.request(
             requests.getsongs(self.songdbid,
                               filters=self.filters,
                               random=True))
         if len(newsongs) > 0:
             songs.extend(newsongs)
         else:
             break
     return songs[:self.maxnr]
Exemplo n.º 23
0
 def getcontents(self):
     # do not show artists which only appear in compilations
     filters = self.filters.added(compilationfilter(False))
     aartists = hub.request(
         requests.getartists(self.songdbid, filters=filters))
     self.nrartists = len(aartists)
     # reset cached value
     self.nrsongs = None
     if config.filelistwindow.virtualdirectoriesattop:
         return self.virtdirs + aartists
     else:
         return aartists + self.virtdirs
Exemplo n.º 24
0
 def __getattr__(self, attr):
     # we refuse to fetch the song metadata if an "internal" method name is queried.
     # Thus, we do not interfere with pickling of song instances, etc.
     if attr.startswith("__"):
         raise AttributeError
     if not self.song_metadata:
         self.song_metadata = hub.request(
             requests.getsong_metadata(self.songdbid, self.id))
     # return metadata if we have been able to fetch it, otherwise return None
     if self.song_metadata:
         return getattr(self.song_metadata, attr)
     else:
         return None
Exemplo n.º 25
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)
Exemplo n.º 26
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)
Exemplo n.º 27
0
    def getcontents(self):
        items = []
        try:
            for name in os.listdir(self.dir):
                try:
                    path = os.path.join(self.dir, name)
                    extension = os.path.splitext(path)[1]
                    if os.path.isdir(path) and os.access(
                            path, os.R_OK | os.X_OK):
                        newitem = filesystemdir(self.songdbid, self.basedir,
                                                path)
                        items.append(newitem)
                    elif extension in metadata.getextensions() and os.access(
                            path, os.R_OK):
                        song = hub.request(
                            requests.autoregisterer_queryregistersong(
                                self.songdbid, path))
                        if song:
                            items.append(song)
                except (IOError, OSError):
                    pass
        except OSError:
            return None

        def cmpitem(x, y):
            if isinstance(x, filesystemdir):
                if isinstance(y, filesystemdir):
                    # sort directories alphabetically
                    return cmp(x.getname(), y.getname())
                else:
                    # sort directories first
                    return -1
            else:
                if isinstance(y, filesystemdir):
                    # sort directories first
                    return 1
                else:
                    # sort songs as usual in db
                    return (x.disknumber and y.disknumber
                            and cmp(x.disknumber, y.disknumber)
                            or x.tracknumber and y.tracknumber
                            and cmp(x.tracknumber, y.tracknumber)
                            or cmp(x.title, y.title))

        items.sort(key=cmp_to_key(cmpitem))
        return items
Exemplo n.º 28
0
    def showitems(self):
        lines = []
        stats = hub.request(requests.getsongdbmanagerstats())
        indent = " "*3
        for songdbstats in stats.songdbsstats:
            dbidstring = _("Database %s") % songdbstats.id + ":"
            dbstatstring = _("%d songs, %d albums, %d artists, %d tags") % (songdbstats.numberofsongs,
									    songdbstats.numberofalbums,
									    songdbstats.numberofartists,
									    songdbstats.numberoftags)

            lines.append((dbidstring, dbstatstring))
            if songdbstats.type == "local":
                dbtypestring = _("local database (db file: %s)") % (songdbstats.dbfile)
            else:
                dbtypestring = _("remote database (server: %s)") % (songdbstats.location)
            lines.append((indent + _("type") + ":", dbtypestring))
            lines.append((indent + _("base directory") + ":", songdbstats.basedir)) 
            dbcachesizestring =  "%dkB" % songdbstats.cachesize
            lines.append((indent + _("cache size") + ":", dbcachesizestring))

        lines.append(("", ""))
        cachestatsstring = _("%d requests, %d / %d objects") % (stats.requestcacherequests, stats.requestcachesize,
                                                                stats.requestcachemaxsize)
        if stats.requestcachemaxsize != 0:
            cachestatsstring = cachestatsstring + " (%d%%)" % (100*stats.requestcachesize//stats.requestcachemaxsize)
        lines.append((_("Request cache size") + ":", cachestatsstring))
        totalrequests = stats.requestcachehits + stats.requestcachemisses
        if totalrequests != 0:
            percentstring = " (%d%%)" % (100*stats.requestcachehits//totalrequests)
        else:
            percentstring = ""
        lines.append((_("Request cache stats") + ":",
                      (_("%d hits / %d requests") % (stats.requestcachehits, totalrequests)) + percentstring))

        wc1 = max([len(lc) for lc, rc in lines]) + 1
        if wc1 > 0.6*self.iw:
            wc1 = int(0.6*self.iw)
        wc2 = self.iw - wc1
        y = self.iy
        for lc, rc in lines:
            self.move(y, self.ix)
            self.addstr(encoding.encode(lc).ljust(wc1)[:wc1], self.colors.description)
            self.addstr(encoding.encode(rc).ljust(wc2)[:wc2], self.colors.content)
            y += 1
Exemplo n.º 29
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
Exemplo n.º 30
0
 def loadplaylisthandler(self, name, key):
     if key == ord("\n"):
         if name[-4:] != ".m3u":
             name = name + ".m3u"
         try:
             path = os.path.join(config.general.playlistdir, name)
             file = open(path, "r", encoding="utf-8")
             self._clear()
             for line in file:
                 if not line.startswith("#"):
                     song = hub.request(requests.autoregisterer_queryregistersong(self.songdbid,
                                                                                  line.strip()))
                     if song:
                         self.append(playlistitem(song))
             file.close()
         except (IOError, OSError):
             pass
         self._updateplaystarttimes()
         self.notifyplaylistchanged()
Exemplo n.º 31
0
 def playlist_requestnextsong(self, request):
     if request.playlistid != self.id:
         raise hub.DenyRequest
     if not request.previous:
         nextitem = self._playnext()
         if not nextitem:
             if self.autoplaymode == "random":
                 # add some randomly selected song to the end of the playlist
                 randomsongs = hub.request(requests.getsongs("main", random=True))
                 if randomsongs:
                     self._addsongs(randomsongs[0:1])
                     nextitem = self._playnext()
             elif self.autoplaymode == "repeat":
                 self._markallunplayed()
                 nextitem = self._playnext()
     else:
         nextitem = self._playprevious()
     self.notifyplaylistchanged()
     return nextitem
Exemplo n.º 32
0
 def playlist_requestnextsong(self, request):
     if request.playlistid != self.id:
         raise hub.DenyRequest
     if not request.previous:
         nextitem = self._playnext()
         if not nextitem:
             if self.autoplaymode == "random":
                 # add some randomly selected song to the end of the playlist
                 randomsongs = hub.request(
                     requests.getsongs("main", random=True))
                 if randomsongs:
                     self._addsongs(randomsongs[0:1])
                     nextitem = self._playnext()
             elif self.autoplaymode == "repeat":
                 self._markallunplayed()
                 nextitem = self._playnext()
     else:
         nextitem = self._playprevious()
     self.notifyplaylistchanged()
     return nextitem
Exemplo n.º 33
0
 def loadplaylisthandler(self, name, key):
     if key == ord("\n"):
         if name[-4:] != ".m3u":
             name = name + ".m3u"
         try:
             path = os.path.join(config.general.playlistdir, name)
             file = open(path, "r", encoding="utf-8")
             self._clear()
             for line in file:
                 if not line.startswith("#"):
                     song = hub.request(
                         requests.autoregisterer_queryregistersong(
                             self.songdbid, line.strip()))
                     if song:
                         self.append(playlistitem(song))
             file.close()
         except (IOError, OSError):
             pass
         self._updateplaystarttimes()
         self.notifyplaylistchanged()
Exemplo n.º 34
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
Exemplo n.º 35
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
Exemplo n.º 36
0
 def getcontents(self):
     items = []
     try:
         for name in os.listdir(self.dir):
             try:
                 path = os.path.join(self.dir, name)
                 extension = os.path.splitext(path)[1]
                 if os.path.isdir(path) and os.access(path, os.R_OK|os.X_OK):
                     newitem = filesystemdir(self.songdbid, self.basedir, path)
                     items.append(newitem)
                 elif extension in metadata.getextensions() and os.access(path, os.R_OK):
                     song = hub.request(requests.autoregisterer_queryregistersong(self.songdbid, path))
                     if song:
                         items.append(song)
             except (IOError, OSError): pass
     except OSError:
         return None
     def cmpitem(x, y):
         if isinstance(x, filesystemdir):
             if isinstance(y, filesystemdir):
                 # sort directories alphabetically
                 return cmp(x.getname(), y.getname())
             else:
                 # sort directories first
                 return -1
         else:
             if isinstance(y, filesystemdir):
                 # sort directories first
                 return 1
             else:
                 # sort songs as usual in db
                 return ( x.disknumber and y.disknumber and cmp(x.disknumber, y.disknumber) or
                          x.tracknumber and y.tracknumber and cmp(x.tracknumber, y.tracknumber) or
                          cmp(x.title, y.title) )
     items.sort(cmp=cmpitem)
     return items
Exemplo n.º 37
0
 def getname(self):
     if self.nrsongs is None:
         self.nrsongs = hub.request(
             requests.getnumberofsongs(self.songdbid, filters=self.filters))
     return "[%s (%d)]/" % (self.name, self.nrsongs)
Exemplo n.º 38
0
 def getcontents(self):
     albums = hub.request(requests.getalbums(self.songdbid, filters=self.filters))
     self.nralbums = len(albums)
     return albums
Exemplo n.º 39
0
 def getname(self):
     if self.nralbums is None:
         self.nralbums = hub.request(requests.getnumberofalbums(self.songdbid, filters=self.filters))
     return "[%s (%d)]/" % (self.name, self.nralbums)
Exemplo n.º 40
0
 def getcontents(self):
     playlists = hub.request(requests.getplaylists(self.songdbid, filters=self.filters))
     self.nrplaylists = len(playlists)
     return playlists
Exemplo n.º 41
0
 def getcontentsrecursiverandom(self):
     return hub.request(
         requests.getsongs(self.songdbid,
                           sort=self.order,
                           filters=self.filters,
                           random=True))
Exemplo n.º 42
0
 def getcontents(self):
     tags = hub.request(
         requests.gettags(self.songdbid, filters=self.filters))
     tags = [tag for tag in tags if tag.id not in self.exclude_tag_ids]
     self.nrtags = len(tags)
     return tags
Exemplo n.º 43
0
 def getcontents(self):
     albums = hub.request(
         requests.getalbums(self.songdbid, filters=self.filters))
     return albums + [songs(self.songdbid, self.name, self.filters)]
Exemplo n.º 44
0
 def getcontents(self):
     songs = hub.request(requests.getsongs(self.songdbid, filters=self.filters, sort=self.order))
     self.nrsongs = len(songs)
     return songs
Exemplo n.º 45
0
 def getcontentsrecursive(self):
     return hub.request(requests.getsongs(self.songdbid, filters=self.filters))
Exemplo n.º 46
0
 def getcontentsrecursivesorted(self):
     albums = hub.request(requests.getalbums(self.songdbid, filters=self.filters))
     result = []
     for aalbum in albums:
         result.extend(aalbum.getcontentsrecursivesorted())
     return result
Exemplo n.º 47
0
 def getcontents(self):
     albums = hub.request(requests.getalbums(self.songdbid, filters=self.filters))
     return albums + [songs(self.songdbid, self.name, self.filters)]
Exemplo n.º 48
0
 def getcontentsrecursiverandom(self):
     return hub.request(
         requests.getlastplayedsongs(self.songdbid,
                                     filters=self.filters,
                                     random=True))
Exemplo n.º 49
0
 def getcontents(self):
     tags = hub.request(requests.gettags(self.songdbid, filters=self.filters))
     tags = [tag for tag in tags if tag.id not in self.exclude_tag_ids]
     self.nrtags = len(tags)
     return tags
Exemplo n.º 50
0
 def getcontentsrecursive(self):
     return hub.request(
         requests.getsongs(self.songdbid, filters=self.filters))
Exemplo n.º 51
0
 def getcontents(self):
     return hub.request(
         requests.getsongs(self.songdbid,
                           filters=self.filters,
                           sort=self.order))
Exemplo n.º 52
0
 def getcontents(self):
     return hub.request(
         requests.getlastplayedsongs(self.songdbid,
                                     sort=self.order,
                                     filters=self.filters))
Exemplo n.º 53
0
 def getcontents(self):
     playlists = hub.request(
         requests.getplaylists(self.songdbid, filters=self.filters))
     self.nrplaylists = len(playlists)
     return playlists
Exemplo n.º 54
0
 def getcontentsrecursiverandom(self):
     return hub.request(requests.getlastplayedsongs(self.songdbid, filters=self.filters, random=True))
Exemplo n.º 55
0
 def getcontents(self):
     albums = hub.request(
         requests.getalbums(self.songdbid, filters=self.filters))
     self.nralbums = len(albums)
     return albums
Exemplo n.º 56
0
 def getcontents(self):
     return hub.request(requests.getsongs(self.songdbid, sort=self.order, filters=self.filters))
Exemplo n.º 57
0
 def getcontents(self):
     songs = hub.request(
         requests.getsongs(self.songdbid,
                           sort=self.order,
                           filters=self.filters))
     return songs
Exemplo n.º 58
0
 def getcontentsrecursiverandom(self):
     return hub.request(requests.getsongs(self.songdbid, sort=self.order, filters=self.filters, random=True))