Spaces:
Paused
Paused
Update app.py
Browse files12234513 unmodified lines19202122222324252627282829303111 unmodified lines4344454647484950464748495051525354555657585960616263from fastapi import FastAPI, HTTPException, Queryfrom fastapi.responses import FileResponsefrom fastapi.responses import JSONResponseimport osfrom yt_dlp import YoutubeDL
13 unmodified lines reel_url: str = Query(..., description="The URL of the Instagram Reel to download"),): """ Download an Instagram Reel using yt-dlp. Download an Instagram Reel using yt-dlp and provide a download link. Args: reel_url (str): The URL of the Instagram Reel. Returns: FileResponse: The path to the downloaded file. JSONResponse: A JSON object containing the download link. """ if not reel_url: raise HTTPException(status_code=400, detail="The 'reel_url' parameter is required.")11 unmodified lines filename = ydl.prepare_filename(info) if not os.path.exists(filename): raise HTTPException(status_code=500, detail="Failed to download the Reel.") return FileResponse( path=filename, filename=os.path.basename(filename), media_type="video/mp4" ) # Construct the download link file_name = os.path.basename(filename) download_link = f"http://your-domain.com/files/{file_name}" return JSONResponse(content={"download_link": download_link}) except Exception as e: raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
@app.get("/files/{file_name}")def serve_file(file_name: str): """ Serve the downloaded file for users to download. """ file_path = os.path.join(DOWNLOAD_DIR, file_name) if not os.path.exists(file_path): raise HTTPException(status_code=404, detail="File not found.") return FileResponse(path=file_path, filename=file_name, media_type="video/mp4")app.py+19-8