mirror of
https://github.com/nathom/streamrip.git
synced 2024-09-19 11:18:45 -04:00
Fix last.fm crash for tidal and deezer (#583)
This commit is contained in:
parent
04f6881131
commit
56f9aac92a
3 changed files with 20 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue