diff --git a/rip/core.py b/rip/core.py index 2de56a1..c21e598 100644 --- a/rip/core.py +++ b/rip/core.py @@ -314,9 +314,9 @@ class MusicDL(list): continue if hasattr(item, "id"): - self.db.add(item.id) + self.db.add(str(item.id)) for item_id in item.downloaded_ids: - self.db.add(item_id) + self.db.add(str(item_id)) if isinstance(item, Track): item.tag() diff --git a/rip/db.py b/rip/db.py index f15ae86..dd562c8 100644 --- a/rip/db.py +++ b/rip/db.py @@ -68,7 +68,7 @@ class Database: conditions = " AND ".join(f"{key}=?" for key in items.keys()) command = f"SELECT EXISTS(SELECT 1 FROM {self.name} WHERE {conditions})" - logger.debug(f"executing {command}") + logger.debug("Executing %s", command) return bool(conn.execute(command, tuple(items.values())).fetchone()[0]) @@ -108,7 +108,8 @@ class Database: question_marks = ", ".join("?" for _ in items) command = f"INSERT INTO {self.name} ({params}) VALUES ({question_marks})" - logger.debug(f"executing {command}") + logger.debug("Executing %s", command) + logger.debug("Items to add: %s", items) with sqlite3.connect(self.path) as conn: try: diff --git a/streamrip/clients.py b/streamrip/clients.py index 76537e7..27866da 100644 --- a/streamrip/clients.py +++ b/streamrip/clients.py @@ -21,6 +21,8 @@ from .constants import ( QOBUZ_FEATURED_KEYS, SOUNDCLOUD_BASE, SOUNDCLOUD_CLIENT_ID, + SOUNDCLOUD_USER_ID, + SOUNDCLOUD_APP_VERSION, TIDAL_AUTH_URL, TIDAL_BASE, TIDAL_CLIENT_INFO, @@ -122,7 +124,7 @@ class QobuzClient(Client): return if (kwargs.get("app_id") or kwargs.get("secrets")) in (None, [], ""): - click.secho("Fetching tokens — this may take a few seconds.", fg='magenta') + click.secho("Fetching tokens — this may take a few seconds.", fg="magenta") logger.info("Fetching tokens from Qobuz") spoofer = Spoofer() kwargs["app_id"] = spoofer.get_app_id() @@ -958,7 +960,7 @@ class SoundCloudClient(Client): resp, _ = self._get(url, no_base=True) return {"url": resp["url"], "type": "mp3"} - def search(self, query: str, media_type="album"): + def search(self, query: str, media_type="album", limit=50, offset=50): """Search for a query. :param query: @@ -966,7 +968,14 @@ class SoundCloudClient(Client): :param media_type: Can be album, though it will return a playlist response. """ - params = {"q": query} + params = { + "q": query, + "facet": "genre", + "user_id": SOUNDCLOUD_USER_ID, + "limit": limit, + "offset": offset, + "linked_partitioning": "1", + } resp, _ = self._get(f"search/{media_type}s", params=params) return resp @@ -983,7 +992,7 @@ class SoundCloudClient(Client): param_arg = params params = { "client_id": SOUNDCLOUD_CLIENT_ID, - "app_version": "1626941202", + "app_version": SOUNDCLOUD_APP_VERSION, "app_locale": "en", } if param_arg is not None: @@ -994,7 +1003,8 @@ class SoundCloudClient(Client): else: url = f"{SOUNDCLOUD_BASE}/{path}" - logger.debug(f"Fetching url {url}") + logger.debug("Fetching url %s", url) + logger.debug("Parameters: %s", params) r = self.session.get(url, params=params) logger.debug(r.text) if resp_obj: diff --git a/streamrip/constants.py b/streamrip/constants.py index 5f3a795..570f8bb 100644 --- a/streamrip/constants.py +++ b/streamrip/constants.py @@ -6,7 +6,9 @@ import re AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0" TIDAL_COVER_URL = "https://resources.tidal.com/images/{uuid}/{width}x{height}.jpg" -SOUNDCLOUD_CLIENT_ID = re.compile("a3e059563d7fd3372b49b37f00a00bcf") +SOUNDCLOUD_CLIENT_ID = "QFciLWLC1GS4P3EZvXIjA3jKhKO5pKB3" +SOUNDCLOUD_USER_ID = "672320-86895-162383-801513" +SOUNDCLOUD_APP_VERSION = "1626941202" QUALITY_DESC = {