B"H use subsonic dir api for browsing
This commit is contained in:
parent
5db17c3862
commit
68d469bdeb
3 changed files with 50 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue