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)
|
spotify_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||||
preview_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
preview_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||||
image_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
|
# AI explanation
|
||||||
reason: Mapped[str] = mapped_column(Text)
|
reason: Mapped[str] = mapped_column(Text)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class RecommendationItem(BaseModel):
|
|||||||
spotify_id: str | None = None
|
spotify_id: str | None = None
|
||||||
preview_url: str | None = None
|
preview_url: str | None = None
|
||||||
image_url: str | None = None
|
image_url: str | None = None
|
||||||
|
bandcamp_url: str | None = None
|
||||||
reason: str
|
reason: str
|
||||||
score: float | None = None
|
score: float | None = None
|
||||||
saved: bool = False
|
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.
|
- "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
|
- "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."""
|
Return ONLY the JSON array, no other text."""
|
||||||
|
|
||||||
# Call Claude API
|
# Call Claude API
|
||||||
@@ -152,9 +152,22 @@ Return ONLY the JSON array, no other text."""
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
return [], remaining
|
return [], remaining
|
||||||
|
|
||||||
|
# Search Bandcamp for each recommendation to attach real links
|
||||||
|
from app.services.bandcamp import search_bandcamp
|
||||||
|
|
||||||
# Save to DB
|
# Save to DB
|
||||||
recommendations = []
|
recommendations = []
|
||||||
for rec in recs_data[:5]:
|
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(
|
r = Recommendation(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
playlist_id=playlist_id,
|
playlist_id=playlist_id,
|
||||||
@@ -164,6 +177,7 @@ Return ONLY the JSON array, no other text."""
|
|||||||
reason=rec.get("reason", ""),
|
reason=rec.get("reason", ""),
|
||||||
score=rec.get("score"),
|
score=rec.get("score"),
|
||||||
query=query,
|
query=query,
|
||||||
|
bandcamp_url=bandcamp_url,
|
||||||
)
|
)
|
||||||
db.add(r)
|
db.add(r)
|
||||||
recommendations.append(r)
|
recommendations.append(r)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ asyncpg==0.30.0
|
|||||||
psycopg2-binary==2.9.10
|
psycopg2-binary==2.9.10
|
||||||
python-jose[cryptography]==3.3.0
|
python-jose[cryptography]==3.3.0
|
||||||
passlib[bcrypt]==1.7.4
|
passlib[bcrypt]==1.7.4
|
||||||
|
bcrypt==4.0.1
|
||||||
python-multipart==0.0.20
|
python-multipart==0.0.20
|
||||||
pydantic[email]==2.10.4
|
pydantic[email]==2.10.4
|
||||||
pydantic-settings==2.7.1
|
pydantic-settings==2.7.1
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ COPY . .
|
|||||||
|
|
||||||
EXPOSE 5173
|
EXPOSE 5173
|
||||||
|
|
||||||
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
|
CMD ["npx", "vite", "--host", "0.0.0.0"]
|
||||||
|
|||||||
@@ -61,25 +61,25 @@ export default function RecommendationCard({ recommendation, onToggleSave, savin
|
|||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{recommendation.spotify_url && (
|
{recommendation.bandcamp_url ? (
|
||||||
<a
|
<a
|
||||||
href={recommendation.spotify_url}
|
href={recommendation.bandcamp_url}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="p-2 rounded-full bg-green-50 text-green-600 hover:bg-green-100 transition-colors"
|
className="p-2 rounded-full bg-amber-50 text-amber-700 hover:bg-amber-100 transition-colors"
|
||||||
title="Open in Spotify"
|
title="Listen on Bandcamp"
|
||||||
>
|
>
|
||||||
<ExternalLink className="w-4 h-4" />
|
<ExternalLink className="w-4 h-4" />
|
||||||
</a>
|
</a>
|
||||||
|
) : (
|
||||||
|
<Link
|
||||||
|
to={`/listen?q=${encodeURIComponent(`${recommendation.artist} ${recommendation.title}`)}`}
|
||||||
|
className="p-2 rounded-full bg-purple-50 text-purple-400 hover:bg-purple-100 hover:text-purple transition-colors"
|
||||||
|
title="Find on Bandcamp"
|
||||||
|
>
|
||||||
|
<Headphones className="w-4 h-4" />
|
||||||
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Link
|
|
||||||
to={`/listen?q=${encodeURIComponent(`${recommendation.artist} ${recommendation.title}`)}`}
|
|
||||||
className="p-2 rounded-full bg-purple-50 text-purple-400 hover:bg-purple-100 hover:text-purple transition-colors"
|
|
||||||
title="Find on Bandcamp"
|
|
||||||
>
|
|
||||||
<Headphones className="w-4 h-4" />
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export interface RecommendationItem {
|
|||||||
album: string
|
album: string
|
||||||
image_url: string | null
|
image_url: string | null
|
||||||
spotify_url: string | null
|
spotify_url: string | null
|
||||||
|
bandcamp_url: string | null
|
||||||
reason: string
|
reason: string
|
||||||
saved: boolean
|
saved: boolean
|
||||||
created_at: string
|
created_at: string
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { ListMusic, Plus, Loader2, Music, ChevronRight, Download, X, Youtube, Link2, ClipboardPaste } from 'lucide-react'
|
import { ListMusic, Plus, Loader2, Music, ChevronRight, Download, X, Play, Link2, ClipboardPaste } from 'lucide-react'
|
||||||
import { getPlaylists, getSpotifyPlaylists, importSpotifyPlaylist, importYouTubePlaylist, previewLastfm, importLastfm, importPastedSongs, type PlaylistResponse, type SpotifyPlaylistItem, type LastfmPreviewResponse } from '../lib/api'
|
import { getPlaylists, getSpotifyPlaylists, importSpotifyPlaylist, importYouTubePlaylist, previewLastfm, importLastfm, importPastedSongs, type PlaylistResponse, type SpotifyPlaylistItem, type LastfmPreviewResponse } from '../lib/api'
|
||||||
|
|
||||||
export default function Playlists() {
|
export default function Playlists() {
|
||||||
@@ -8,7 +8,7 @@ export default function Playlists() {
|
|||||||
const [spotifyPlaylists, setSpotifyPlaylists] = useState<SpotifyPlaylistItem[]>([])
|
const [spotifyPlaylists, setSpotifyPlaylists] = useState<SpotifyPlaylistItem[]>([])
|
||||||
const [showImport, setShowImport] = useState(false)
|
const [showImport, setShowImport] = useState(false)
|
||||||
const [showYouTubeImport, setShowYouTubeImport] = useState(false)
|
const [showYouTubeImport, setShowYouTubeImport] = useState(false)
|
||||||
const [youtubeUrl, setYoutubeUrl] = useState('')
|
const [youtubeUrl, setPlayUrl] = useState('')
|
||||||
const [importingYouTube, setImportingYouTube] = useState(false)
|
const [importingYouTube, setImportingYouTube] = useState(false)
|
||||||
const [importing, setImporting] = useState<string | null>(null)
|
const [importing, setImporting] = useState<string | null>(null)
|
||||||
const [loadingSpotify, setLoadingSpotify] = useState(false)
|
const [loadingSpotify, setLoadingSpotify] = useState(false)
|
||||||
@@ -60,7 +60,7 @@ export default function Playlists() {
|
|||||||
try {
|
try {
|
||||||
const imported = await importYouTubePlaylist(youtubeUrl.trim())
|
const imported = await importYouTubePlaylist(youtubeUrl.trim())
|
||||||
setPlaylists((prev) => [...prev, imported])
|
setPlaylists((prev) => [...prev, imported])
|
||||||
setYoutubeUrl('')
|
setPlayUrl('')
|
||||||
setShowYouTubeImport(false)
|
setShowYouTubeImport(false)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError(err.response?.data?.detail || 'Failed to import YouTube Music playlist')
|
setError(err.response?.data?.detail || 'Failed to import YouTube Music playlist')
|
||||||
@@ -162,7 +162,7 @@ export default function Playlists() {
|
|||||||
onClick={() => setShowYouTubeImport(true)}
|
onClick={() => setShowYouTubeImport(true)}
|
||||||
className="flex items-center gap-2 px-5 py-2.5 bg-red-600 text-white font-medium rounded-xl hover:bg-red-700 transition-colors cursor-pointer border-none text-sm"
|
className="flex items-center gap-2 px-5 py-2.5 bg-red-600 text-white font-medium rounded-xl hover:bg-red-700 transition-colors cursor-pointer border-none text-sm"
|
||||||
>
|
>
|
||||||
<Youtube className="w-4 h-4" />
|
<Play className="w-4 h-4" />
|
||||||
Import from YouTube Music
|
Import from YouTube Music
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@@ -210,7 +210,7 @@ export default function Playlists() {
|
|||||||
onClick={() => setShowYouTubeImport(true)}
|
onClick={() => setShowYouTubeImport(true)}
|
||||||
className="inline-flex items-center gap-2 px-6 py-3 bg-red-600 text-white font-medium rounded-xl hover:bg-red-700 transition-colors cursor-pointer border-none text-sm"
|
className="inline-flex items-center gap-2 px-6 py-3 bg-red-600 text-white font-medium rounded-xl hover:bg-red-700 transition-colors cursor-pointer border-none text-sm"
|
||||||
>
|
>
|
||||||
<Youtube className="w-4 h-4" />
|
<Play className="w-4 h-4" />
|
||||||
Import from YouTube Music
|
Import from YouTube Music
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@@ -291,7 +291,7 @@ export default function Playlists() {
|
|||||||
<input
|
<input
|
||||||
type="url"
|
type="url"
|
||||||
value={youtubeUrl}
|
value={youtubeUrl}
|
||||||
onChange={(e) => setYoutubeUrl(e.target.value)}
|
onChange={(e) => setPlayUrl(e.target.value)}
|
||||||
placeholder="https://music.youtube.com/playlist?list=..."
|
placeholder="https://music.youtube.com/playlist?list=..."
|
||||||
className="w-full pl-10 pr-4 py-3 bg-cream/50 border border-purple-100 rounded-xl text-charcoal placeholder:text-charcoal-muted/40 focus:outline-none focus:ring-2 focus:ring-purple/30 focus:border-purple transition-colors text-sm"
|
className="w-full pl-10 pr-4 py-3 bg-cream/50 border border-purple-100 rounded-xl text-charcoal placeholder:text-charcoal-muted/40 focus:outline-none focus:ring-2 focus:ring-purple/30 focus:border-purple transition-colors text-sm"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user