Spaces:
Paused
Paused
| from fastapi import FastAPI, HTTPException, Query | |
| from pydantic import BaseModel | |
| from TeraboxDL import TeraboxDL | |
| from fastapi.responses import PlainTextResponse | |
| # Initialize cookie and downloader | |
| cookie = "lang=en; ndus=YVoWvgEteHui-NdzSUQue1sOeq1Ixk1H1Up2AAQP" | |
| terabox = TeraboxDL(cookie) | |
| # Create FastAPI app | |
| app = FastAPI( | |
| title="Terabox Direct Link API", | |
| description="Get direct download link from Terabox share URL", | |
| version="1.0.0" | |
| ) | |
| class LinkRequest(BaseModel): | |
| link: str | |
| def read_root(): | |
| return {"message": "Visit /docs for API documentation"} | |
| async def get_download_link(link: str = Query(...)): | |
| try: | |
| file_info = terabox.get_file_info(link) | |
| if "error" in file_info: | |
| raise HTTPException(status_code=400, detail=file_info["error"]) | |
| dl_link = file_info.get("download_link") | |
| if not dl_link: | |
| raise HTTPException(status_code=404, detail="Download link not found") | |
| return dl_link | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def post_download_link(request: LinkRequest): | |
| try: | |
| file_info = terabox.get_file_info(request.link) | |
| if "error" in file_info: | |
| raise HTTPException(status_code=400, detail=file_info["error"]) | |
| dl_link = file_info.get("download_link") | |
| if not dl_link: | |
| raise HTTPException(status_code=404, detail="Download link not found") | |
| return dl_link | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |