File size: 860 Bytes
ff7a5f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from fastapi import FastAPI, HTTPException
from deezspot import Deezer
from typing import Optional
app = FastAPI(title="Deezer API")
dz = Deezer()
@app.get("/")
def read_root():
return {"message": "Deezer API Endpoints - Use /track/{track_id}"}
@app.get("/track/{track_id}")
def get_track(track_id: str):
try:
track = dz.get_track(track_id)
if not track:
raise HTTPException(status_code=404, detail="Track not found")
return track
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
# Additional endpoint: Search tracks
@app.get("/search")
def search_tracks(query: str, limit: Optional[int] = 10):
try:
results = dz.search(query, limit=limit)
return {"results": results}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) |