From 3f378dd2f11a0bfa78a10fe366f43bef469fbc4a Mon Sep 17 00:00:00 2001 From: Jonathan Jefferies Date: Tue, 10 Mar 2020 23:36:30 +0000 Subject: [PATCH] Fix track filtering (#232) * Convert Filter object to List to pass back to filter() * Specifically check for List as string seems to now be iterable * Ran `black .` --- mopidy_gmusic/library.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/mopidy_gmusic/library.py b/mopidy_gmusic/library.py index bb447ac..9bad6f0 100644 --- a/mopidy_gmusic/library.py +++ b/mopidy_gmusic/library.py @@ -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: @@ -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)