Add possible solution for _gen_pages

This commit is contained in:
vitiko98 committed 2021-03-15 00:18:56 -04:00
1 parent ac37721f52
commit a0975ea5f2
2 files changed
+13 -12

No files matched your search

+11 -3
View File
@@ -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:
+2 -9
View File
@@ -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)