Added basic naive search implementation.
This commit is contained in:
parent
0eb8795263
commit
6103fd1f27
3 changed files with 28 additions and 4 deletions
|
@ -27,7 +27,7 @@ The following things are supported:
|
|||
The following things are **not** supported:
|
||||
|
||||
* Creating, editing and deleting playlists
|
||||
* Searching explicitly for artists, albums, tracks, etc.
|
||||
* Advanced searching. This means everything except 'any', 'artist', 'artist' and 'album'
|
||||
* Subsonics smart playlists
|
||||
|
||||
## Contributors
|
||||
|
|
|
@ -4,7 +4,7 @@ import os
|
|||
|
||||
from mopidy import ext, config
|
||||
|
||||
__version__ = '0.1.0'
|
||||
__version__ = '0.2.0'
|
||||
|
||||
|
||||
class SubidyExtension(ext.Extension):
|
||||
|
|
|
@ -74,8 +74,32 @@ class SubidyLibraryProvider(backend.LibraryProvider):
|
|||
return SearchResult(tracks=[song])
|
||||
return None
|
||||
|
||||
def search_by_artist_and_album(self, artist_name, album_name):
|
||||
artists = self.subsonic_api.get_raw_artists()
|
||||
artist = next(item for item in artists if artist_name in item.get('name'))
|
||||
albums = self.subsonic_api.get_raw_albums(artist.get('id'))
|
||||
album = next(item for item in albums if album_name in item.get('title'))
|
||||
return SearchResult(tracks=self.subsonic_api.get_songs_as_tracks(album.get('id')))
|
||||
|
||||
def get_distinct(self, field, query):
|
||||
search_result = self.search(query)
|
||||
if not search_result:
|
||||
return []
|
||||
if field == 'track' or field == 'title':
|
||||
return [track.name for track in (search_result.tracks or [])]
|
||||
if field == 'album':
|
||||
return [album.name for album in (search_result.albums or [])]
|
||||
if field == 'artist':
|
||||
if not search_result.artists:
|
||||
return [artist.name for artist in self.browse_artists()]
|
||||
return [artist.name for artist in search_result.artists]
|
||||
|
||||
def search(self, query=None, uris=None, exact=False):
|
||||
if 'uri' in query:
|
||||
return self.search_uri(query.get('uri')[0])
|
||||
if 'artist' in query and 'album' in query:
|
||||
return self.search_by_artist_and_album(query.get('artist')[0], query.get('album')[0])
|
||||
if 'artist' in query:
|
||||
return self.subsonic_api.find_as_search_result(query.get('artist')[0])
|
||||
if 'any' in query:
|
||||
return self.subsonic_api.find_as_search_result(query.get('any')[0])
|
||||
return SearchResult(artists=self.subsonic_api.get_artists_as_artists())
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue