Update app.py
Browse files335 unmodified lines336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382335 unmodified linesclass ErrorResponse(BaseModel): detail: str
# --- API Endpoint ---@app.post( "/spot_dl", response_model=SpotDlResponse, responses={ 400: {"model": ErrorResponse, "description": "Bad Request - Invalid input"}, 422: {"model": ErrorResponse, "description": "Validation Error - Input data is not valid"} }, summary="Generate SpotDL Link", description="Accepts a URL and quality, returns a processed URL if quality is '128', " "otherwise returns an error for higher qualities.")async def create_spot_dl_link(request: SpotDlRequest = Body(...)): """ Processes a URL and quality to generate a download link.
- **url**: The URL to process (must be a valid HTTP/HTTPS URL). - **quality**: The desired quality. Must be one of "128", "320", "FLAC". Currently, only "128" will result in a successful link generation. """ # Log the received request for debugging (optional) print(f"Received request: url='{request.url}', quality='{request.quality}'")
# Check the quality if request.quality == "128": # URL-encode the input URL encoded_url = urllib.parse.quote(str(request.url), safe='') # Construct the target URL output_url = f"https://velynapi.vercel.app/api/downloader/spotifydl?url={encoded_url}" return SpotDlResponse(download_url=output_url) elif request.quality == "320" or request.quality == "FLAC": # If quality is 320 or FLAC, return an error as per requirements raise HTTPException( status_code=400, detail=f"Quality '{request.quality}' is for Premium Users Only. '128' is allowed." ) else: # This case should ideally be caught by Pydantic's Literal validation, # but as a fallback or for more general invalid quality values: raise HTTPException( status_code=400, detail=f"Invalid quality value: '{request.quality}'. Allowed values are '128', '320', 'FLAC'." )
app.py+44