mirror of
https://github.com/bnair123/MusicAnalyser.git
synced 2026-02-25 11:46:07 +00:00
Implement Phase 2 Frontend and Phase 3 Data Enrichment
- Initialize React+Vite Frontend with Ant Design Dashboard. - Implement Data Enrichment: ReccoBeats (Audio Features) and Spotify (Genres). - Update Database Schema via Alembic Migrations. - Add Docker support (Dockerfile, docker-compose.yml). - Update README with hosting instructions.
This commit is contained in:
@@ -3,6 +3,7 @@ import base64
|
||||
import time
|
||||
import httpx
|
||||
from fastapi import HTTPException
|
||||
from typing import List, Dict, Any
|
||||
|
||||
SPOTIFY_TOKEN_URL = "https://accounts.spotify.com/api/token"
|
||||
SPOTIFY_API_BASE = "https://api.spotify.com/v1"
|
||||
@@ -68,3 +69,26 @@ class SpotifyClient:
|
||||
if response.status_code != 200:
|
||||
return None
|
||||
return response.json()
|
||||
|
||||
async def get_artists(self, artist_ids: List[str]) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Fetches artist details (including genres) for a list of artist IDs.
|
||||
Spotify allows up to 50 IDs per request.
|
||||
"""
|
||||
if not artist_ids:
|
||||
return []
|
||||
|
||||
token = await self.get_access_token()
|
||||
ids_param = ",".join(artist_ids)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
f"{SPOTIFY_API_BASE}/artists",
|
||||
params={"ids": ids_param},
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
if response.status_code != 200:
|
||||
print(f"Error fetching artists: {response.text}")
|
||||
return []
|
||||
|
||||
return response.json().get("artists", [])
|
||||
|
||||
Reference in New Issue
Block a user