From 376aaa4cc958b7e25e102f677e6fc1a214630895 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 16 May 2026 19:19:12 -0700 Subject: [PATCH] Fix Amazon artist detail: album art and singles missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs in the library artist detail page when Amazon is the source: 1. No album art: get_artist_albums returned Album dataclasses with image_url=None — it collected ASINs but never called _fetch_album_metas. Now fetches metas for up to 10 albums (same cap as search_albums), populating image_url, release_date, and total_tracks on each Album. 2. No singles: Album.from_search_hit hardcodes album_type="album" and T2Tunes exposes no release type in search results. Added inference: total_tracks==1 → album_type="single", which routes them to the singles bucket in the discography categorizer. Also passes album_name through _strip_edition and artist through _primary_artist in get_artist_albums (parity with search_albums). 3. amazon_id missing from artist_source_ids in get_artist_detail: the discography lookup never received the stored Amazon slug so it always fell back to name search. Added 'amazon': artist_info. get('amazon_id') to the dict alongside spotify/deezer/itunes/etc. --- core/amazon_client.py | 32 ++++++++++++++++++++++++++------ web_server.py | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/amazon_client.py b/core/amazon_client.py index 3febed1e..a392211e 100644 --- a/core/amazon_client.py +++ b/core/amazon_client.py @@ -576,7 +576,7 @@ class AmazonClient: items = self.search_raw(f"{search_name} album", types="track,album") except AmazonClientError: return [] - albums: List[Album] = [] + album_candidates: List[tuple] = [] # (Album, asin) seen_asins: set = set() name_lower = search_name.lower() for item in items: @@ -588,13 +588,33 @@ class AmazonClient: if album_asin in seen_asins: continue seen_asins.add(album_asin) - albums.append(Album.from_search_hit({ + album = Album.from_search_hit({ "albumAsin": album_asin, - "albumName": item.album_name or item.title, - "artistName": item.artist_name, - })) - if len(albums) >= limit: + "albumName": _strip_edition(item.album_name or item.title), + "artistName": _primary_artist(item.artist_name), + }) + album_candidates.append((album, album_asin)) + if len(album_candidates) >= limit: break + + # Fetch metadata for art, release_date, track_count, and type inference. + # Cap at 10 parallel fetches — discography views don't need full coverage. + asins_to_fetch = [a for _, a in album_candidates[:10]] + metas = self._fetch_album_metas(asins_to_fetch) + + albums: List[Album] = [] + for album, asin in album_candidates: + meta = metas.get(asin, {}) + if meta: + album.image_url = meta.get("image") + album.release_date = str(meta.get("release_date") or meta.get("releaseDate") or "") + total = int(meta.get("trackCount") or 0) + album.total_tracks = total + # T2Tunes doesn't expose release type — infer from track count. + # 1-track releases are singles; keep default "album" otherwise. + if total == 1: + album.album_type = "single" + albums.append(album) return albums def get_track_features(self, track_id: str) -> Optional[Dict[str, Any]]: diff --git a/web_server.py b/web_server.py index e31cbda7..7e328051 100644 --- a/web_server.py +++ b/web_server.py @@ -7411,6 +7411,7 @@ def get_artist_detail(artist_id): 'itunes': artist_info.get('itunes_artist_id'), 'discogs': artist_info.get('discogs_id'), 'hydrabase': artist_info.get('soul_id'), + 'amazon': artist_info.get('amazon_id'), } artist_detail_discography = _get_artist_detail_discography(