Gujal00 / ResolveURL

Fork of UrlResolver for XBMC by @t0mm0, @eldorados, @bstrdsmkr, @tknorris and @jsergio123
GNU General Public License v2.0
118 stars 56 forks source link

terabox new resolver #872

Closed Ghb3245 closed 4 days ago

Ghb3245 commented 4 weeks ago

https://www.terabox.com/sharing/embed?surl=qivF2FrCZS6l-4E2LbLPSQ&resolution=1080

can you add it please

Gujal00 commented 4 weeks ago

basically they are wrapping on top of baidu's wangpan, due to which the main code is in chinese and unable to understand. may be someone who can read chinese or someone with node experience who can deobfuscate the js can help out

Ghb3245 commented 4 weeks ago

`def terabox(url, video_quality="HD Video", save_dir="HD_Video"): """Terabox direct link generator 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
terabox_url = url.replace(
    netloc,
    "1024tera.com"
)

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",
    "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"
}

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
}

for item in data["response"]:
    title = item["title"]
    resolutions = item.get(
        "resolutions",
        {}
    )
    zlink = resolutions.get(video_quality)
    if zlink:
        details["contents"].append({
            "url": zlink,
            "filename": title,
            "path": ospath.join(
                title,
                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 `
Ghb3245 commented 4 weeks ago

I found this can it help

Ghb3245 commented 4 weeks ago

I found this too

"""def terabox(url) -> str: sess = session() while True: try: res = sess.get(url) print("connected") break except: print("retrying") url = res.url

key = url.split('?surl=')[-1]
url = f'http://www.terabox.com/wap/share/filelist?surl={key}'
sess.cookies.update(TERA_COOKIE)

while True:
    try: 
        res = sess.get(url)
        print("connected")
        break
    except Exception as e: print("retrying")

key = res.url.split('?surl=')[-1]
soup = BeautifulSoup(res.content, 'lxml')
jsToken = None

for fs in soup.find_all('script'):
    fstring = fs.string
    if fstring and fstring.startswith('try {eval(decodeURIComponent'):
        jsToken = fstring.split('%22')[1]

while True:
    try:
        res = sess.get(f'https://www.terabox.com/share/list?app_id=250528&jsToken={jsToken}&shorturl={key}&root=1')
        print("connected")
        break
    except: print("retrying")
result = res.json()

if result['errno'] != 0: return f"ERROR: '{result['errmsg']}' Check cookies"
result = result['list']
if len(result) > 1: return "ERROR: Can't download mutiple files"
result = result[0]

if result['isdir'] != '0':return "ERROR: Can't download folder"
return result.get('dlink',"Error")"""
Gujal00 commented 4 weeks ago

no, first one is for a telegram bot to download from terabox. and the second one requires a users authenticated cookie extracted from browser terabox session. Both no good for ResolveURL