Wire Bandcamp into AI recommendations - prioritize indie artists, attach Bandcamp links to results
This commit is contained in:
24
backend/alembic/versions/002_add_bandcamp_url.py
Normal file
24
backend/alembic/versions/002_add_bandcamp_url.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Add bandcamp_url to recommendations
|
||||
|
||||
Revision ID: 002
|
||||
Revises: 001
|
||||
Create Date: 2026-03-30
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = "002"
|
||||
down_revision: Union[str, None] = "001"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("recommendations", sa.Column("bandcamp_url", sa.String(500), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("recommendations", "bandcamp_url")
|
||||
@@ -20,6 +20,7 @@ class Recommendation(Base):
|
||||
spotify_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
preview_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
image_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
bandcamp_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
|
||||
# AI explanation
|
||||
reason: Mapped[str] = mapped_column(Text)
|
||||
|
||||
@@ -16,6 +16,7 @@ class RecommendationItem(BaseModel):
|
||||
spotify_id: str | None = None
|
||||
preview_url: str | None = None
|
||||
image_url: str | None = None
|
||||
bandcamp_url: str | None = None
|
||||
reason: str
|
||||
score: float | None = None
|
||||
saved: bool = False
|
||||
|
||||
@@ -129,7 +129,7 @@ Respond with exactly 5 music recommendations as a JSON array. Each item should h
|
||||
- "reason": A warm, personal 2-3 sentence explanation of WHY they'll love this track. Reference specific qualities from their taste profile. Be specific about sonic qualities, not generic.
|
||||
- "score": confidence score 0.0-1.0
|
||||
|
||||
Focus on discovery - prioritize lesser-known artists, deep cuts, and hidden gems over obvious popular choices.
|
||||
IMPORTANT: Strongly prioritize independent and underground artists who release music on Bandcamp. Think DIY, indie labels, self-released artists, and the kind of music you'd find crate-digging on Bandcamp. Mix in some Bandcamp-type artists alongside any well-known recommendations. Focus on real discovery — lesser-known artists, deep cuts, and hidden gems over obvious popular choices.
|
||||
Return ONLY the JSON array, no other text."""
|
||||
|
||||
# Call Claude API
|
||||
@@ -152,9 +152,22 @@ Return ONLY the JSON array, no other text."""
|
||||
except json.JSONDecodeError:
|
||||
return [], remaining
|
||||
|
||||
# Search Bandcamp for each recommendation to attach real links
|
||||
from app.services.bandcamp import search_bandcamp
|
||||
|
||||
# Save to DB
|
||||
recommendations = []
|
||||
for rec in recs_data[:5]:
|
||||
bandcamp_url = None
|
||||
try:
|
||||
results = await search_bandcamp(
|
||||
f"{rec.get('artist', '')} {rec.get('title', '')}", item_type="t"
|
||||
)
|
||||
if results:
|
||||
bandcamp_url = results[0].get("bandcamp_url")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
r = Recommendation(
|
||||
user_id=user.id,
|
||||
playlist_id=playlist_id,
|
||||
@@ -164,6 +177,7 @@ Return ONLY the JSON array, no other text."""
|
||||
reason=rec.get("reason", ""),
|
||||
score=rec.get("score"),
|
||||
query=query,
|
||||
bandcamp_url=bandcamp_url,
|
||||
)
|
||||
db.add(r)
|
||||
recommendations.append(r)
|
||||
|
||||
@@ -6,6 +6,7 @@ asyncpg==0.30.0
|
||||
psycopg2-binary==2.9.10
|
||||
python-jose[cryptography]==3.3.0
|
||||
passlib[bcrypt]==1.7.4
|
||||
bcrypt==4.0.1
|
||||
python-multipart==0.0.20
|
||||
pydantic[email]==2.10.4
|
||||
pydantic-settings==2.7.1
|
||||
|
||||
Reference in New Issue
Block a user