-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathterabox.py
167 lines (142 loc) · 4.62 KB
/
terabox.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import re
from pprint import pp
from urllib.parse import parse_qs, urlparse
import requests
from tools import get_formatted_size
def check_url_patterns(url):
patterns = [
r"ww\.mirrobox\.com",
r"www\.nephobox\.com",
r"freeterabox\.com",
r"www\.freeterabox\.com",
r"1024tera\.com",
r"4funbox\.co",
r"www\.4funbox\.com",
r"mirrobox\.com",
r"nephobox\.com",
r"terabox\.app",
r"terabox\.com",
r"www\.terabox\.ap",
r"www\.terabox\.com",
r"www\.1024tera\.co",
r"www\.momerybox\.com",
r"teraboxapp\.com",
r"momerybox\.com",
r"tibibox\.com",
r"www\.tibibox\.com",
r"www\.teraboxapp\.com",
]
for pattern in patterns:
if re.search(pattern, url):
return True
return False
def get_urls_from_string(string: str) -> list[str]:
"""
Extracts URLs from a given string.
Args:
string (str): The input string from which to extract URLs.
Returns:
list[str]: A list of URLs extracted from the input string. If no URLs are found, an empty list is returned.
"""
pattern = r"(https?://\S+)"
urls = re.findall(pattern, string)
urls = [url for url in urls if check_url_patterns(url)]
if not urls:
return []
return urls[0]
def find_between(data: str, first: str, last: str) -> str | None:
"""
Searches for the first occurrence of the `first` string in `data`,
and returns the text between the two strings.
Args:
data (str): The input string.
first (str): The first string to search for.
last (str): The last string to search for.
Returns:
str | None: The text between the two strings, or None if the
`first` string was not found in `data`.
"""
try:
start = data.index(first) + len(first)
end = data.index(last, start)
return data[start:end]
except ValueError:
return None
def extract_surl_from_url(url: str) -> str | None:
"""
Extracts the surl parameter from a given URL.
Args:
url (str): The URL from which to extract the surl parameter.
Returns:
str: The surl parameter, or False if the parameter could not be found.
"""
parsed_url = urlparse(url)
query_params = parse_qs(parsed_url.query)
surl = query_params.get("surl", [])
if surl:
return surl[0]
else:
return False
def get_data(url: str):
netloc = urlparse(url).netloc
url = url.replace(netloc, "1024terabox.com")
response = requests.get(
url,
data="",
)
if not response.status_code == 200:
return False
default_thumbnail = find_between(response.text, 'og:image" content="', '"')
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/json",
"Origin": "https://ytshorts.savetube.me",
"Alt-Used": "ytshorts.savetube.me",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
}
response = requests.post(
"https://ytshorts.savetube.me/api/v1/terabox-downloader",
headers=headers,
json={"url": url},
)
if response.status_code != 200:
return False
response = response.json()
responses = response.get("response", [])
if not responses:
return False
resolutions = responses[0].get("resolutions", [])
if not resolutions:
return False
download = resolutions.get("Fast Download", "")
video = resolutions.get("HD Video", "")
response = requests.request(
"HEAD",
video,
data="",
)
content_length = response.headers.get("Content-Length", 0)
if not content_length:
content_length = None
idk = response.headers.get("content-disposition")
if idk:
fname = re.findall('filename="(.+)"', idk)
else:
fname = None
response = requests.head(
download,
)
direct_link = response.headers.get("location")
data = {
"file_name": (fname[0] if fname else None),
"link": (video if video else None),
"direct_link": (direct_link if direct_link else download if list else None),
"thumb": (default_thumbnail if default_thumbnail else None),
"size": (get_formatted_size(int(content_length)) if content_length else None),
"sizebytes": (int(content_length) if content_length else None),
}
return data