-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddl.py
484 lines (442 loc) · 18.8 KB
/
ddl.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
from requests import get as rget, head as rhead, post as rpost, Session as rsession
from re import findall as re_findall, sub as re_sub, match as re_match, search as re_search
from urllib.parse import urlparse, unquote
from json import loads as jsonloads
from lk21 import Bypass
from cfscrape import create_scraper
from bs4 import BeautifulSoup
from base64 import standard_b64encode
from time import sleep
import cloudscraper
import hashlib
import requests
import os
from config import log, Vars, sys
# Setup Logger
log.basicConfig(
level=log.INFO,
datefmt="%d/%m/%Y %H:%M:%S",
format="[%(asctime)s][%(levelname)s] => %(message)s",
handlers=[log.StreamHandler(stream=sys.stdout),
log.FileHandler("runtime-log.txt", mode="a", encoding="utf-8")],)
UPTOBOX_TOKEN = Vars[8]
class DirectDownloadLinkException(Exception):
"""Not method found for extracting direct download link from the http link"""
pass
def yandex_disk(url: str) -> str:
""" Yandex.Disk direct link generator
Based on https://github.com/wldhx/yadisk-direct """
try:
link = re_findall(r'\b(https?://(yadi.sk|disk.yandex.com)\S+)', url)[0][0]
except IndexError:
return "No Yandex.Disk links found\n"
api = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key={}'
try:
return rget(api.format(link)).json()['href']
except KeyError:
raise DirectDownloadLinkException("ERROR: File not found/Download limit reached")
def uptobox(url: str, UPTOBOX_TOKEN: str) -> str:
""" Uptobox direct link generator
based on https://github.com/jovanzers/WinTenCermin and https://github.com/sinoobie/noobie-mirror """
try:
link = re_findall(r'\bhttps?://.*uptobox\.com\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("No Uptobox links found")
if UPTOBOX_TOKEN is None:
log.error('Unable to bypass UPTOBOX Link because absence of cookie(s)')
dl_url = 'UPTOBOX TOKEN not provided!'
else:
try:
link = re_findall(r'\bhttp?://.*uptobox\.com/dl\S+', url)[0]
dl_url = link
except:
file_id = re_findall(r'\bhttps?://.*uptobox\.com/(\w+)', url)[0]
file_link = f'https://uptobox.com/api/link?token={UPTOBOX_TOKEN}&file_code={file_id}'
req = rget(file_link)
result = req.json()
if result['message'].lower() == 'success':
dl_url = result['data']['dlLink']
elif result['message'].lower() == 'waiting needed':
waiting_time = result["data"]["waiting"] + 1
waiting_token = result["data"]["waitingToken"]
sleep(waiting_time)
req2 = rget(f"{file_link}&waitingToken={waiting_token}")
result2 = req2.json()
dl_url = result2['data']['dlLink']
elif result['message'].lower() == 'you need to wait before requesting a new download link':
cooldown = divmod(result['data']['waiting'], 60)
raise DirectDownloadLinkException(f"ERROR: Uptobox is being limited please wait {cooldown[0]} min {cooldown[1]} sec.")
else:
log.error(f"UPTOBOX_ERROR: {result}")
raise DirectDownloadLinkException(f"ERROR: {result['message']}")
return dl_url
def mediafire(url: str) -> str:
""" MediaFire direct link generator """
try:
link = re_findall(r'\bhttps?://.*mediafire\.com\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("No MediaFire links found")
page = BeautifulSoup(rget(link).content, 'lxml')
info = page.find('a', {'aria-label': 'Download file'})
return info.get('href')
def osdn(url: str) -> str:
""" OSDN direct link generator """
osdn_link = 'https://osdn.net'
try:
link = re_findall(r'\bhttps?://.*osdn\.net\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("No OSDN links found")
page = BeautifulSoup(
rget(link, allow_redirects=True).content, 'lxml')
info = page.find('a', {'class': 'mirror_link'})
link = unquote(osdn_link + info['href'])
mirrors = page.find('form', {'id': 'mirror-select-form'}).findAll('tr')
urls = []
for data in mirrors[1:]:
mirror = data.find('input')['value']
urls.append(re_sub(r'm=(.*)&f', f'm={mirror}&f', link))
return urls[0]
def github(url: str) -> str:
""" GitHub direct links generator """
try:
re_findall(r'\bhttps?://.*github\.com.*releases\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("No GitHub Releases links found")
download = rget(url, stream=True, allow_redirects=False)
try:
return download.headers["location"]
except KeyError:
raise DirectDownloadLinkException("ERROR: Can't extract the link")
def hxfile(url: str) -> str:
""" Hxfile direct link generator
Based on https://github.com/zevtyardt/lk21
"""
return Bypass().bypass_filesIm(url)
def anonfiles(url: str) -> str:
""" Anonfiles direct link generator
Based on https://github.com/zevtyardt/lk21
"""
return Bypass().bypass_anonfiles(url)
def letsupload(url: str) -> str:
""" Letsupload direct link generator
Based on https://github.com/zevtyardt/lk21
"""
try:
link = re_findall(r'\bhttps?://.*letsupload\.io\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("No Letsupload links found\n")
return Bypass().bypass_url(link)
def fembed(link: str) -> str:
""" Fembed direct link generator
Based on https://github.com/zevtyardt/lk21
"""
dl_url= Bypass().bypass_fembed(link)
count = len(dl_url)
lst_link = [dl_url[i] for i in dl_url]
return lst_link[count-1]
def sbembed(link: str) -> str:
""" Sbembed direct link generator
Based on https://github.com/zevtyardt/lk21
"""
dl_url= Bypass().bypass_sbembed(link)
count = len(dl_url)
lst_link = [dl_url[i] for i in dl_url]
return lst_link[count-1]
def onedrive(link: str) -> str:
""" Onedrive direct link generator
Based on https://github.com/UsergeTeam/Userge """
link_without_query = urlparse(link)._replace(query=None).geturl()
direct_link_encoded = str(standard_b64encode(bytes(link_without_query, "utf-8")), "utf-8")
direct_link1 = f"https://api.onedrive.com/v1.0/shares/u!{direct_link_encoded}/root/content"
resp = rhead(direct_link1)
if resp.status_code != 302:
raise DirectDownloadLinkException("ERROR: Unauthorized link, the link may be private")
return resp.next.url
def pixeldrain(url: str) -> str:
""" Based on https://github.com/yash-dk/TorToolkit-Telegram """
url = url.strip("/ ")
file_id = url.split("/")[-1]
if url.split("/")[-2] == "l":
info_link = f"https://pixeldrain.com/api/list/{file_id}"
dl_link = f"https://pixeldrain.com/api/list/{file_id}/zip"
else:
info_link = f"https://pixeldrain.com/api/file/{file_id}/info"
dl_link = f"https://pixeldrain.com/api/file/{file_id}"
resp = rget(info_link).json()
if resp["success"]:
return dl_link
else:
raise DirectDownloadLinkException(f"ERROR: Cant't download due {resp['message']}.")
def antfiles(url: str) -> str:
""" Antfiles direct link generator
Based on https://github.com/zevtyardt/lk21
"""
return Bypass().bypass_antfiles(url)
def streamtape(url: str) -> str:
""" Streamtape direct link generator
Based on https://github.com/zevtyardt/lk21
"""
return Bypass().bypass_streamtape(url)
def racaty(url: str) -> str:
""" Racaty direct link generator
based on https://github.com/SlamDevs/slam-mirrorbot"""
dl_url = ''
try:
re_findall(r'\bhttps?://.*racaty\.net\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("No Racaty links found")
scraper = create_scraper()
r = scraper.get(url)
soup = BeautifulSoup(r.text, "lxml")
op = soup.find("input", {"name": "op"})["value"]
ids = soup.find("input", {"name": "id"})["value"]
rapost = scraper.post(url, data = {"op": op, "id": ids})
rsoup = BeautifulSoup(rapost.text, "lxml")
dl_url = rsoup.find("a", {"id": "uniqueExpirylink"})["href"].replace(" ", "%20")
return dl_url
def fichier(link: str) -> str:
""" 1Fichier direct link generator
Based on https://github.com/Maujar
"""
regex = r"^([http:\/\/|https:\/\/]+)?.*1fichier\.com\/\?.+"
gan = re_match(regex, link)
if not gan:
raise DirectDownloadLinkException("ERROR: The link you entered is wrong!")
if "::" in link:
pswd = link.split("::")[-1]
url = link.split("::")[-2]
else:
pswd = None
url = link
try:
if pswd is None:
req = rpost(url)
else:
pw = {"pass": pswd}
req = rpost(url, data=pw)
except:
raise DirectDownloadLinkException("ERROR: Unable to reach 1fichier server!")
if req.status_code == 404:
raise DirectDownloadLinkException("ERROR: File not found/The link you entered is wrong!")
soup = BeautifulSoup(req.content, 'lxml')
if soup.find("a", {"class": "ok btn-general btn-orange"}) is not None:
dl_url = soup.find("a", {"class": "ok btn-general btn-orange"})["href"]
if dl_url is None:
raise DirectDownloadLinkException("ERROR: Unable to generate Direct Link 1fichier!")
else:
return dl_url
elif len(soup.find_all("div", {"class": "ct_warn"})) == 3:
str_2 = soup.find_all("div", {"class": "ct_warn"})[-1]
if "you must wait" in str(str_2).lower():
numbers = [int(word) for word in str(str_2).split() if word.isdigit()]
if not numbers:
raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.")
else:
raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.")
elif "protect access" in str(str_2).lower():
raise DirectDownloadLinkException(f"ERROR: This link requires a password!\n\n<b>This link requires a password!</b>\n- Insert sign <b>::</b> after the link and write the password after the sign.\n\n<b>Example:</b> https://1fichier.com/?smmtd8twfpm66awbqz04::love you\n\n* No spaces between the signs <b>::</b>\n* For the password, you can use a space!")
else:
print(str_2)
raise DirectDownloadLinkException("ERROR: Failed to generate Direct Link from 1fichier!")
elif len(soup.find_all("div", {"class": "ct_warn"})) == 4:
str_1 = soup.find_all("div", {"class": "ct_warn"})[-2]
str_3 = soup.find_all("div", {"class": "ct_warn"})[-1]
if "you must wait" in str(str_1).lower():
numbers = [int(word) for word in str(str_1).split() if word.isdigit()]
if not numbers:
raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.")
else:
raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.")
elif "bad password" in str(str_3).lower():
raise DirectDownloadLinkException("ERROR: The password you entered is wrong!")
else:
raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!")
else:
raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!")
def solidfiles(url: str) -> str:
""" Solidfiles direct link generator
Based on https://github.com/Xonshiz/SolidFiles-Downloader
By https://github.com/Jusidama18 """
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36'
}
pageSource = rget(url, headers = headers).text
mainOptions = str(re_search(r'viewerOptions\'\,\ (.*?)\)\;', pageSource).group(1))
return jsonloads(mainOptions)["downloadUrl"]
def krakenfiles(page_link: str) -> str:
""" krakenfiles direct link generator
Based on https://github.com/tha23rd/py-kraken
By https://github.com/junedkh """
page_resp = rsession().get(page_link)
soup = BeautifulSoup(page_resp.text, "lxml")
try:
token = soup.find("input", id="dl-token")["value"]
except:
raise DirectDownloadLinkException(f"Page link is wrong: {page_link}")
hashes = [
item["data-file-hash"]
for item in soup.find_all("div", attrs={"data-file-hash": True})
]
if not hashes:
raise DirectDownloadLinkException(f"ERROR: Hash not found for : {page_link}")
dl_hash = hashes[0]
payload = f'------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="token"\r\n\r\n{token}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--'
headers = {
"content-type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
"cache-control": "no-cache",
"hash": dl_hash,
}
dl_link_resp = rsession().post(
f"https://krakenfiles.com/download/{hash}", data=payload, headers=headers)
dl_link_json = dl_link_resp.json()
if "url" in dl_link_json:
return dl_link_json["url"]
else:
raise DirectDownloadLinkException(f"ERROR: Failed to acquire download URL from kraken for : {page_link}")
def uploadee(url: str) -> str:
""" uploadee direct link generator
By https://github.com/iron-heart-x"""
try:
soup = BeautifulSoup(rget(url).content, 'lxml')
sa = soup.find('a', attrs={'id':'d_l'})
return sa['href']
except:
raise DirectDownloadLinkException(f"ERROR: Failed to acquire download URL from upload.ee for : {url}")
def mdisk(url):
api = "https://api.emilyx.in/api"
client = cloudscraper.create_scraper(allow_brotli=False)
resp = client.get(url)
if resp.status_code == 404:
return "File not found/The link you entered is wrong!"
try:
resp = client.post(api, json={"type": "mdisk", "url": url})
res = resp.json()
except BaseException:
return "API UnResponsive / Invalid Link !"
if res["success"] is True:
return res["url"]
else:
return res["msg"]
def wetransfer(url):
api = "https://api.emilyx.in/api"
client = cloudscraper.create_scraper(allow_brotli=False)
resp = client.get(url)
if resp.status_code == 404:
return "File not found/The link you entered is wrong!"
try:
resp = client.post(api, json={"type": "wetransfer", "url": url})
res = resp.json()
except BaseException:
return "API UnResponsive / Invalid Link !"
if res["success"] is True:
return res["url"]
else:
return res["msg"]
def gofile_dl(url,password=""):
api_uri = 'https://api.gofile.io'
client = requests.Session()
res = client.get(api_uri+'/createAccount').json()
data = {
'contentId': url.split('/')[-1],
'token': res['data']['token'],
'websiteToken': '12345',
'cache': 'true',
'password': hashlib.sha256(password.encode('utf-8')).hexdigest()
}
res = client.get(api_uri+'/getContent', params=data).json()
content = []
for item in res['data']['contents'].values():
content.append(item)
return {
'accountToken': data['token'],
'files': content
}["files"][0]["link"]
def dropbox(url):
return url.replace("www.","").replace("dropbox.com","dl.dropboxusercontent.com").replace("?dl=0","")
def zippyshare(url):
resp = requests.get(url).text
surl = resp.split("document.getElementById('dlbutton').href = ")[1].split(";")[0]
parts = surl.split("(")[1].split(")")[0].split(" ")
val = str(int(parts[0]) % int(parts[2]) + int(parts[4]) % int(parts[6]))
surl = surl.split('"')
burl = url.split("zippyshare.com")[0]
furl = burl + "zippyshare.com" + surl[1] + val + surl[-2]
print(furl)
def megaup(url):
api = "https://api.emilyx.in/api"
client = cloudscraper.create_scraper(allow_brotli=False)
resp = client.get(url)
if resp.status_code == 404:
return "File not found/The link you entered is wrong!"
try:
resp = client.post(api, json={"type": "megaup", "url": url})
res = resp.json()
except BaseException:
return "API UnResponsive / Invalid Link !"
if res["success"] is True:
return res["url"]
else:
return res["msg"]
supported_sites_list = "disk.yandex.com\nmediafire.com\nuptobox.com\nosdn.net\ngithub.com\nhxfile.co\nanonfiles.com\nletsupload.io\n1drv.ms(onedrive)\n\
pixeldrain.com\nantfiles.com\nstreamtape.com\nbayfiles.com\nracaty.net\n1fichier.com\nsolidfiles.com\nkrakenfiles.com\n\
upload.ee\nmdisk.me\nwetransfer.com\ngofile.io\ndropbox.com\nzippyshare.com\nmegaup.net\n\
fembed.net, fembed.com, femax20.com, fcdn.stream, feurl.com, layarkacaxxi.icu, naniplay.nanime.in, naniplay.nanime.biz, naniplay.com, mm9842.com\n\
sbembed.com, watchsb.com, streamsb.net, sbplay.org"
fmed_list = ['fembed.net', 'fembed.com', 'femax20.com', 'fcdn.stream', 'feurl.com', 'layarkacaxxi.icu',
'naniplay.nanime.in', 'naniplay.nanime.biz', 'naniplay.com', 'mm9842.com']
def direct_link_generator(link: str):
""" direct links generator """
if 'yadi.sk' in link or 'disk.yandex.com' in link:
return yandex_disk(link)
elif 'mediafire.com' in link:
return mediafire(link)
elif 'uptobox.com' in link:
return uptobox(link,"UPTOBOX_TOKEN")
elif 'osdn.net' in link:
return osdn(link)
elif 'github.com' in link:
return github(link)
elif 'hxfile.co' in link:
return hxfile(link)
elif 'anonfiles.com' in link:
return anonfiles(link)
elif 'letsupload.io' in link:
return letsupload(link)
elif '1drv.ms' in link:
return onedrive(link)
elif 'pixeldrain.com' in link:
return pixeldrain(link)
elif 'antfiles.com' in link:
return antfiles(link)
elif 'streamtape.com' in link:
return streamtape(link)
elif 'bayfiles.com' in link:
return anonfiles(link)
elif 'racaty.net' in link:
return racaty(link)
elif '1fichier.com' in link:
return fichier(link)
elif 'solidfiles.com' in link:
return solidfiles(link)
elif 'krakenfiles.com' in link:
return krakenfiles(link)
elif 'upload.ee' in link:
return uploadee(link)
elif 'mdisk.me' in link:
return mdisk(link)
elif 'wetransfer.com' in link:
return wetransfer(link)
elif 'gofile.io' in link:
return gofile_dl(link,"GO_FILE_PASS")
elif 'dropbox.com' in link:
return dropbox(link)
elif 'zippyshare.com' in link:
return zippyshare(link)
elif 'megaup.net' in link:
return megaup(link)
elif any(x in link for x in fmed_list):
return fembed(link)
elif any(x in link for x in ['sbembed.com', 'watchsb.com', 'streamsb.net', 'sbplay.org']):
return sbembed(link)
else:
return f'No Direct link function found for {link}'