Spaces:
Paused
Paused
Update app.py
Browse files1234534 unmodified lines40414243444546474849505152from fastapi import FastAPI, HTTPException, Queryfrom fastapi.responses import JSONResponseimport osfrom yt_dlp import YoutubeDL34 unmodified linestry: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):raise HTTPException(status_code=500, detail="Failed to download the Reel.")# Construct the download linkfile_name = os.path.basename(filename)download_link = f"https://slimshadow-instagram-r-api.hf.space/files/{file_name}"return JSONResponse(content={"download_link": download_link})except Exception as e:1234534 unmodified lines40414243444546474849505152535455565758596061from fastapi import FastAPI, HTTPException, Queryfrom fastapi.responses import JSONResponse, FileResponseimport osfrom yt_dlp import YoutubeDL34 unmodified linestry:with YoutubeDL(ydl_opts) as ydl:info = ydl.extract_info(reel_url, download=True)original_filename = ydl.prepare_filename(info)# Ensure the file was createdif not os.path.exists(original_filename):raise HTTPException(status_code=500, detail="Failed to download the Reel.")# Replace spaces with underscores in the filenamebase_name = os.path.basename(original_filename)sanitized_name = base_name.replace(" ", "_")sanitized_path = os.path.join(DOWNLOAD_DIR, sanitized_name)# Rename the fileos.rename(original_filename, sanitized_path)# Construct the download linkdownload_link = f"http://your-domain.com/files/{sanitized_name}"return JSONResponse(content={"download_link": download_link})except Exception as e:
app.py+14-5