diff --git a/qobuz_dl_rewrite/clients.py b/qobuz_dl_rewrite/clients.py index 858d13c..61d7165 100644 --- a/qobuz_dl_rewrite/clients.py +++ b/qobuz_dl_rewrite/clients.py @@ -168,9 +168,17 @@ class QobuzClient(SecureClientInterface): def _gen_pages(self, epoint: str, params): page, status_code = self._api_request(epoint, params) - total = page["albums"]["total"] - limit = page["albums"]["limit"] - offset = page["albums"]["offset"] + logger.debug("Keys returned from _gen_pages: %s", ", ".join(page.keys())) + key = epoint.split("/")[0] + "s" + total = page.get(key, {}) + total = total.get("total") or total.get("items") + + if not total: + logger.debug("Nothing found from %s epoint", epoint) + return + + limit = page.get(key, {}).get("limit", 500) + offset = page.get(key, {}).get("offset", 0) params.update({"limit": limit}) yield page while (offset + limit) < total: diff --git a/qobuz_dl_rewrite/core.py b/qobuz_dl_rewrite/core.py index 27b686f..673a791 100644 --- a/qobuz_dl_rewrite/core.py +++ b/qobuz_dl_rewrite/core.py @@ -1,6 +1,7 @@ import logging import os import re + # ------- Testing ---------- from typing import Generator, Sequence, Tuple, Union @@ -87,12 +88,4 @@ class QobuzDL: raise ParsingError("Error parsing URLs from file `{filepath}`") def search(self, query: str, media_type: str, limit: int = 200) -> Generator: - results = self.client.search(query, media_type=media_type, limit=limit) - key = media_type + "s" - - # Temporal to test Deezer - iterable = results.get(key, {}).get("items") or results.get("data", []) - - return ( - MEDIA_CLASS[media_type].from_api(item, self.client) for item in iterable - ) + return self.client.search(query, media_type, limit)