Spaces:
Paused
Paused
Update app.py
Browse files12234534 unmodified lines4041424344434445464748495051525354555657484958596061from fastapi import FastAPI, HTTPException, Queryfrom fastapi.responses import JSONResponsefrom fastapi.responses import JSONResponse, FileResponseimport osfrom yt_dlp import YoutubeDL
34 unmodified lines try: with YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(reel_url, download=True) filename = ydl.prepare_filename(info) if not os.path.exists(filename): original_filename = ydl.prepare_filename(info) # Ensure the file was created if not os.path.exists(original_filename): raise HTTPException(status_code=500, detail="Failed to download the Reel.") # Replace spaces with underscores in the filename base_name = os.path.basename(original_filename) sanitized_name = base_name.replace(" ", "_") sanitized_path = os.path.join(DOWNLOAD_DIR, sanitized_name) # Rename the file os.rename(original_filename, sanitized_path) # Construct the download link file_name = os.path.basename(filename) download_link = f"https://slimshadow-instagram-r-api.hf.space/files/{file_name}" download_link = f"http://your-domain.com/files/{sanitized_name}" return JSONResponse(content={"download_link": download_link}) except Exception as e:app.py+14-5