Spaces:
Paused
Paused
Update app.py
Browse files1234513 unmodified lines1920212223242526272829303111 unmodified lines43444546474849505152from fastapi import FastAPI, HTTPException, Queryfrom fastapi.responses import FileResponseimport osfrom yt_dlp import YoutubeDL13 unmodified linesreel_url: str = Query(..., description="The URL of the Instagram Reel to download"),):"""Download an Instagram Reel using yt-dlp.Args:reel_url (str): The URL of the Instagram Reel.Returns:FileResponse: The path to the downloaded file."""if not reel_url:raise HTTPException(status_code=400, detail="The 'reel_url' parameter is required.")11 unmodified linesfilename = 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")except Exception as e:raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")1234513 unmodified lines1920212223242526272829303111 unmodified lines434445464748495051525354555657585960616263from fastapi import FastAPI, HTTPException, Queryfrom fastapi.responses import JSONResponseimport osfrom yt_dlp import YoutubeDL13 unmodified linesreel_url: str = Query(..., description="The URL of the Instagram Reel to download"),):"""Download an Instagram Reel using yt-dlp and provide a download link.Args:reel_url (str): The URL of the Instagram Reel.Returns: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 linesfilename = ydl.prepare_filename(info)if not os.path.exists(filename):raise HTTPException(status_code=500, detail="Failed to download the Reel.")# Construct the download linkfile_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