Fix missing album art on downloads page with multi-layer fallback
This commit is contained in:
parent
d2bd66c0ce
commit
735a0ebe58
1 changed files with 76 additions and 11 deletions
|
|
@ -31352,13 +31352,26 @@ def get_all_downloads_unified():
|
||||||
album = str(raw_album) if raw_album else ''
|
album = str(raw_album) if raw_album else ''
|
||||||
|
|
||||||
artwork = track_info.get('artwork_url') or track_info.get('image_url') or track_info.get('album_art') or ''
|
artwork = track_info.get('artwork_url') or track_info.get('image_url') or track_info.get('album_art') or ''
|
||||||
# Try album images
|
# Try album images (both image_url and images[] formats)
|
||||||
if not artwork:
|
if not artwork:
|
||||||
raw_alb = track_info.get('album')
|
raw_alb = track_info.get('album')
|
||||||
if isinstance(raw_alb, dict):
|
if isinstance(raw_alb, dict):
|
||||||
images = raw_alb.get('images') or []
|
artwork = raw_alb.get('image_url') or ''
|
||||||
if images and isinstance(images, list) and len(images) > 0:
|
if not artwork:
|
||||||
artwork = images[0].get('url', '') if isinstance(images[0], dict) else str(images[0])
|
images = raw_alb.get('images') or []
|
||||||
|
if images and isinstance(images, list) and len(images) > 0:
|
||||||
|
artwork = images[0].get('url', '') if isinstance(images[0], dict) else str(images[0])
|
||||||
|
# Try spotify_data nested object (wishlist tracks store metadata here)
|
||||||
|
if not artwork:
|
||||||
|
sp_data = track_info.get('spotify_data') or {}
|
||||||
|
if isinstance(sp_data, dict):
|
||||||
|
sp_album = sp_data.get('album') or {}
|
||||||
|
if isinstance(sp_album, dict):
|
||||||
|
artwork = sp_album.get('image_url') or ''
|
||||||
|
if not artwork:
|
||||||
|
sp_imgs = sp_album.get('images') or []
|
||||||
|
if sp_imgs and isinstance(sp_imgs, list) and isinstance(sp_imgs[0], dict):
|
||||||
|
artwork = sp_imgs[0].get('url', '')
|
||||||
|
|
||||||
status = task.get('status', 'queued')
|
status = task.get('status', 'queued')
|
||||||
# Determine download progress percentage
|
# Determine download progress percentage
|
||||||
|
|
@ -31408,18 +31421,18 @@ def get_all_downloads_unified():
|
||||||
if items_needing_art:
|
if items_needing_art:
|
||||||
try:
|
try:
|
||||||
database = get_database()
|
database = get_database()
|
||||||
# Batch lookup by track name — metadata cache has deezer/itunes images
|
with database._get_connection() as conn:
|
||||||
track_names = list({it['title'] for it in items_needing_art if it['title']})
|
cursor = conn.cursor()
|
||||||
if track_names:
|
# 1. Batch lookup by track name
|
||||||
placeholders = ','.join('?' for _ in track_names)
|
track_names = list({it['title'] for it in items_needing_art if it['title']})
|
||||||
with database._get_connection() as conn:
|
name_to_art = {}
|
||||||
cursor = conn.cursor()
|
if track_names:
|
||||||
|
placeholders = ','.join('?' for _ in track_names)
|
||||||
cursor.execute(f"""
|
cursor.execute(f"""
|
||||||
SELECT name, image_url FROM metadata_cache_entities
|
SELECT name, image_url FROM metadata_cache_entities
|
||||||
WHERE entity_type='track' AND name IN ({placeholders})
|
WHERE entity_type='track' AND name IN ({placeholders})
|
||||||
AND image_url IS NOT NULL AND image_url != ''
|
AND image_url IS NOT NULL AND image_url != ''
|
||||||
""", track_names)
|
""", track_names)
|
||||||
name_to_art = {}
|
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
if row[0] not in name_to_art:
|
if row[0] not in name_to_art:
|
||||||
name_to_art[row[0]] = row[1]
|
name_to_art[row[0]] = row[1]
|
||||||
|
|
@ -31427,6 +31440,58 @@ def get_all_downloads_unified():
|
||||||
cached_url = name_to_art.get(it['title'])
|
cached_url = name_to_art.get(it['title'])
|
||||||
if cached_url:
|
if cached_url:
|
||||||
it['artwork'] = cached_url
|
it['artwork'] = cached_url
|
||||||
|
|
||||||
|
# 2. Remaining items: look up by album name (album art is better than nothing)
|
||||||
|
still_needing = [it for it in items_needing_art if not it.get('artwork') and it.get('album')]
|
||||||
|
if still_needing:
|
||||||
|
album_names = list({it['album'] for it in still_needing if it['album']})
|
||||||
|
if album_names:
|
||||||
|
placeholders = ','.join('?' for _ in album_names)
|
||||||
|
cursor.execute(f"""
|
||||||
|
SELECT name, image_url FROM metadata_cache_entities
|
||||||
|
WHERE entity_type='album' AND name IN ({placeholders})
|
||||||
|
AND image_url IS NOT NULL AND image_url != ''
|
||||||
|
""", album_names)
|
||||||
|
album_to_art = {}
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
if row[0] not in album_to_art:
|
||||||
|
album_to_art[row[0]] = row[1]
|
||||||
|
for it in still_needing:
|
||||||
|
cached_url = album_to_art.get(it['album'])
|
||||||
|
if cached_url:
|
||||||
|
it['artwork'] = cached_url
|
||||||
|
|
||||||
|
# 3. Last resort: check matched_downloads_context for items with active downloads
|
||||||
|
final_needing = [it for it in items_needing_art if not it.get('artwork')]
|
||||||
|
if final_needing:
|
||||||
|
with matched_context_lock:
|
||||||
|
for it in final_needing:
|
||||||
|
# Find task in download_tasks to get username/filename for context lookup
|
||||||
|
task_id = it.get('task_id')
|
||||||
|
if not task_id:
|
||||||
|
continue
|
||||||
|
with tasks_lock:
|
||||||
|
task = download_tasks.get(task_id)
|
||||||
|
if not task:
|
||||||
|
continue
|
||||||
|
t_username = task.get('username')
|
||||||
|
t_filename = task.get('filename')
|
||||||
|
if t_username and t_filename:
|
||||||
|
ctx_key = _make_context_key(t_username, t_filename)
|
||||||
|
ctx = matched_downloads_context.get(ctx_key)
|
||||||
|
if ctx:
|
||||||
|
_sp_album = ctx.get('spotify_album') or {}
|
||||||
|
_sp_track = ctx.get('track_info') or {}
|
||||||
|
_sp_images = _sp_album.get('images') or []
|
||||||
|
_art = ''
|
||||||
|
if _sp_images and isinstance(_sp_images[0], dict):
|
||||||
|
_art = _sp_images[0].get('url', '') or ''
|
||||||
|
if not _art:
|
||||||
|
_art = _sp_album.get('image_url') or ''
|
||||||
|
if not _art:
|
||||||
|
_art = _sp_track.get('image_url') or ''
|
||||||
|
if _art:
|
||||||
|
it['artwork'] = _art
|
||||||
except Exception as cache_err:
|
except Exception as cache_err:
|
||||||
logger.debug(f"Metadata cache artwork lookup failed: {cache_err}")
|
logger.debug(f"Metadata cache artwork lookup failed: {cache_err}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue