Fix SoundCloud search #122

This commit is contained in:
nathom 2021-07-23 21:38:01 -07:00
parent 65aa1efc38
commit 5ab0fdbc4a
4 changed files with 23 additions and 10 deletions

View file

@ -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()

View file

@ -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:

View file

@ -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:

View file

@ -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 = {