Esempio n. 1
0
 def browse(self, uri):
     logger.debug('Browsing Beets at: %s', uri)
     path, item_id = parse_uri(uri, uri_prefix=self.root_directory.uri)
     if path is None:
         logger.error('Beets - failed to parse uri: %s', uri)
         return []
     elif uri == self.root_directory.uri:
         # top level - show the categories
         refs = [browser.ref for browser in self.category_browsers]
         refs.sort(key=lambda item: item.name)
         return refs
     elif path == 'album':
         # show an album
         try:
             album_id = int(item_id)
         except ValueError:
             logger.error('Beets - invalid album ID in URI: %s', uri)
             return []
         tracks = self.remote.get_tracks_by([('album_id', album_id)], True,
                                            ['track+'])
         return [models.Ref.track(uri=track.uri, name=track.name)
                 for track in tracks]
     else:
         # show a generic category directory
         for browser in self.category_browsers:
             if path == parse_uri(browser.ref.uri,
                                  uri_prefix=self.root_directory.uri)[0]:
                 if item_id is None:
                     return browser.get_toplevel()
                 else:
                     return browser.get_directory(item_id)
         else:
             logger.error('Beets - Invalid browse URI: %s / %s', uri, path)
             return []
Esempio n. 2
0
 def browse(self, uri):
     logger.debug('Browsing Beets at: %s', uri)
     path, item_id = parse_uri(uri, uri_prefix=self.root_directory.uri)
     if path is None:
         logger.error('Beets - failed to parse uri: %s', uri)
         return []
     elif uri == self.root_directory.uri:
         # top level - show the categories
         refs = [browser.ref for browser in self.category_browsers]
         refs.sort(key=lambda item: item.name)
         return refs
     elif path == 'album':
         # show an album
         try:
             album_id = int(item_id)
         except ValueError:
             logger.error('Beets - invalid album ID in URI: %s', uri)
             return []
         tracks = self.remote.get_tracks_by([('album_id', album_id)], True,
                                            ['track+'])
         return [models.Ref.track(uri=track.uri, name=track.name)
                 for track in tracks]
     else:
         # show a generic category directory
         for browser in self.category_browsers:
             if path == parse_uri(browser.ref.uri,
                                  uri_prefix=self.root_directory.uri)[0]:
                 if item_id is None:
                     return browser.get_toplevel()
                 else:
                     return browser.get_directory(item_id)
         else:
             logger.error('Invalid browse URI: %s / %s', uri, path)
             return []
Esempio n. 3
0
 def lookup(self, uri=None, uris=None):
     logger.debug('Beets lookup: %s', uri or uris)
     if uri:
         # the older method (mopidy < 1.0): return a list of tracks
         # handle one or more tracks given with multiple semicolons
         logger.debug('Beets lookup: %s', uri)
         path, item_id = parse_uri(uri, uri_prefix=self.root_directory.uri)
         if path == 'track':
             tracks = [self.remote.get_track(item_id)]
         elif path == 'album':
             tracks = self.remote.get_tracks_by([('album_id', item_id)],
                                                True, ('disc+', 'track+'))
         elif path == 'artist':
             artist_tracks = self.remote.get_tracks_by(
                 [('artist', item_id)], True, [])
             composer_tracks = self.remote.get_tracks_by(
                 [('composer', item_id)], True, [])
             # Append composer tracks to the artist tracks (unique items).
             tracks = list(set(artist_tracks + composer_tracks))
             tracks.sort(key=lambda t: (t.date, t.disc_no, t.track_no))
         else:
             logger.info('Unknown Beets lookup URI: %s', uri)
             tracks = []
         # remove occourences of None
         return [track for track in tracks if track]
     else:
         # the newer method (mopidy>=1.0): return a dict of uris and tracks
         return {uri: self.lookup(uri=uri) for uri in uris}
Esempio n. 4
0
 def lookup(self, uri=None, uris=None):
     logger.debug("Beets lookup: %s", uri or uris)
     if uri:
         # the older method (mopidy < 1.0): return a list of tracks
         # handle one or more tracks given with multiple semicolons
         logger.debug("Beets lookup: %s", uri)
         path, item_id = parse_uri(uri, uri_prefix=self.root_directory.uri)
         if path == "track":
             tracks = [self.remote.get_track(item_id)]
         elif path == "album":
             tracks = self.remote.get_tracks_by([("album_id", item_id)],
                                                True, ("disc+", "track+"))
         elif path == "artist":
             artist_tracks = self.remote.get_tracks_by(
                 [("artist", item_id)], True, [])
             composer_tracks = self.remote.get_tracks_by(
                 [("composer", item_id)], True, [])
             # Append composer tracks to the artist tracks (unique items).
             tracks = list(set(artist_tracks + composer_tracks))
             tracks.sort(key=lambda t: (t.date, t.disc_no, t.track_no))
         else:
             logger.info("Unknown Beets lookup URI: %s", uri)
             tracks = []
         # remove occourences of None
         return [track for track in tracks if track]
     else:
         # the newer method (mopidy>=1.0): return a dict of uris and tracks
         return {uri: self.lookup(uri=uri) for uri in uris}