Wire Bandcamp into AI recommendations - prioritize indie artists, attach Bandcamp links to results

This commit is contained in:
root
2026-03-30 23:42:03 -05:00
parent dd4df6a070
commit 37fccc6eef
9 changed files with 62 additions and 20 deletions

View 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")

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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