diff --git a/streamrip/client/deezer.py b/streamrip/client/deezer.py index 40c4d78..3f42260 100644 --- a/streamrip/client/deezer.py +++ b/streamrip/client/deezer.py @@ -129,7 +129,9 @@ class DeezerClient(Client): raise Exception(f"Invalid media type {media_type}") response = search_function(query, limit=limit) # type: ignore - return [response] + if response["total"] > 0: + return [response] + return [] async def get_downloadable( self, diff --git a/streamrip/client/tidal.py b/streamrip/client/tidal.py index 0238d40..6e31643 100644 --- a/streamrip/client/tidal.py +++ b/streamrip/client/tidal.py @@ -121,7 +121,9 @@ class TidalClient(Client): } assert media_type in ("album", "track", "playlist", "video", "artist") resp = await self._api_request(f"search/{media_type}s", params=params) - return [resp] + if len(resp["items"]) > 1: + return [resp] + return [] async def get_downloadable(self, track_id: str, quality: int): params = { diff --git a/streamrip/media/playlist.py b/streamrip/media/playlist.py index 59b7aa6..8227899 100644 --- a/streamrip/media/playlist.py +++ b/streamrip/media/playlist.py @@ -254,12 +254,19 @@ class PendingLastfmPlaylist(Pending): async def _make_query( self, query: str, - s: Status, + search_status: Status, callback, ) -> tuple[str | None, bool]: - """Try searching for `query` with main source. If that fails, try with next source. + """Search for a track with the main source, and use fallback source + if that fails. - If both fail, return None. + Args: + query (str): Query to search + s (Status): + callback: function to call after each query completes + + Returns: A 2-tuple, where the first element contains the ID if it was found, + and the second element is True if the fallback source was used. """ with ExitStack() as stack: # ensure `callback` is always called @@ -267,7 +274,7 @@ class PendingLastfmPlaylist(Pending): pages = await self.client.search("track", query, limit=1) if len(pages) > 0: logger.debug(f"Found result for {query} on {self.client.source}") - s.found += 1 + search_status.found += 1 return ( SearchResults.from_pages(self.client.source, "track", pages) .results[0] @@ -276,13 +283,13 @@ class PendingLastfmPlaylist(Pending): if self.fallback_client is None: logger.debug(f"No result found for {query} on {self.client.source}") - s.failed += 1 + search_status.failed += 1 return None, False pages = await self.fallback_client.search("track", query, limit=1) if len(pages) > 0: logger.debug(f"Found result for {query} on {self.client.source}") - s.found += 1 + search_status.found += 1 return ( SearchResults.from_pages( self.fallback_client.source, @@ -294,7 +301,7 @@ class PendingLastfmPlaylist(Pending): ), True logger.debug(f"No result found for {query} on {self.client.source}") - s.failed += 1 + search_status.failed += 1 return None, True async def _parse_lastfm_playlist(