Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Fix track filtering (#232)
Browse files Browse the repository at this point in the history
* Convert Filter object to List to pass back to filter()

* Specifically check for List as string seems to now be iterable

* Ran `black .`
  • Loading branch information
jjok authored Mar 10, 2020
1 parent 88e71a1 commit 3f378dd
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions mopidy_gmusic/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def _search_library(self, query=None, uris=None):
result_tracks = self.tracks.values()

for (field, values) in query.items():
if not hasattr(values, "__iter__"):
if not isinstance(values, list):
values = [values]
# FIXME this is bound to be slow for large libraries
for value in values:
Expand Down Expand Up @@ -528,21 +528,25 @@ def any_filter(track):
)

if field == "uri":
result_tracks = filter(uri_filter, result_tracks)
result_tracks = list(filter(uri_filter, result_tracks))
elif field == "track_name":
result_tracks = filter(track_name_filter, result_tracks)
result_tracks = list(
filter(track_name_filter, result_tracks)
)
elif field == "album":
result_tracks = filter(album_filter, result_tracks)
result_tracks = list(filter(album_filter, result_tracks))
elif field == "artist":
result_tracks = filter(artist_filter, result_tracks)
result_tracks = list(filter(artist_filter, result_tracks))
elif field == "albumartist":
result_tracks = filter(albumartist_filter, result_tracks)
result_tracks = list(
filter(albumartist_filter, result_tracks)
)
elif field == "track_no":
result_tracks = filter(track_no_filter, result_tracks)
result_tracks = list(filter(track_no_filter, result_tracks))
elif field == "date":
result_tracks = filter(date_filter, result_tracks)
result_tracks = list(filter(date_filter, result_tracks))
elif field == "any":
result_tracks = filter(any_filter, result_tracks)
result_tracks = list(filter(any_filter, result_tracks))
else:
raise LookupError("Invalid lookup field: %s" % field)

Expand Down

0 comments on commit 3f378dd

Please sign in to comment.