Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Fix terabox ddl

- No need to upload terabox cookies

Signed-off-by: Dawn India <[email protected]>
  • Loading branch information
Dawn-India committed Aug 16, 2024
1 parent d0f1b2e commit 2039c74
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 143 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ list_drives.txt
cookies.txt
downloads
bot.session*
terabox.txt
rclone.conf
accounts.zip
shorteners.txt
buttons.txt
buttons.txt
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ programming in Python.
> shrdsk.me (
> sharedisk.io), akmfiles.com, wetransfer.com, pcloud.link, gofile.io (file/folders), easyupload.io, mdisk.me (with
> ytdl),
> tmpsend.com, qiwi.gg, berkasdrive.com, mp4upload.com, terabox.com (file/folders) (you need to add cookies txt with
> name) [terabox.txt](https://github.com/ytdl-org/youtube-dl#how-do-i-pass-cookies-to-youtube-dl).
> tmpsend.com, qiwi.gg, berkasdrive.com, mp4upload.com, terabox.com (file/folders).
</details>

------
Expand Down
60 changes: 30 additions & 30 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ async def beforeStart(self):
or not member.privileges.can_post_messages
):
raise ValueError(
"I don't have enough privileges in the 'leech destination'!\n"
"Allow me 'post messages' and 'manage chat' permissions!"
"I don't have enough permissions in the <b>leech destination</b>!\n"
"Allow me <b>post messages</b> and <b>manage chat</b> permissions!"
)
else:
try:
Expand All @@ -612,36 +612,36 @@ async def beforeStart(self):
raise ValueError("Start me in DM and try again!")

if config_dict["LOG_CHAT_ID"]:
try:
log_chat = await self.client.get_chat(config_dict["LOG_CHAT_ID"]) # type: ignore
except:
raise ValueError("First add me in LOG_CHAT_ID!")
if log_chat.type.name != "CHANNEL":
raise ValueError(
"LOG_CHAT_ID must be a channel!"
)
member = await log_chat.get_member(uploader_id)
if not member.privileges.can_post_messages:
raise ValueError(
"I don't have enough permission in LOG_CHAT_ID!"
"Allow me 'post messages' permissions!"
)
try:
log_chat = await self.client.get_chat(config_dict["LOG_CHAT_ID"]) # type: ignore
except:
raise ValueError("First add me in LOG_CHAT_ID!")
if log_chat.type.name != "CHANNEL":
raise ValueError(
"LOG_CHAT_ID must be a channel!"
)
member = await log_chat.get_member(uploader_id)
if not member.privileges.can_post_messages:
raise ValueError(
"I don't have enough permission in LOG_CHAT_ID!"
"Allow me 'post messages' permissions!"
)

if config_dict["DUMP_CHAT_ID"]:
try:
dump_chat = await self.client.get_chat(config_dict["DUMP_CHAT_ID"]) # type: ignore
except:
raise ValueError("First add me in DUMP_CHAT_ID!")
if dump_chat.type.name != "CHANNEL":
raise ValueError(
"DUMP_CHAT_ID must be a channel!"
)
member = await dump_chat.get_member(uploader_id)
if not member.privileges.can_post_messages:
raise ValueError(
"I don't have enough permission in DUMP_CHAT_ID!"
"Allow me 'post messages' permissions!"
)
try:
dump_chat = await self.client.get_chat(config_dict["DUMP_CHAT_ID"]) # type: ignore
except:
raise ValueError("First add me in DUMP_CHAT_ID!")
if dump_chat.type.name != "CHANNEL":
raise ValueError(
"DUMP_CHAT_ID must be a channel!"
)
member = await dump_chat.get_member(uploader_id)
if not member.privileges.can_post_messages:
raise ValueError(
"I don't have enough permission in DUMP_CHAT_ID!"
"Allow me 'post messages' permissions!"
)

if self.splitSize:
if self.splitSize.isdigit(): # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async def _onDownloadStarted(api, gid):
start_time = time()
total_speed = 0
count = 0
while time() - start_time < 600:
while time() - start_time < 1800:
await sync_to_async(download.update)
dl_speed = download.download_speed
total_speed += dl_speed
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def _avg_speed_check(tor):
start_time = time()
total_speed = 0
count = 0
while time() - start_time < 600:
while time() - start_time < 1800:
live_dl = await sync_to_async(
qbittorrent_client.torrents_info,
torrent_hashes=tor.hash
Expand Down
179 changes: 73 additions & 106 deletions bot/helper/task_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,117 +640,84 @@ def uploadee(url):


def terabox(url):
if not ospath.isfile("terabox.txt"):
raise DirectDownloadLinkException("ERROR: terabox.txt not found")
try:
jar = MozillaCookieJar("terabox.txt")
jar.load()
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")
cookies = {}
for cookie in jar:
cookies[cookie.name] = cookie.value
details = {
"contents": [],
"title": "",
"total_size": 0
"""Terabox direct link generator
Based on https://github.com/r0ld3x/terabox-downloader-bot
By: https://github.com/Dawn-India"""

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

if not (
search(
pattern1,
url
) or search(
pattern2,
url
)
):
raise DirectDownloadLinkException("ERROR: Invalid terabox URL")

netloc = urlparse(url).netloc
url = url.replace(
netloc,
"1024terabox.com"
)

response = get(url)
if response.status_code != 200:
raise DirectDownloadLinkException("ERROR: Unable to fetch the page")

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"
}
details["header"] = " ".join(
f"{key}: {value}"
for key, value
in cookies.items()

response = post(
"https://ytshorts.savetube.me/api/v1/terabox-downloader",
headers=headers,
json={"url": url}
)
if response.status_code != 200:
raise DirectDownloadLinkException("ERROR: Unable to fetch the page")

response_data = response.json()
responses = response_data.get(
"response",
[]
)
if not responses:
raise DirectDownloadLinkException("ERROR: No response found")

resolutions = responses[0].get(
"resolutions",
{}
)
if not resolutions:
raise DirectDownloadLinkException("ERROR: No resolutions found")

def __fetch_links(session, dir_="", folderPath=""):
params = {
"app_id": "250528",
"jsToken": jsToken,
"shorturl": shortUrl
}
if dir_:
params["dir"] = dir_
else:
params["root"] = "1"
try:
_json = session.get(
"https://www.1024tera.com/share/list",
params=params,
cookies=cookies,
).json()
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")
if _json["errno"] not in [
0,
"0"
]:
if "errmsg" in _json:
raise DirectDownloadLinkException(f"ERROR: {_json['errmsg']}")
else:
raise DirectDownloadLinkException("ERROR: Something went wrong!")
download = resolutions.get(
"Fast Download",
""
)
video = resolutions.get(
"HD Video",
""
)

if "list" not in _json:
return
contents = _json["list"]
for content in contents:
if content["isdir"] in [
"1",
1
]:
if not folderPath:
if not details["title"]:
details["title"] = content["server_filename"]
newFolderPath = ospath.join(details["title"])
else:
newFolderPath = ospath.join(
details["title"],
content["server_filename"]
)
else:
newFolderPath = ospath.join(folderPath, content["server_filename"])
__fetch_links(
session,
content["path"],
newFolderPath
)
else:
if not folderPath:
if not details["title"]:
details["title"] = content["server_filename"]
folderPath = details["title"]
item = {
"url": content["dlink"],
"filename": content["server_filename"],
"path": ospath.join(folderPath),
}
if "size" in content:
size = content["size"]
if isinstance(size, str) and size.isdigit():
size = float(size)
details["total_size"] += size
details["contents"].append(item)
return (
download
if download
else video
)

with Session() as session:
try:
_res = session.get(
url,
cookies=cookies
)
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")
if jsToken := findall(r"window\.jsToken.*%22(.*)%22", _res.text):
jsToken = jsToken[0]
else:
raise DirectDownloadLinkException("ERROR: jsToken not found!.")
shortUrl = parse_qs(urlparse(_res.url).query).get("surl")
if not shortUrl:
raise DirectDownloadLinkException("ERROR: Could not find surl")
try:
__fetch_links(session)
except Exception as e:
raise DirectDownloadLinkException(e)
if len(details["contents"]) == 1:
return details["contents"][0]["url"]
return details


def filepress(url):
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def get_buttons(key=None, edit_type=None):
)
msg = """
Send private file: config.env, token.pickle, rclone.conf, accounts.zip,
list_drives.txt, cookies.txt, terabox.txt, .netrc or any other private file!
list_drives.txt, cookies.txt, .netrc or any other private file!
To delete private file send only the file name as text message.
Note: Changing .netrc will not take effect for aria2c until restart.
Expand Down

0 comments on commit 2039c74

Please sign in to comment.