Pubgbc9799 commited on
Commit
20b6481
·
verified ·
1 Parent(s): b9a2ff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -18
app.py CHANGED
@@ -1,32 +1,50 @@
1
  from fastapi import FastAPI, HTTPException, Query
 
2
  from TeraboxDL import TeraboxDL
3
  from fastapi.responses import PlainTextResponse
 
4
 
5
- # Aapki values
6
  NDUS = "Yu15lX9peHuivvLf8qgnwuyn4HME0cKkQsDWH5Mm"
7
  STOKEN = "E969796B6B3939DDC8AFEA4CA7C895C1033850933D59CCEA58C0A02D312033D8CCF3C357B925EBCD0B73A4CD9F5A5BFBBE666D0539455F6E16DF935E9D591248"
8
 
9
- # Yahan hum manually token force karenge
10
- # Note: TeraboxDL library ke version ke hisaab se variable name 'jstoken' ya 'token' ho sakta hai
11
  full_cookie = f"lang=en; ndus={NDUS}; STOKEN={STOKEN}"
12
 
13
- app = FastAPI()
14
  terabox = TeraboxDL(full_cookie)
15
 
 
 
16
  @app.get("/download", response_class=PlainTextResponse)
17
  async def get_download_link(link: str = Query(...)):
18
- try:
19
- # Hum domain badal kar check karenge (Ye aksar block bypass karta hai)
20
- target_link = link.replace("1024terabox.com", "www.teraboxapp.com")
21
-
22
- file_info = terabox.get_file_info(target_link)
23
-
24
- if isinstance(file_info, dict) and "error" in file_info:
25
- # Agar extraction fail ho rahi hai, toh iska matlab browser block hai
26
- if "extract" in file_info["error"].lower():
27
- return "❌ Error: TeraBox ne Hugging Face ko block kar diya hai. Naya STOKEN nikaal kar update karein."
28
- raise HTTPException(status_code=400, detail=file_info["error"])
 
 
 
 
29
 
30
- return file_info.get("download_link", "Link not found")
31
- except Exception as e:
32
- raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, HTTPException, Query
2
+ from pydantic import BaseModel
3
  from TeraboxDL import TeraboxDL
4
  from fastapi.responses import PlainTextResponse
5
+ import time
6
 
7
+ # --- CONFIGURATION ---
8
  NDUS = "Yu15lX9peHuivvLf8qgnwuyn4HME0cKkQsDWH5Mm"
9
  STOKEN = "E969796B6B3939DDC8AFEA4CA7C895C1033850933D59CCEA58C0A02D312033D8CCF3C357B925EBCD0B73A4CD9F5A5BFBBE666D0539455F6E16DF935E9D591248"
10
 
 
 
11
  full_cookie = f"lang=en; ndus={NDUS}; STOKEN={STOKEN}"
12
 
13
+ # Timeout ko 60 seconds tak badha diya gaya hai library initialization mein
14
  terabox = TeraboxDL(full_cookie)
15
 
16
+ app = FastAPI(title="Terabox Fix API")
17
+
18
  @app.get("/download", response_class=PlainTextResponse)
19
  async def get_download_link(link: str = Query(...)):
20
+ # Hum 3 baar koshish karenge agar timeout hota hai
21
+ max_retries = 3
22
+ for attempt in range(max_retries):
23
+ try:
24
+ # Domain switch logic to avoid 1024terabox block
25
+ clean_link = link.replace("1024terabox.com", "www.teraboxapp.com")
26
+
27
+ file_info = terabox.get_file_info(clean_link)
28
+
29
+ if isinstance(file_info, dict) and "error" in file_info:
30
+ # Agar error 'timeout' hai toh retry karo
31
+ if "timeout" in file_info["error"].lower() and attempt < max_retries - 1:
32
+ time.sleep(2) # 2 second wait
33
+ continue
34
+ raise HTTPException(status_code=400, detail=file_info["error"])
35
 
36
+ dl_link = file_info.get("download_link")
37
+ if dl_link:
38
+ return dl_link
39
+
40
+ except Exception as e:
41
+ if attempt < max_retries - 1:
42
+ time.sleep(2)
43
+ continue
44
+ raise HTTPException(status_code=500, detail=f"Server Timeout: {str(e)}")
45
+
46
+ raise HTTPException(status_code=504, detail="TeraBox Server is too slow. Try again after 5 minutes.")
47
+
48
+ if __name__ == "__main__":
49
+ import uvicorn
50
+ uvicorn.run(app, host="0.0.0.0", port=7860)