Fix Discogs album lookups — try master ID before release ID
- get_album and get_album_tracks now try /masters/{id} first, fall back
to /releases/{id} — artist discography returns master IDs which are
in a different namespace than release IDs
- Fixes wrong album showing in download modal (master ID 3664443 for
GNX was hitting /releases/3664443 which is a different album)
- Add Discogs source override to all 6 artist/album/track endpoints
- Add discogs_id to _resolve_db_album_id lookup
This commit is contained in:
parent
d98d3b33c4
commit
69a09826f4
2 changed files with 33 additions and 4 deletions
|
|
@ -445,8 +445,12 @@ class DiscogsClient:
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_album(self, release_id: str, include_tracks: bool = True) -> Optional[Dict[str, Any]]:
|
def get_album(self, release_id: str, include_tracks: bool = True) -> Optional[Dict[str, Any]]:
|
||||||
"""Get release/album details by Discogs ID."""
|
"""Get release/album details by Discogs ID. Tries master first, falls back to release."""
|
||||||
data = self._api_get(f'/releases/{release_id}')
|
# Try as master first (artist discography returns master IDs)
|
||||||
|
data = self._api_get(f'/masters/{release_id}')
|
||||||
|
if not data or not data.get('title'):
|
||||||
|
# Fall back to release
|
||||||
|
data = self._api_get(f'/releases/{release_id}')
|
||||||
if not data:
|
if not data:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9484,6 +9484,11 @@ def get_artist_image(artist_id):
|
||||||
client = _get_deezer_client()
|
client = _get_deezer_client()
|
||||||
image_url = client._get_artist_image_from_albums(artist_id)
|
image_url = client._get_artist_image_from_albums(artist_id)
|
||||||
return jsonify({"success": True, "image_url": image_url})
|
return jsonify({"success": True, "image_url": image_url})
|
||||||
|
elif source_override == 'discogs':
|
||||||
|
from core.discogs_client import DiscogsClient
|
||||||
|
client = DiscogsClient()
|
||||||
|
image_url = client._get_artist_image_from_albums(artist_id)
|
||||||
|
return jsonify({"success": True, "image_url": image_url})
|
||||||
elif source_override == 'hydrabase':
|
elif source_override == 'hydrabase':
|
||||||
# Route to the plugin that sourced the data
|
# Route to the plugin that sourced the data
|
||||||
plugin = request.args.get('plugin', '').lower()
|
plugin = request.args.get('plugin', '').lower()
|
||||||
|
|
@ -9556,6 +9561,12 @@ def get_artist_discography(artist_id):
|
||||||
albums = deezer_cl.get_artist_albums(artist_id, album_type='album,single', limit=50)
|
albums = deezer_cl.get_artist_albums(artist_id, album_type='album,single', limit=50)
|
||||||
if albums:
|
if albums:
|
||||||
active_source = 'deezer'
|
active_source = 'deezer'
|
||||||
|
elif source_override == 'discogs':
|
||||||
|
from core.discogs_client import DiscogsClient
|
||||||
|
discogs_cl = DiscogsClient()
|
||||||
|
albums = discogs_cl.get_artist_albums(artist_id, album_type='album,single', limit=50)
|
||||||
|
if albums:
|
||||||
|
active_source = 'discogs'
|
||||||
elif source_override == 'hydrabase':
|
elif source_override == 'hydrabase':
|
||||||
plugin = request.args.get('plugin', '').lower()
|
plugin = request.args.get('plugin', '').lower()
|
||||||
if plugin == 'deezer':
|
if plugin == 'deezer':
|
||||||
|
|
@ -9583,6 +9594,9 @@ def get_artist_discography(artist_id):
|
||||||
cl = iTunesClient()
|
cl = iTunesClient()
|
||||||
elif source_override == 'deezer':
|
elif source_override == 'deezer':
|
||||||
cl = _get_deezer_client()
|
cl = _get_deezer_client()
|
||||||
|
elif source_override == 'discogs':
|
||||||
|
from core.discogs_client import DiscogsClient
|
||||||
|
cl = DiscogsClient()
|
||||||
elif source_override == 'spotify' and spotify_available:
|
elif source_override == 'spotify' and spotify_available:
|
||||||
cl = spotify_client
|
cl = spotify_client
|
||||||
else:
|
else:
|
||||||
|
|
@ -9851,7 +9865,7 @@ def _resolve_db_album_id(album_id, artist_id=None):
|
||||||
with database._get_connection() as conn:
|
with database._get_connection() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT a.title, a.spotify_album_id, a.itunes_album_id, ar.name as artist_name
|
SELECT a.title, a.spotify_album_id, a.itunes_album_id, a.discogs_id, ar.name as artist_name
|
||||||
FROM albums a
|
FROM albums a
|
||||||
JOIN artists ar ON a.artist_id = ar.id
|
JOIN artists ar ON a.artist_id = ar.id
|
||||||
WHERE a.id = ?
|
WHERE a.id = ?
|
||||||
|
|
@ -9860,11 +9874,16 @@ def _resolve_db_album_id(album_id, artist_id=None):
|
||||||
if not row:
|
if not row:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Prefer stored external IDs
|
# Prefer stored external IDs — match the active fallback source
|
||||||
|
fallback = _get_metadata_fallback_source()
|
||||||
|
if fallback == 'discogs' and row.get('discogs_id'):
|
||||||
|
return row['discogs_id']
|
||||||
if row['spotify_album_id']:
|
if row['spotify_album_id']:
|
||||||
return row['spotify_album_id']
|
return row['spotify_album_id']
|
||||||
if row['itunes_album_id']:
|
if row['itunes_album_id']:
|
||||||
return row['itunes_album_id']
|
return row['itunes_album_id']
|
||||||
|
if row.get('discogs_id'):
|
||||||
|
return row['discogs_id']
|
||||||
|
|
||||||
# No stored external ID — search by name
|
# No stored external ID — search by name
|
||||||
album_title = row['title']
|
album_title = row['title']
|
||||||
|
|
@ -9950,6 +9969,9 @@ def get_artist_album_tracks(artist_id, album_id):
|
||||||
client = iTunesClient()
|
client = iTunesClient()
|
||||||
elif source_override == 'deezer':
|
elif source_override == 'deezer':
|
||||||
client = _get_deezer_client()
|
client = _get_deezer_client()
|
||||||
|
elif source_override == 'discogs':
|
||||||
|
from core.discogs_client import DiscogsClient
|
||||||
|
client = DiscogsClient()
|
||||||
|
|
||||||
print(f"🎵 Fetching tracks for album: {album_id} by artist: {artist_id} (source: {source_override or 'auto'})")
|
print(f"🎵 Fetching tracks for album: {album_id} by artist: {artist_id} (source: {source_override or 'auto'})")
|
||||||
|
|
||||||
|
|
@ -29724,6 +29746,9 @@ def get_album_tracks(album_id):
|
||||||
# else: spotify (default)
|
# else: spotify (default)
|
||||||
elif source_override == 'deezer':
|
elif source_override == 'deezer':
|
||||||
client = _get_deezer_client()
|
client = _get_deezer_client()
|
||||||
|
elif source_override == 'discogs':
|
||||||
|
from core.discogs_client import DiscogsClient
|
||||||
|
client = DiscogsClient()
|
||||||
|
|
||||||
album_data = client.get_album(album_id)
|
album_data = client.get_album(album_id)
|
||||||
if not album_data:
|
if not album_data:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue