Tidal & Qobuz Enrichment Workers - Bug Fixes & Rate Limiting
This commit is contained in:
parent
35d6068f99
commit
cc35864e7d
2 changed files with 75 additions and 34 deletions
|
|
@ -682,15 +682,16 @@ class TidalClient:
|
||||||
logger.error("Not authenticated with Tidal")
|
logger.error("Not authenticated with Tidal")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
from urllib.parse import quote
|
||||||
|
encoded_query = quote(query, safe='')
|
||||||
params = {
|
params = {
|
||||||
'query': query,
|
'countryCode': 'US',
|
||||||
'type': 'tracks',
|
'include': 'tracks',
|
||||||
'limit': limit,
|
'limit': limit
|
||||||
'countryCode': 'US' # Default to US
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.session.get(
|
response = self.session.get(
|
||||||
f"{self.base_url}/searchresults",
|
f"{self.base_url}/searchresults/{encoded_query}",
|
||||||
params=params,
|
params=params,
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
|
|
@ -724,15 +725,16 @@ class TidalClient:
|
||||||
if not self._ensure_valid_token():
|
if not self._ensure_valid_token():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
from urllib.parse import quote
|
||||||
|
encoded_query = quote(name, safe='')
|
||||||
params = {
|
params = {
|
||||||
'query': name,
|
'countryCode': 'US',
|
||||||
'type': 'artists',
|
'include': 'artists',
|
||||||
'limit': 1,
|
'limit': 1
|
||||||
'countryCode': 'US'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.session.get(
|
response = self.session.get(
|
||||||
f"{self.base_url}/searchresults",
|
f"{self.base_url}/searchresults/{encoded_query}",
|
||||||
params=params,
|
params=params,
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
|
|
@ -741,13 +743,22 @@ class TidalClient:
|
||||||
raise Exception(f"Rate limited (429) on search_artist")
|
raise Exception(f"Rate limited (429) on search_artist")
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
# JSON:API format: included artists in 'artists' or nested in relationships
|
||||||
items = []
|
items = []
|
||||||
if 'artists' in data and 'items' in data['artists']:
|
if 'artists' in data and isinstance(data['artists'], list):
|
||||||
items = data['artists']['items']
|
|
||||||
elif 'artists' in data and isinstance(data['artists'], list):
|
|
||||||
items = data['artists']
|
items = data['artists']
|
||||||
|
elif 'artists' in data and 'items' in data['artists']:
|
||||||
|
items = data['artists']['items']
|
||||||
|
elif 'included' in data:
|
||||||
|
items = [r for r in data['included'] if r.get('type') == 'artists']
|
||||||
if items:
|
if items:
|
||||||
return items[0]
|
item = items[0]
|
||||||
|
# Flatten JSON:API resource if needed
|
||||||
|
if 'attributes' in item and 'id' in item:
|
||||||
|
flat = dict(item['attributes'])
|
||||||
|
flat['id'] = item['id']
|
||||||
|
return flat
|
||||||
|
return item
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Tidal artist search failed: {response.status_code}")
|
logger.debug(f"Tidal artist search failed: {response.status_code}")
|
||||||
return None
|
return None
|
||||||
|
|
@ -765,16 +776,17 @@ class TidalClient:
|
||||||
if not self._ensure_valid_token():
|
if not self._ensure_valid_token():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
from urllib.parse import quote
|
||||||
query = f"{artist} {title}" if artist else title
|
query = f"{artist} {title}" if artist else title
|
||||||
|
encoded_query = quote(query, safe='')
|
||||||
params = {
|
params = {
|
||||||
'query': query,
|
'countryCode': 'US',
|
||||||
'type': 'albums',
|
'include': 'albums',
|
||||||
'limit': 1,
|
'limit': 1
|
||||||
'countryCode': 'US'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.session.get(
|
response = self.session.get(
|
||||||
f"{self.base_url}/searchresults",
|
f"{self.base_url}/searchresults/{encoded_query}",
|
||||||
params=params,
|
params=params,
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
|
|
@ -784,12 +796,19 @@ class TidalClient:
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
items = []
|
items = []
|
||||||
if 'albums' in data and 'items' in data['albums']:
|
if 'albums' in data and isinstance(data['albums'], list):
|
||||||
items = data['albums']['items']
|
|
||||||
elif 'albums' in data and isinstance(data['albums'], list):
|
|
||||||
items = data['albums']
|
items = data['albums']
|
||||||
|
elif 'albums' in data and 'items' in data['albums']:
|
||||||
|
items = data['albums']['items']
|
||||||
|
elif 'included' in data:
|
||||||
|
items = [r for r in data['included'] if r.get('type') == 'albums']
|
||||||
if items:
|
if items:
|
||||||
return items[0]
|
item = items[0]
|
||||||
|
if 'attributes' in item and 'id' in item:
|
||||||
|
flat = dict(item['attributes'])
|
||||||
|
flat['id'] = item['id']
|
||||||
|
return flat
|
||||||
|
return item
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Tidal album search failed: {response.status_code}")
|
logger.debug(f"Tidal album search failed: {response.status_code}")
|
||||||
return None
|
return None
|
||||||
|
|
@ -807,16 +826,17 @@ class TidalClient:
|
||||||
if not self._ensure_valid_token():
|
if not self._ensure_valid_token():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
from urllib.parse import quote
|
||||||
query = f"{artist} {title}" if artist else title
|
query = f"{artist} {title}" if artist else title
|
||||||
|
encoded_query = quote(query, safe='')
|
||||||
params = {
|
params = {
|
||||||
'query': query,
|
'countryCode': 'US',
|
||||||
'type': 'tracks',
|
'include': 'tracks',
|
||||||
'limit': 1,
|
'limit': 1
|
||||||
'countryCode': 'US'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.session.get(
|
response = self.session.get(
|
||||||
f"{self.base_url}/searchresults",
|
f"{self.base_url}/searchresults/{encoded_query}",
|
||||||
params=params,
|
params=params,
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
|
|
@ -826,12 +846,19 @@ class TidalClient:
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
items = []
|
items = []
|
||||||
if 'tracks' in data and 'items' in data['tracks']:
|
if 'tracks' in data and isinstance(data['tracks'], list):
|
||||||
items = data['tracks']['items']
|
|
||||||
elif 'tracks' in data and isinstance(data['tracks'], list):
|
|
||||||
items = data['tracks']
|
items = data['tracks']
|
||||||
|
elif 'tracks' in data and 'items' in data['tracks']:
|
||||||
|
items = data['tracks']['items']
|
||||||
|
elif 'included' in data:
|
||||||
|
items = [r for r in data['included'] if r.get('type') == 'tracks']
|
||||||
if items:
|
if items:
|
||||||
return items[0]
|
item = items[0]
|
||||||
|
if 'attributes' in item and 'id' in item:
|
||||||
|
flat = dict(item['attributes'])
|
||||||
|
flat['id'] = item['id']
|
||||||
|
return flat
|
||||||
|
return item
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Tidal track search failed: {response.status_code}")
|
logger.debug(f"Tidal track search failed: {response.status_code}")
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -29196,6 +29196,20 @@ body {
|
||||||
.genius-card-icon:hover {
|
.genius-card-icon:hover {
|
||||||
background: #ffff64;
|
background: #ffff64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tidal-card-icon:hover {
|
||||||
|
background: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qobuz-card-icon:hover {
|
||||||
|
background: #0170ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tidal-card-icon img,
|
||||||
|
.qobuz-card-icon img {
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
|
||||||
.watch-card-icon {
|
.watch-card-icon {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue