from fastapi import FastAPI, Query, HTTPException from fastapi.responses import JSONResponse import uvicorn from downloader import download_song from config import settings import os # Make sure the music directory exists os.makedirs(settings.MUSIC_DIR, exist_ok=True) app = FastAPI(title="Tunedrop") @app.get("/download") def download(query: str = Query(..., description="Song name or YouTube search term")): try: result = download_song(query) return JSONResponse(content={"status": "success", **result}) except Exception as e: raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)