From 68d469bdebaf1238cc77df91f73b42eec4592cb2 Mon Sep 17 00:00:00 2001 From: hhm Date: Sun, 12 Feb 2017 15:50:41 -0500 Subject: [PATCH 01/13] B"H use subsonic dir api for browsing --- mopidy_subidy/library.py | 15 +++++++++------ mopidy_subidy/subsonic_api.py | 34 +++++++++++++++++++++++++++++++--- mopidy_subidy/uri.py | 10 ++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index f7460bb..6d01ba3 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -21,6 +21,12 @@ class SubidyLibraryProvider(backend.LibraryProvider): def browse_artists(self): return self.subsonic_api.get_artists_as_refs() + def browse_rootdirs(self): + return self.subsonic_api.get_rootdirs_as_refs() + + def browse_diritems(self, directory_id): + return self.subsonic_api.get_diritems_as_refs(directory_id) + def lookup_song(self, song_id): return self.subsonic_api.get_song_by_id(song_id) @@ -31,13 +37,10 @@ class SubidyLibraryProvider(backend.LibraryProvider): return self.subsonic_api.get_artist_by_id(artist_id) def browse(self, browse_uri): - type = uri.get_type(browse_uri) if browse_uri == uri.ROOT_URI: - return self.browse_artists() - if type == uri.ARTIST: - return self.browse_albums(uri.get_artist_id(browse_uri)) - if type == uri.ALBUM: - return self.browse_songs(uri.get_album_id(browse_uri)) + return self.browse_rootdirs() + else: + return self.browse_diritems(uri.get_directory_id(browse_uri)) def lookup_one(self, lookup_uri): type = uri.get_type(lookup_uri) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index 3aaa7f2..c8b6a0c 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -90,12 +90,27 @@ class SubsonicApi(): albums=[self.raw_album_to_album(album) for album in result.get('album') or []], tracks=[self.raw_song_to_track(song) for song in result.get('song') or []]) - def get_raw_artists(self): + try: + response = self.connection.getArtists() + except Exception as e: + logger.warning('Connecting to subsonic failed when loading list of artists.') + return [] + if response.get('status') != RESPONSE_OK: + logger.warning('Got non-okay status code from subsonic: %s' % response.get('status')) + return [] + letters = response.get('artists').get('index') + if letters is not None: + artists = [artist for letter in letters for artist in letter.get('artist') or []] + return artists + logger.warning('Subsonic does not seem to have any artists in it\'s library.') + return [] + + def get_raw_rootdirs(self): try: response = self.connection.getIndexes() except Exception as e: - logger.warning('Connecting to subsonic failed when loading list of artists.') + logger.warning('Connecting to subsonic failed when loading list of rootdirs.') return [] if response.get('status') != RESPONSE_OK: logger.warning('Got non-okay status code from subsonic: %s' % response.get('status')) @@ -104,7 +119,7 @@ class SubsonicApi(): if letters is not None: artists = [artist for letter in letters for artist in letter.get('artist') or []] return artists - logger.warning('Subsonic does not seem to have any artists in it\'s library.') + logger.warning('Subsonic does not seem to have any rootdirs in its library.') return [] def get_song_by_id(self, song_id): @@ -202,6 +217,12 @@ class SubsonicApi(): def get_artists_as_refs(self): return [self.raw_artist_to_ref(artist) for artist in self.get_raw_artists()] + def get_rootdirs_as_refs(self): + return [self.raw_directory_to_ref(rootdir) for rootdir in self.get_raw_rootdirs()] + + def get_diritems_as_refs(self, directory_id): + return [(self.raw_directory_to_ref(diritem) if diritem.get('isDir') else self.raw_song_to_ref(diritem)) for diritem in self.get_raw_dir(directory_id)] + def get_artists_as_artists(self): return [self.raw_artist_to_artist(artist) for artist in self.get_raw_artists()] @@ -263,6 +284,13 @@ class SubsonicApi(): name=album.get('artist'), uri=uri.get_artist_uri(album.get('artistId')))]) + def raw_directory_to_ref(self, directory): + if directory is None: + return None + return Ref.directory( + name=directory.get('title') or directory.get('name'), + uri=uri.get_directory_uri(directory.get('id'))) + def raw_artist_to_ref(self, artist): if artist is None: return None diff --git a/mopidy_subidy/uri.py b/mopidy_subidy/uri.py index 2ff792f..55e99ba 100644 --- a/mopidy_subidy/uri.py +++ b/mopidy_subidy/uri.py @@ -4,6 +4,7 @@ SONG = 'song' ARTIST = 'artist' PLAYLIST = 'playlist' ALBUM = 'album' +DIRECTORY='directory' PREFIX = 'subidy' ROOT = 'root' SEARCH = 'search' @@ -45,6 +46,12 @@ def get_album_id(uri): return None return result.group(3) +def get_directory_id(uri): + result = regex.match(uri) + if not is_id_result_valid(result, DIRECTORY): + return None + return result.group(3) + def get_type(uri): result = regex.match(uri) if not is_type_result_valid(result): @@ -63,6 +70,9 @@ def get_album_uri(id): def get_song_uri(id): return get_type_uri(SONG, id) +def get_directory_uri(id): + return get_type_uri(DIRECTORY, id) + def get_playlist_uri(id): return get_type_uri(PLAYLIST, id) From a9aa13cdb014f4c195f31f9677964de7abd094f1 Mon Sep 17 00:00:00 2001 From: hhm Date: Sun, 12 Feb 2017 18:46:27 -0500 Subject: [PATCH 02/13] B"H add album songs retrieval --- mopidy_subidy/subsonic_api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index c8b6a0c..001aa78 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -200,7 +200,18 @@ class SubsonicApi(): return self.get_raw_dir(artist_id) def get_raw_songs(self, album_id): - return self.get_raw_dir(album_id) + try: + response = self.connection.getAlbum(album_id) + except Exception as e: + logger.warning('Connecting to subsonic failed when loading list of songs in album.') + return [] + if response.get('status') != RESPONSE_OK: + logger.warning('Got non-okay status code from subsonic: %s' % response.get('status')) + return [] + songs = response.get('album').get('song') + if songs is not None: + return songs + return [] def get_albums_as_refs(self, artist_id): return [self.raw_album_to_ref(album) for album in self.get_raw_albums(artist_id)] From e7209a4f35005a16c32b2c9424b8effe849a2bef Mon Sep 17 00:00:00 2001 From: hhm Date: Wed, 15 Feb 2017 16:46:27 -0500 Subject: [PATCH 03/13] B"H get_raw_albums --- mopidy_subidy/subsonic_api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index 001aa78..dfc8940 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -197,7 +197,18 @@ class SubsonicApi(): return None def get_raw_albums(self, artist_id): - return self.get_raw_dir(artist_id) + try: + response = self.connection.getArtist(artist_id) + except Exception as e: + logger.warning('Connecting to subsonic failed when loading list of albums.') + return [] + if response.get('status') != RESPONSE_OK: + logger.warning('Got non-okay status code from subsonic: %s' % response.get('status')) + return [] + albums = response.get('artist').get('album') + if albums is not None: + return albums + return [] def get_raw_songs(self, album_id): try: From a8910096c2dfb393ee5ccefb36cb9773b8828360 Mon Sep 17 00:00:00 2001 From: hhm Date: Mon, 27 Feb 2017 23:52:00 -0500 Subject: [PATCH 04/13] B"H styling fix --- mopidy_subidy/uri.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy_subidy/uri.py b/mopidy_subidy/uri.py index 55e99ba..667e584 100644 --- a/mopidy_subidy/uri.py +++ b/mopidy_subidy/uri.py @@ -4,7 +4,7 @@ SONG = 'song' ARTIST = 'artist' PLAYLIST = 'playlist' ALBUM = 'album' -DIRECTORY='directory' +DIRECTORY = 'directory' PREFIX = 'subidy' ROOT = 'root' SEARCH = 'search' From 76dad22268305c272fd19981f98978ab9a5df859 Mon Sep 17 00:00:00 2001 From: hhm Date: Tue, 28 Feb 2017 01:45:17 -0500 Subject: [PATCH 05/13] B"H browse artists too --- mopidy_subidy/library.py | 29 ++++++++++++++++++++++++----- mopidy_subidy/uri.py | 12 +++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index 6d01ba3..e68fb77 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -12,14 +12,14 @@ class SubidyLibraryProvider(backend.LibraryProvider): super(SubidyLibraryProvider, self).__init__(*args, **kwargs) self.subsonic_api = self.backend.subsonic_api - def browse_songs(self,album_id): - return self.subsonic_api.get_songs_as_refs(album_id) + def browse_songs(self, album_id): + return [Ref.track(name=song.name, uri=song.uri) for song in self.subsonic_api.get_songs_as_refs(album_id)] def browse_albums(self, artist_id): - return self.subsonic_api.get_albums_as_refs(artist_id) + return [Ref.directory(name=album.name, uri=album.uri) for album in self.subsonic_api.get_albums_as_refs(artist_id)] def browse_artists(self): - return self.subsonic_api.get_artists_as_refs() + return [Ref.directory(name=artist.name, uri=artist.uri) for artist in self.subsonic_api.get_artists_as_refs()] def browse_rootdirs(self): return self.subsonic_api.get_rootdirs_as_refs() @@ -37,10 +37,29 @@ class SubidyLibraryProvider(backend.LibraryProvider): return self.subsonic_api.get_artist_by_id(artist_id) def browse(self, browse_uri): + vdir_templates = [ + # ("root", ) + ("rootdirs", "Directories"), + ("artists", "Artists"), + ] + vdirs = dict((template[0], dict(id=template[0], name=template[1])) for template in vdir_templates) if browse_uri == uri.ROOT_URI: + root_vdirs = (vdirs[vdir_name] for vdir_name in ["rootdirs", "artists"]) + return [Ref.directory(name=vdir["name"], uri=uri.get_vdir_uri(vdir["id"])) for vdir in root_vdirs] + elif browse_uri == uri.get_vdir_uri("rootdirs"): return self.browse_rootdirs() + elif browse_uri == uri.get_vdir_uri("artists"): + return self.browse_artists() else: - return self.browse_diritems(uri.get_directory_id(browse_uri)) + uri_type = uri.get_type(browse_uri) + if uri_type == uri.DIRECTORY: + return self.browse_diritems(uri.get_directory_id(browse_uri)) + elif uri_type == uri.ARTIST: + return self.browse_albums(uri.get_artist_id(browse_uri)) + elif uri_type == uri.ALBUM: + return self.browse_songs(uri.get_album_id(browse_uri)) + else: + return [] def lookup_one(self, lookup_uri): type = uri.get_type(lookup_uri) diff --git a/mopidy_subidy/uri.py b/mopidy_subidy/uri.py index 667e584..d9216ce 100644 --- a/mopidy_subidy/uri.py +++ b/mopidy_subidy/uri.py @@ -5,11 +5,12 @@ ARTIST = 'artist' PLAYLIST = 'playlist' ALBUM = 'album' DIRECTORY = 'directory' +VDIR = 'vdir' PREFIX = 'subidy' ROOT = 'root' SEARCH = 'search' -ROOT_URI = '%s:%s' % (PREFIX, ROOT) +ROOT_URI = '%s:%s:%s' % (PREFIX, VDIR, ROOT) regex = re.compile(r'(\w+?):(\w+?)(?::|$)(.+?)?$') @@ -52,6 +53,12 @@ def get_directory_id(uri): return None return result.group(3) +def get_vdir_id(uri): + result = regex.match(uri) + if not is_id_result_valid(result, VDIR): + return None + return result.group(3) + def get_type(uri): result = regex.match(uri) if not is_type_result_valid(result): @@ -73,6 +80,9 @@ def get_song_uri(id): def get_directory_uri(id): return get_type_uri(DIRECTORY, id) +def get_vdir_uri(id): + return get_type_uri(VDIR, id) + def get_playlist_uri(id): return get_type_uri(PLAYLIST, id) From 635c180c13eeb57e5766ea96f572096462e618ee Mon Sep 17 00:00:00 2001 From: hhm Date: Tue, 28 Feb 2017 10:07:02 -0500 Subject: [PATCH 06/13] B"H sort root browse items, use song refs directly --- mopidy_subidy/library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index e68fb77..258da55 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -13,7 +13,7 @@ class SubidyLibraryProvider(backend.LibraryProvider): self.subsonic_api = self.backend.subsonic_api def browse_songs(self, album_id): - return [Ref.track(name=song.name, uri=song.uri) for song in self.subsonic_api.get_songs_as_refs(album_id)] + return self.subsonic_api.get_songs_as_refs(album_id) def browse_albums(self, artist_id): return [Ref.directory(name=album.name, uri=album.uri) for album in self.subsonic_api.get_albums_as_refs(artist_id)] @@ -44,7 +44,7 @@ class SubidyLibraryProvider(backend.LibraryProvider): ] vdirs = dict((template[0], dict(id=template[0], name=template[1])) for template in vdir_templates) if browse_uri == uri.ROOT_URI: - root_vdirs = (vdirs[vdir_name] for vdir_name in ["rootdirs", "artists"]) + root_vdirs = sorted((vdirs[vdir_name] for vdir_name in ["rootdirs", "artists"]), key=lambda a: a["name"]) return [Ref.directory(name=vdir["name"], uri=uri.get_vdir_uri(vdir["id"])) for vdir in root_vdirs] elif browse_uri == uri.get_vdir_uri("rootdirs"): return self.browse_rootdirs() From 17432857a6cbe2ae259758e6bb7b18e40dbe1d43 Mon Sep 17 00:00:00 2001 From: hhm Date: Tue, 28 Feb 2017 16:00:09 -0500 Subject: [PATCH 07/13] B"H browse by albums --- mopidy_subidy/library.py | 7 +++++-- mopidy_subidy/subsonic_api.py | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index 258da55..b6bdd88 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -15,7 +15,7 @@ class SubidyLibraryProvider(backend.LibraryProvider): def browse_songs(self, album_id): return self.subsonic_api.get_songs_as_refs(album_id) - def browse_albums(self, artist_id): + def browse_albums(self, artist_id=None): return [Ref.directory(name=album.name, uri=album.uri) for album in self.subsonic_api.get_albums_as_refs(artist_id)] def browse_artists(self): @@ -41,15 +41,18 @@ class SubidyLibraryProvider(backend.LibraryProvider): # ("root", ) ("rootdirs", "Directories"), ("artists", "Artists"), + ("albums", "Albums"), ] vdirs = dict((template[0], dict(id=template[0], name=template[1])) for template in vdir_templates) if browse_uri == uri.ROOT_URI: - root_vdirs = sorted((vdirs[vdir_name] for vdir_name in ["rootdirs", "artists"]), key=lambda a: a["name"]) + root_vdirs = sorted((vdirs[vdir_name] for vdir_name in ["rootdirs", "artists", "albums"]), key=lambda a: a["name"]) return [Ref.directory(name=vdir["name"], uri=uri.get_vdir_uri(vdir["id"])) for vdir in root_vdirs] elif browse_uri == uri.get_vdir_uri("rootdirs"): return self.browse_rootdirs() elif browse_uri == uri.get_vdir_uri("artists"): return self.browse_artists() + elif browse_uri == uri.get_vdir_uri("albums"): + return self.browse_albums() else: uri_type = uri.get_type(browse_uri) if uri_type == uri.DIRECTORY: diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index dfc8940..bd4eb99 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -13,6 +13,7 @@ UNKNOWN_SONG = u'Unknown Song' UNKNOWN_ALBUM = u'Unknown Album' UNKNOWN_ARTIST = u'Unknown Artist' MAX_SEARCH_RESULTS = 100 +MAX_LIST_RESULTS = 500 ref_sort_key = lambda ref: ref.name @@ -224,8 +225,23 @@ class SubsonicApi(): return songs return [] - def get_albums_as_refs(self, artist_id): - return [self.raw_album_to_ref(album) for album in self.get_raw_albums(artist_id)] + def get_raw_album_list(self, ltype, size=MAX_LIST_RESULTS): + try: + response = self.connection.getAlbumList2(ltype=ltype, size=size) + except Exception as e: + logger.warning('Connecting to subsonic failed when loading album list.') + return [] + if response.get('status') != RESPONSE_OK: + logger.warning('Got non-okay status code from subsonic: %s' % response.get('status')) + return [] + albums = response.get('albumList2').get('album') + if albums is not None: + return albums + return [] + + def get_albums_as_refs(self, artist_id=None): + albums = (self.get_raw_album_list('alphabeticalByName') if artist_id is None else self.get_raw_albums(artist_id)) + return [self.raw_album_to_ref(album) for album in albums] def get_albums_as_albums(self, artist_id): return [self.raw_album_to_album(album) for album in self.get_raw_albums(artist_id)] From ea98c7e2708d193db34b5c080ede8c23f2cb2a3e Mon Sep 17 00:00:00 2001 From: hhm Date: Wed, 8 Mar 2017 21:53:58 -0500 Subject: [PATCH 08/13] B"H sort albums of artist --- mopidy_subidy/subsonic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index bd4eb99..b480d4e 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -208,7 +208,7 @@ class SubsonicApi(): return [] albums = response.get('artist').get('album') if albums is not None: - return albums + return sorted(albums, key=lambda album: string_nums_nocase_sort_key(album['name'])) return [] def get_raw_songs(self, album_id): From 0452298a4d8054fdd697ada9fd3cff9645f84937 Mon Sep 17 00:00:00 2001 From: hhm Date: Sun, 12 Feb 2017 16:00:00 -0500 Subject: [PATCH 09/13] B"H update docs --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 31505a8..791da2c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ The following things are **not** supported: * Creating, editing and deleting playlists * Subsonics smart playlists * Searching for a combination of filters (artist and album, artist and track, etc.) - * Browsing more than 2 levels deep in the Subsonic directory tree ## Contributors From 0841fe7f100022a9f1321514bd57627eaacd88c4 Mon Sep 17 00:00:00 2001 From: hhm Date: Fri, 17 Mar 2017 02:28:44 -0400 Subject: [PATCH 10/13] B"H return artists and albums as refs of their type --- mopidy_subidy/library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index b6bdd88..8e11042 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -16,10 +16,10 @@ class SubidyLibraryProvider(backend.LibraryProvider): return self.subsonic_api.get_songs_as_refs(album_id) def browse_albums(self, artist_id=None): - return [Ref.directory(name=album.name, uri=album.uri) for album in self.subsonic_api.get_albums_as_refs(artist_id)] + return self.subsonic_api.get_albums_as_refs(artist_id) def browse_artists(self): - return [Ref.directory(name=artist.name, uri=artist.uri) for artist in self.subsonic_api.get_artists_as_refs()] + return self.subsonic_api.get_artists_as_refs() def browse_rootdirs(self): return self.subsonic_api.get_rootdirs_as_refs() From 55e0dd0609d621c449221e0df97d3acf8d6ff08a Mon Sep 17 00:00:00 2001 From: Frederick Gnodtke Date: Mon, 20 Mar 2017 17:27:15 +0100 Subject: [PATCH 11/13] Add documentation --- mopidy_subidy/library.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index 8e11042..a319a49 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -43,8 +43,11 @@ class SubidyLibraryProvider(backend.LibraryProvider): ("artists", "Artists"), ("albums", "Albums"), ] + # Create a dict with the keys being the left sides in `vdir_templates` ("rootdirs", "artists", ...) + # and the values being objects containing the key as `id` as well as the human readable name as `name`. vdirs = dict((template[0], dict(id=template[0], name=template[1])) for template in vdir_templates) if browse_uri == uri.ROOT_URI: + # Sort directories by name. root_vdirs = sorted((vdirs[vdir_name] for vdir_name in ["rootdirs", "artists", "albums"]), key=lambda a: a["name"]) return [Ref.directory(name=vdir["name"], uri=uri.get_vdir_uri(vdir["id"])) for vdir in root_vdirs] elif browse_uri == uri.get_vdir_uri("rootdirs"): From 5aab757fd99c61077200e5c175fcafb7228b166f Mon Sep 17 00:00:00 2001 From: hhm Date: Wed, 22 Mar 2017 02:22:36 -0400 Subject: [PATCH 12/13] B"H rearrange vdir code in a clearer fashion --- mopidy_subidy/library.py | 48 ++++++++++++++++++++++++++++------------ mopidy_subidy/uri.py | 3 --- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/mopidy_subidy/library.py b/mopidy_subidy/library.py index a319a49..cd29d53 100644 --- a/mopidy_subidy/library.py +++ b/mopidy_subidy/library.py @@ -6,7 +6,35 @@ import logging logger = logging.getLogger(__name__) class SubidyLibraryProvider(backend.LibraryProvider): - root_directory = Ref.directory(uri=uri.ROOT_URI, name='Subsonic') + def __create_vdirs(): + vdir_templates = [ + dict(id="root", name="Subsonic"), + dict(id="artists", name="Artists"), + dict(id="albums", name="Albums"), + dict(id="rootdirs", name="Directories"), + ] + # Create a dict with the keys being the `id`s in `vdir_templates` + # and the values being objects containing the vdir `id`, + # the human readable name as `name`, and the URI as `uri`. + vdirs = {} + for template in vdir_templates: + vdir = template.copy() + vdir.update(uri=uri.get_vdir_uri(vdir["id"])) + vdirs[template['id']] = vdir + return vdirs + + _vdirs = __create_vdirs() + + def __raw_vdir_to_ref(vdir): + if vdir is None: + return None + return Ref.directory( + name=vdir['name'], + uri=vdir['uri']) + + root_directory = __raw_vdir_to_ref(_vdirs['root']) + + _raw_vdir_to_ref = staticmethod(__raw_vdir_to_ref) def __init__(self, *args, **kwargs): super(SubidyLibraryProvider, self).__init__(*args, **kwargs) @@ -37,19 +65,11 @@ class SubidyLibraryProvider(backend.LibraryProvider): return self.subsonic_api.get_artist_by_id(artist_id) def browse(self, browse_uri): - vdir_templates = [ - # ("root", ) - ("rootdirs", "Directories"), - ("artists", "Artists"), - ("albums", "Albums"), - ] - # Create a dict with the keys being the left sides in `vdir_templates` ("rootdirs", "artists", ...) - # and the values being objects containing the key as `id` as well as the human readable name as `name`. - vdirs = dict((template[0], dict(id=template[0], name=template[1])) for template in vdir_templates) - if browse_uri == uri.ROOT_URI: - # Sort directories by name. - root_vdirs = sorted((vdirs[vdir_name] for vdir_name in ["rootdirs", "artists", "albums"]), key=lambda a: a["name"]) - return [Ref.directory(name=vdir["name"], uri=uri.get_vdir_uri(vdir["id"])) for vdir in root_vdirs] + if browse_uri == uri.get_vdir_uri('root'): + root_vdir_names = ["rootdirs", "artists", "albums"] + root_vdirs = [self._vdirs[vdir_name] for vdir_name in root_vdir_names] + sorted_root_vdirs = sorted(root_vdirs, key=lambda vdir: vdir["name"]) + return [self._raw_vdir_to_ref(vdir) for vdir in sorted_root_vdirs] elif browse_uri == uri.get_vdir_uri("rootdirs"): return self.browse_rootdirs() elif browse_uri == uri.get_vdir_uri("artists"): diff --git a/mopidy_subidy/uri.py b/mopidy_subidy/uri.py index d9216ce..613f958 100644 --- a/mopidy_subidy/uri.py +++ b/mopidy_subidy/uri.py @@ -7,11 +7,8 @@ ALBUM = 'album' DIRECTORY = 'directory' VDIR = 'vdir' PREFIX = 'subidy' -ROOT = 'root' SEARCH = 'search' -ROOT_URI = '%s:%s:%s' % (PREFIX, VDIR, ROOT) - regex = re.compile(r'(\w+?):(\w+?)(?::|$)(.+?)?$') def is_type_result_valid(result): From 7e538fbd1e8b5dc8314fa1111f6720258d095beb Mon Sep 17 00:00:00 2001 From: Frederick Date: Wed, 22 Mar 2017 08:56:03 +0100 Subject: [PATCH 13/13] Use 1 as default for tracks without numbers --- mopidy_subidy/subsonic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mopidy_subidy/subsonic_api.py b/mopidy_subidy/subsonic_api.py index b480d4e..2d56449 100644 --- a/mopidy_subidy/subsonic_api.py +++ b/mopidy_subidy/subsonic_api.py @@ -32,7 +32,7 @@ def diritem_sort_key(item): if isdir: key = string_nums_nocase_sort_key(item['title']) else: - key = int(item['track']) + key = int(item.get('track', 1)) return (isdir, key) class SubsonicApi():