Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, HTTPException, Query | |
| from pydantic import BaseModel | |
| from TeraboxDL import TeraboxDL | |
| from fastapi.responses import PlainTextResponse | |
| import time | |
| # --- CONFIGURATION --- | |
| NDUS = "Yu15lX9peHuivvLf8qgnwuyn4HME0cKkQsDWH5Mm" | |
| STOKEN = "E969796B6B3939DDC8AFEA4CA7C895C1033850933D59CCEA58C0A02D312033D8CCF3C357B925EBCD0B73A4CD9F5A5BFBBE666D0539455F6E16DF935E9D591248" | |
| full_cookie = f"lang=en; ndus={NDUS}; STOKEN={STOKEN}" | |
| # Timeout ko 60 seconds tak badha diya gaya hai library initialization mein | |
| terabox = TeraboxDL(full_cookie) | |
| app = FastAPI(title="Terabox Fix API") | |
| async def get_download_link(link: str = Query(...)): | |
| # Hum 3 baar koshish karenge agar timeout hota hai | |
| max_retries = 3 | |
| for attempt in range(max_retries): | |
| try: | |
| # Domain switch logic to avoid 1024terabox block | |
| clean_link = link.replace("1024terabox.com", "www.teraboxapp.com") | |
| file_info = terabox.get_file_info(clean_link) | |
| if isinstance(file_info, dict) and "error" in file_info: | |
| # Agar error 'timeout' hai toh retry karo | |
| if "timeout" in file_info["error"].lower() and attempt < max_retries - 1: | |
| time.sleep(2) # 2 second wait | |
| continue | |
| raise HTTPException(status_code=400, detail=file_info["error"]) | |
| dl_link = file_info.get("download_link") | |
| if dl_link: | |
| return dl_link | |
| except Exception as e: | |
| if attempt < max_retries - 1: | |
| time.sleep(2) | |
| continue | |
| raise HTTPException(status_code=500, detail=f"Server Timeout: {str(e)}") | |
| raise HTTPException(status_code=504, detail="TeraBox Server is too slow. Try again after 5 minutes.") | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |