Spaces:
Paused
Paused
File size: 1,781 Bytes
8f2c38e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 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
@app.get("/")
def read_root():
return {"message": "Visit /docs for API documentation"}
@app.get("/download", response_class=PlainTextResponse)
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))
@app.post("/download", response_class=PlainTextResponse)
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) |