fix(shop): apple_preview_url is a JSON array — return the first clean preview URL

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
type-two 2026-06-23 23:12:39 +10:00
parent 16c85184cd
commit 7e9d5028b0

View File

@ -153,10 +153,17 @@ async def shop_audio(release_id: int, db=Depends(get_db)):
SELECT apple_preview_url, apple_url, beatport_id, beatport_url, beatport_embed, beatport_genre,
spotify_id, bandcamp_url, bandcamp_embed, soundcloud_url
FROM disc_release_audio WHERE release_id = :r"""), {"r": release_id})).mappings().first()
audio = dict(a) if a else None
if audio and isinstance(audio.get("apple_preview_url"), str) and audio["apple_preview_url"].lstrip().startswith("["):
try:
arr = json.loads(audio["apple_preview_url"])
audio["apple_preview_url"] = next((u for u in arr if u), None)
except (ValueError, TypeError):
audio["apple_preview_url"] = None
vids = [dict(r) for r in (await db.execute(text("""
SELECT title, uri, duration FROM disc_release_video WHERE release_id = :r AND uri <> '' LIMIT 8
"""), {"r": release_id})).mappings()]
return {"audio": dict(a) if a else None, "videos": vids}
return {"audio": audio, "videos": vids}
class WantIn(BaseModel):