Remove Bandcamp scraping (TOS violation), use YouTube links for all recommendations
This commit is contained in:
@@ -2,7 +2,7 @@ from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.core.config import settings
|
||||
from app.api.endpoints import auth, bandcamp, billing, lastfm, manual_import, playlist_fix, playlists, profile, recommendations, youtube_music
|
||||
from app.api.endpoints import auth, billing, lastfm, manual_import, playlist_fix, playlists, profile, recommendations, youtube_music
|
||||
|
||||
app = FastAPI(title="Vynl API", version="1.0.0", redirect_slashes=False)
|
||||
|
||||
@@ -22,7 +22,6 @@ app.include_router(recommendations.router, prefix="/api")
|
||||
app.include_router(youtube_music.router, prefix="/api")
|
||||
app.include_router(manual_import.router, prefix="/api")
|
||||
app.include_router(lastfm.router, prefix="/api")
|
||||
app.include_router(bandcamp.router, prefix="/api")
|
||||
app.include_router(profile.router, prefix="/api")
|
||||
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ Already in their library (do NOT recommend these):
|
||||
{disliked_instruction}
|
||||
{exclude_instruction}
|
||||
|
||||
Respond with exactly {count * 3 if bandcamp_mode else count} music recommendations as a JSON array. Each item should have:
|
||||
Respond with exactly {count} music recommendations as a JSON array. Each item should have:
|
||||
- "title": song title
|
||||
- "artist": artist name
|
||||
- "album": album name (if known)
|
||||
@@ -216,9 +216,7 @@ Return ONLY the JSON array, no other text."""
|
||||
except json.JSONDecodeError:
|
||||
return [], remaining
|
||||
|
||||
from app.services.bandcamp import search_bandcamp_verified
|
||||
|
||||
# Save to DB — in bandcamp mode, only keep results verified on Bandcamp
|
||||
# Save to DB with YouTube links
|
||||
recommendations = []
|
||||
for rec in recs_data:
|
||||
if len(recommendations) >= count:
|
||||
@@ -226,24 +224,9 @@ Return ONLY the JSON array, no other text."""
|
||||
|
||||
artist = rec.get("artist", "Unknown")
|
||||
title = rec.get("title", "Unknown")
|
||||
bandcamp_url = None
|
||||
youtube_url = None
|
||||
|
||||
# Try Bandcamp for every recommendation
|
||||
try:
|
||||
match = await search_bandcamp_verified(artist, title)
|
||||
if match:
|
||||
bandcamp_url = match.get("bandcamp_url")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if bandcamp_mode and not bandcamp_url:
|
||||
# In bandcamp mode, skip recommendations not found on Bandcamp
|
||||
continue
|
||||
|
||||
# If not on Bandcamp, build a YouTube search link
|
||||
if not bandcamp_url:
|
||||
youtube_url = f"https://www.youtube.com/results?search_query={quote_plus(f'{artist} {title} official music video')}"
|
||||
# YouTube search link for every recommendation
|
||||
youtube_url = f"https://www.youtube.com/results?search_query={quote_plus(f'{artist} {title} official music video')}"
|
||||
|
||||
r = Recommendation(
|
||||
user_id=user.id,
|
||||
@@ -254,7 +237,6 @@ Return ONLY the JSON array, no other text."""
|
||||
reason=rec.get("reason", ""),
|
||||
score=rec.get("score"),
|
||||
query=query,
|
||||
bandcamp_url=bandcamp_url,
|
||||
youtube_url=youtube_url,
|
||||
)
|
||||
db.add(r)
|
||||
|
||||
Reference in New Issue
Block a user