|
from fastapi import FastAPI, HTTPException |
|
from deezspot.deezloader import DeeLogin |
|
import requests |
|
from typing import Optional |
|
|
|
app = FastAPI(title="Deezer API") |
|
|
|
|
|
DEEZER_API_URL = "https://api.deezer.com" |
|
|
|
|
|
ARL_TOKEN = "f10b97c01d087e29c71e1b1950f220244f57e199e923e5fc975b45533a497daac4831349242ea9dbc9ee56b6c27970c28314dfe7777be10cc516a1e91125f2b322521b83644e1a7c533709f29453ab44414466cc8a1bdebdd37240c8c84a2a" |
|
dl = DeeLogin(arl=ARL_TOKEN) |
|
|
|
@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: |
|
response = requests.get(f"{DEEZER_API_URL}/track/{track_id}") |
|
if response.status_code != 200: |
|
raise HTTPException(status_code=404, detail="Track not found") |
|
return response.json() |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
|
|
@app.post("/download/track/{track_id}") |
|
def download_track(track_id: str, quality: str = "MP3_320"): |
|
try: |
|
|
|
track_info = requests.get(f"{DEEZER_API_URL}/track/{track_id}").json() |
|
track_link = track_info.get("link") |
|
if not track_link: |
|
raise HTTPException(status_code=404, detail="Track link not found") |
|
|
|
|
|
dl.download_trackdee( |
|
link_track=track_link, |
|
output_dir="./downloads", |
|
quality_download=quality, |
|
recursive_quality=False, |
|
recursive_download=False |
|
) |
|
return {"message": f"Track {track_id} downloaded successfully"} |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
|
|
@app.get("/search") |
|
def search_tracks(query: str, limit: Optional[int] = 10): |
|
try: |
|
response = requests.get(f"{DEEZER_API_URL}/search", params={"q": query, "limit": limit}) |
|
return response.json() |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |