Skip to content

Commit d32f0d6

Browse files
authored
Merge pull request #1871 from pikaproject/master
fix mediafire single and folder link
2 parents de77223 + 04b09f7 commit d32f0d6

1 file changed

Lines changed: 52 additions & 34 deletions

File tree

bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def direct_link_generator(link):
183183
"lbx.to",
184184
"teltobx.net",
185185
"telbx.net",
186+
"linkbox.cloud",
186187
]
187188
):
188189
return linkBox(link)
@@ -451,14 +452,27 @@ def mediafire(url, session=None):
451452
r"https?:\/\/download\d+\.mediafire\.com\/\S+\/\S+\/\S+", url
452453
):
453454
return final_link[0]
454-
455-
def _repair_download(url, session):
456-
try:
457-
html = HTML(session.get(url).text)
458-
if new_link := html.xpath('//a[@id="continue-btn"]/@href'):
459-
return mediafire(f"https://mediafire.com/{new_link[0]}")
460-
except Exception as e:
461-
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") from e
455+
456+
def _decode_url(html, session):
457+
enc_url = html.xpath('//a[@id="downloadButton"]')
458+
if enc_url:
459+
final_link = enc_url[0].attrib.get('href')
460+
scrambled = enc_url[0].attrib.get('data-scrambled-url')
461+
462+
if final_link and scrambled:
463+
try:
464+
final_link = b64decode(scrambled).decode("utf-8")
465+
return final_link
466+
except Exception as e:
467+
raise ValueError(f"Failed to decode final link. {e.__class__.__name__}") from e
468+
elif final_link.startswith("http"):
469+
return final_link
470+
elif final_link.startswith("//"):
471+
return mediafire(f"https:{final_link}", session=session)
472+
else:
473+
raise ValueError(f"No download link found")
474+
else:
475+
raise ValueError("Download button not found in the HTML content. It may have been blocked by Cloudflare's anti-bot protection.")
462476

463477
if session is None:
464478
session = create_scraper()
@@ -486,19 +500,12 @@ def _repair_download(url, session):
486500
if html.xpath("//div[@class='passwordPrompt']"):
487501
session.close()
488502
raise DirectDownloadLinkException("ERROR: Wrong password.")
489-
if not (final_link := html.xpath('//a[@aria-label="Download file"]/@href')):
490-
if repair_link := html.xpath("//a[@class='retry']/@href"):
491-
return _repair_download(repair_link[0], session)
492-
raise DirectDownloadLinkException(
493-
"ERROR: No links found in this page Try Again"
494-
)
495-
if final_link[0].startswith("//"):
496-
final_url = f"https://{final_link[0][2:]}"
497-
if _password:
498-
final_url += f"::{_password}"
499-
return mediafire(final_url, session)
503+
try:
504+
final_link = _decode_url(html, session)
505+
except Exception as e:
506+
raise DirectDownloadLinkException(f"ERROR: {str(e)}")
500507
session.close()
501-
return final_link[0]
508+
return final_link
502509

503510

504511
def osdn(url):
@@ -1236,14 +1243,6 @@ def __scraper(url):
12361243
parsed_url = urlparse(url)
12371244
url = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}"
12381245

1239-
def __repair_download(url):
1240-
try:
1241-
html = HTML(session.get(url).text)
1242-
if new_link := html.xpath('//a[@id="continue-btn"]/@href'):
1243-
return __scraper(f"https://mediafire.com/{new_link[0]}")
1244-
except:
1245-
return None
1246-
12471246
try:
12481247
html = HTML(session.get(url).text)
12491248
except:
@@ -1259,12 +1258,31 @@ def __repair_download(url):
12591258
return None
12601259
if html.xpath("//div[@class='passwordPrompt']"):
12611260
return None
1262-
if final_link := html.xpath('//a[@aria-label="Download file"]/@href'):
1263-
if final_link[0].startswith("//"):
1264-
return __scraper(f"https://{final_link[0][2:]}")
1265-
return final_link[0]
1266-
if repair_link := html.xpath("//a[@class='retry']/@href"):
1267-
return __repair_download(repair_link[0])
1261+
try:
1262+
final_link = __decode_url(html)
1263+
except:
1264+
return None
1265+
return final_link
1266+
1267+
def __decode_url(html):
1268+
enc_url = html.xpath('//a[@id="downloadButton"]')
1269+
if enc_url:
1270+
final_link = enc_url[0].attrib.get('href')
1271+
scrambled = enc_url[0].attrib.get('data-scrambled-url')
1272+
if final_link and scrambled:
1273+
try:
1274+
final_link = b64decode(scrambled).decode("utf-8")
1275+
return final_link
1276+
except:
1277+
return None
1278+
elif final_link.startswith("http"):
1279+
return final_link
1280+
elif final_link.startswith("//"):
1281+
return __scraper(f"https:{final_link}")
1282+
else:
1283+
return None
1284+
else:
1285+
return None
12681286

12691287
def __get_content(folderKey, folderPath="", content_type="folders"):
12701288
try:

0 commit comments

Comments
 (0)