Spaces:
No application file
No application file
Upload 2 files
Browse files- app (1).py +56 -0
- requirements.txt +4 -0
app (1).py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Query
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from TeraboxDL import TeraboxDL
|
| 4 |
+
from fastapi.responses import PlainTextResponse
|
| 5 |
+
|
| 6 |
+
# Initialize cookie and downloader
|
| 7 |
+
cookie = "lang=en; ndus=YVoWvgEteHui-NdzSUQue1sOeq1Ixk1H1Up2AAQP"
|
| 8 |
+
terabox = TeraboxDL(cookie)
|
| 9 |
+
|
| 10 |
+
# Create FastAPI app
|
| 11 |
+
app = FastAPI(
|
| 12 |
+
title="Terabox Direct Link API",
|
| 13 |
+
description="Get direct download link from Terabox share URL",
|
| 14 |
+
version="1.0.0"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
class LinkRequest(BaseModel):
|
| 18 |
+
link: str
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@app.get("/")
|
| 22 |
+
def read_root():
|
| 23 |
+
return {"message": "Visit /docs for API documentation"}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@app.get("/download", response_class=PlainTextResponse)
|
| 27 |
+
async def get_download_link(link: str = Query(...)):
|
| 28 |
+
try:
|
| 29 |
+
file_info = terabox.get_file_info(link)
|
| 30 |
+
if "error" in file_info:
|
| 31 |
+
raise HTTPException(status_code=400, detail=file_info["error"])
|
| 32 |
+
dl_link = file_info.get("download_link")
|
| 33 |
+
if not dl_link:
|
| 34 |
+
raise HTTPException(status_code=404, detail="Download link not found")
|
| 35 |
+
return dl_link
|
| 36 |
+
except Exception as e:
|
| 37 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@app.post("/download", response_class=PlainTextResponse)
|
| 41 |
+
async def post_download_link(request: LinkRequest):
|
| 42 |
+
try:
|
| 43 |
+
file_info = terabox.get_file_info(request.link)
|
| 44 |
+
if "error" in file_info:
|
| 45 |
+
raise HTTPException(status_code=400, detail=file_info["error"])
|
| 46 |
+
dl_link = file_info.get("download_link")
|
| 47 |
+
if not dl_link:
|
| 48 |
+
raise HTTPException(status_code=404, detail="Download link not found")
|
| 49 |
+
return dl_link
|
| 50 |
+
except Exception as e:
|
| 51 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
import uvicorn
|
| 56 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
httpx
|
| 4 |
+
terabox-downloader
|