Bandcamp mode: only return artists verified on Bandcamp, request 15 and filter to 5
This commit is contained in:
@@ -128,7 +128,7 @@ User request: {user_request}
|
|||||||
Already in their library (do NOT recommend these):
|
Already in their library (do NOT recommend these):
|
||||||
{', '.join(list(existing_tracks)[:50]) if existing_tracks else 'None provided'}
|
{', '.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
|
- "title": song title
|
||||||
- "artist": artist name
|
- "artist": artist name
|
||||||
- "album": album name (if known)
|
- "album": album name (if known)
|
||||||
@@ -158,22 +158,30 @@ Return ONLY the JSON array, no other text."""
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
return [], remaining
|
return [], remaining
|
||||||
|
|
||||||
# Search Bandcamp for each recommendation if bandcamp mode is on
|
|
||||||
from app.services.bandcamp import search_bandcamp
|
from app.services.bandcamp import search_bandcamp
|
||||||
|
|
||||||
# Save to DB
|
# Save to DB — in bandcamp mode, only keep results verified on Bandcamp
|
||||||
recommendations = []
|
recommendations = []
|
||||||
for rec in recs_data[:5]:
|
for rec in recs_data:
|
||||||
|
if len(recommendations) >= 5:
|
||||||
|
break
|
||||||
|
|
||||||
bandcamp_url = None
|
bandcamp_url = None
|
||||||
if bandcamp_mode:
|
if bandcamp_mode:
|
||||||
try:
|
try:
|
||||||
results = await search_bandcamp(
|
results = await search_bandcamp(
|
||||||
f"{rec.get('artist', '')} {rec.get('title', '')}", item_type="t"
|
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:
|
if results:
|
||||||
bandcamp_url = results[0].get("bandcamp_url")
|
bandcamp_url = results[0].get("bandcamp_url")
|
||||||
|
else:
|
||||||
|
# Not on Bandcamp — skip this recommendation
|
||||||
|
continue
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
continue
|
||||||
|
|
||||||
r = Recommendation(
|
r = Recommendation(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user