From c6a82cf9d982511197bcfb0f11c04defed43288f Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Mar 2026 23:50:02 -0500 Subject: [PATCH] Bandcamp mode: only return artists verified on Bandcamp, request 15 and filter to 5 --- backend/app/services/recommender.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/app/services/recommender.py b/backend/app/services/recommender.py index a35d6c0..8fd2123 100644 --- a/backend/app/services/recommender.py +++ b/backend/app/services/recommender.py @@ -128,7 +128,7 @@ User request: {user_request} Already in their library (do NOT recommend these): {', '.join(list(existing_tracks)[:50]) if existing_tracks else 'None provided'} -Respond with exactly 5 music recommendations as a JSON array. Each item should have: +Respond with exactly {"15" if bandcamp_mode else "5"} music recommendations as a JSON array. Each item should have: - "title": song title - "artist": artist name - "album": album name (if known) @@ -158,22 +158,30 @@ Return ONLY the JSON array, no other text.""" except json.JSONDecodeError: return [], remaining - # Search Bandcamp for each recommendation if bandcamp mode is on from app.services.bandcamp import search_bandcamp - # Save to DB + # Save to DB — in bandcamp mode, only keep results verified on Bandcamp recommendations = [] - for rec in recs_data[:5]: + for rec in recs_data: + if len(recommendations) >= 5: + break + bandcamp_url = None if bandcamp_mode: try: results = await search_bandcamp( f"{rec.get('artist', '')} {rec.get('title', '')}", item_type="t" ) + if not results: + # Try artist-only search as fallback + results = await search_bandcamp(rec.get("artist", ""), item_type="b") if results: bandcamp_url = results[0].get("bandcamp_url") + else: + # Not on Bandcamp — skip this recommendation + continue except Exception: - pass + continue r = Recommendation( user_id=user.id,