Spaces:
No application file
No application file
Create terabox.py
Browse files- terabox.py +84 -0
terabox.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# terabox.py
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
import requests
|
| 5 |
+
from urllib.parse import parse_qs, urlparse
|
| 6 |
+
from tools import get_formatted_size # Optional
|
| 7 |
+
|
| 8 |
+
# Check supported domains
|
| 9 |
+
def check_url_patterns(url):
|
| 10 |
+
patterns = [
|
| 11 |
+
r"ww\.mirrobox\.com",
|
| 12 |
+
r"www\.nephobox\.com",
|
| 13 |
+
r"freeterabox\.com",
|
| 14 |
+
r"www\.freeterabox\.com",
|
| 15 |
+
r"1024tera\.com",
|
| 16 |
+
r"4funbox\.co",
|
| 17 |
+
r"www\.4funbox\.com",
|
| 18 |
+
r"mirrobox\.com",
|
| 19 |
+
r"nephobox\.com",
|
| 20 |
+
r"terabox\.app",
|
| 21 |
+
r"terabox\.com",
|
| 22 |
+
r"www\.terabox\.ap",
|
| 23 |
+
r"www\.terabox\.com",
|
| 24 |
+
r"www\.1024tera\.co",
|
| 25 |
+
r"www\.momerybox\.com",
|
| 26 |
+
r"teraboxapp\.com",
|
| 27 |
+
r"momerybox\.com",
|
| 28 |
+
r"tibibox\.com",
|
| 29 |
+
r"www\.tibibox\.com",
|
| 30 |
+
r"www\.teraboxapp\.com",
|
| 31 |
+
]
|
| 32 |
+
return any(re.search(pattern, url) for pattern in patterns)
|
| 33 |
+
|
| 34 |
+
# Extract URL
|
| 35 |
+
def get_urls_from_string(string: str) -> str:
|
| 36 |
+
pattern = r"(https?://\S+)"
|
| 37 |
+
urls = re.findall(pattern, string)
|
| 38 |
+
urls = [url for url in urls if check_url_patterns(url)]
|
| 39 |
+
return urls[0] if urls else ""
|
| 40 |
+
|
| 41 |
+
# Extract surl param
|
| 42 |
+
def extract_surl_from_url(url: str) -> str | None:
|
| 43 |
+
parsed_url = urlparse(url)
|
| 44 |
+
query_params = parse_qs(parsed_url.query)
|
| 45 |
+
surl = query_params.get("surl", [])
|
| 46 |
+
return surl[0] if surl else False
|
| 47 |
+
|
| 48 |
+
# Get download info from API
|
| 49 |
+
def get_data(url: str):
|
| 50 |
+
try:
|
| 51 |
+
api_url = "https://terabox-downloader-direct-download-link-generator2.p.rapidapi.com/url"
|
| 52 |
+
headers = {
|
| 53 |
+
"x-rapidapi-host": "terabox-downloader-direct-download-link-generator2.p.rapidapi.com",
|
| 54 |
+
"x-rapidapi-key": "e001039e2emshf6e499c6afe75f3p1723fdjsn1c9cc179bde0",
|
| 55 |
+
}
|
| 56 |
+
params = {"url": url}
|
| 57 |
+
|
| 58 |
+
response = requests.get(api_url, headers=headers, params=params, timeout=15)
|
| 59 |
+
if response.status_code != 200:
|
| 60 |
+
print(f"❌ API error: {response.status_code} - {response.text}")
|
| 61 |
+
return False
|
| 62 |
+
|
| 63 |
+
data = response.json()
|
| 64 |
+
|
| 65 |
+
# Handle case where API returns a list with a dict inside
|
| 66 |
+
if isinstance(data, list) and len(data) > 0 and isinstance(data[0], dict):
|
| 67 |
+
data = data[0]
|
| 68 |
+
|
| 69 |
+
if not data or "file_name" not in data:
|
| 70 |
+
print(f"⚠️ Unexpected API response: {data}")
|
| 71 |
+
return False
|
| 72 |
+
|
| 73 |
+
return {
|
| 74 |
+
"file_name": data.get("file_name"),
|
| 75 |
+
"link": data.get("link"),
|
| 76 |
+
"direct_link": data.get("direct_link"),
|
| 77 |
+
"thumb": data.get("thumb"),
|
| 78 |
+
"size": data.get("size"),
|
| 79 |
+
"sizebytes": int(data.get("sizebytes", 0)),
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
except Exception as e:
|
| 83 |
+
print(f"❌ Exception in get_data: {e}")
|
| 84 |
+
return False
|