Skip to content

Commit

Permalink
Merge pull request #1746 from Dawn-India/master
Browse files Browse the repository at this point in the history
Terabox fix
  • Loading branch information
anasty17 authored Aug 18, 2024
2 parents 2a17212 + ccc703d commit 14c8fa6
Showing 1 changed file with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from lxml.etree import HTML
from os import path as ospath
from re import findall, match, search
from requests import Session, post, get
from requests import Session, post, get, RequestException
from requests.adapters import HTTPAdapter
from time import sleep
from urllib.parse import parse_qs, urlparse
Expand Down Expand Up @@ -557,32 +557,25 @@ def uploadee(url):
raise DirectDownloadLinkException("ERROR: Direct Link not found")


def terabox(url):
def terabox(url, video_quality="HD Video", save_dir="HD_Video"):
"""Terabox direct link generator
By: https://github.com/Dawn-India/Z-Mirror"""

pattern1 = r"/s/(\w+)"
pattern2 = r"surl=(\w+)"

if not (
search(
pattern1,
url
) or search(
pattern2,
url
)
):
https://github.com/Dawn-India/Z-Mirror"""

pattern = r"/s/(\w+)|surl=(\w+)"
if not search(pattern, url):
raise DirectDownloadLinkException("ERROR: Invalid terabox URL")

netloc = urlparse(url).netloc
url = url.replace(
terabox_url = url.replace(
netloc,
"1024tera.com"
)
response = get(url)
if response.status_code != 200:
raise DirectDownloadLinkException("ERROR: Unable to fetch the webpage")

urls = [
"https://ytshorts.savetube.me/api/v1/terabox-downloader",
f"https://teraboxvideodownloader.nepcoderdevs.workers.dev/?url={terabox_url}",
f"https://terabox.udayscriptsx.workers.dev/?url={terabox_url}"
]

headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0",
Expand All @@ -596,37 +589,55 @@ def terabox(url):
"Sec-Fetch-Site": "same-origin"
}

response = post(
"https://ytshorts.savetube.me/api/v1/terabox-downloader",
headers=headers,
json={"url": url}
)
if response.status_code != 200:
for base_url in urls:
try:
if "api/v1" in base_url:
response = post(
base_url,
headers=headers,
json={"url": terabox_url}
)
else:
response = get(base_url)

if response.status_code == 200:
break
except RequestException as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") from e
else:
raise DirectDownloadLinkException("ERROR: Unable to fetch the JSON data")

data = response.json()
details = {"contents": [], "title": "", "total_size": 0}
details = {
"contents": [],
"title": "",
"total_size": 0
}

for item in data["response"]:
title = item["title"]
resolutions = item.get(
"resolutions",
{}
)
zlink = resolutions.get("HD Video")
zlink = resolutions.get(video_quality)
if zlink:
details["contents"].append({
"url": zlink,
"filename": title,
"path": ospath.join(
title,
"HD_Video"
save_dir
)
})
details["title"] = title

if not details["contents"]:
raise DirectDownloadLinkException("ERROR: No valid download links found")

if len(details["contents"]) == 1:
return details["contents"][0]["url"]

return details


Expand Down

0 comments on commit 14c8fa6

Please sign in to comment.