Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Fix some issues in jdownloader and yt-dlp ranges path.
- Add rclone select.
  • Loading branch information
Dawn-India committed Oct 3, 2024
1 parent 307ba9c commit baed38d
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 160 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ programming in Python.

## Rclone

- Rclone transfer (download/upload/clone-server-side) without or with random service accounts (global and user option)
- Ability to choose config, remote and path from list with buttons (global, user and task option)
- Ability to set rclone flags for each task or globally from config (global, user and task option)
- Transfer (download/upload/clone-server-side) without or with random service accounts (global and user option)
- Ability to choose config, remote and path from list with or without buttons (global, user and task option)
- Ability to set flags for each task or globally from config (global, user and task option)
- Abitity to select specific files or folders to download/copy using buttons (task option)
- Rclone.conf (global and user option)
- Rclone serve for combine remote to use it as index from all remotes (global option)
- Upload destination (global, user and task option)
Expand Down Expand Up @@ -378,13 +379,13 @@ programming in Python.
1. Seed will get disbaled while using this option
2. Before any character you must add `\BACKSLASH`, those are the characters: `\^$.|?*+()[]{}-`
* Example: script/code/s | mirror/leech | tea/ /s | clone | cpu/ | \[ZEE\]/ZEE | \\text\\/text/s
- script will get replaced by code with sensitive case
- mirror will get replaced by leech
- tea will get replaced by space with sensitive case
- clone will get removed
- cpu will get replaced by space
- [ZEE] will get replaced by ZEE
- \text\ will get replaced by text with sensitive case
- script will get replaced by code with sensitive case
- mirror will get replaced by leech
- tea will get replaced by space with sensitive case
- clone will get removed
- cpu will get replaced by space
- [ZEE] will get replaced by ZEE
- \text\ will get replaced by text with sensitive case
- `METADATA_TXT`: Edit metadata of the video. `Str`
- `META_ATTACHMENT`: Add attachment to the metadata. `Str`
- `THUMBNAIL_LAYOUT`: Thumbnail layout (widthxheight, 2x2, 3x3, 2x4, 4x4, ...) of how many photo arranged for the thumbnail.`Str`
Expand Down
2 changes: 1 addition & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def log(_, message):
/{BotCommands.RmSudoCommand}: Remove sudo users (Only Owner).
<b>Maintainance:</b>
/{BotCommands.RestartCommand}: Restart and update the bot (Only Owner & Sudo).
/{BotCommands.RestartCommand[0]}: Restart and update the bot (Only Owner & Sudo).
/{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports (Only Owner & Sudo).
/{BotCommands.ShellCommand}: Run shell commands (Only Owner).
/{BotCommands.AExecCommand}: Exec async functions (Only Owner).
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async def create_thumb(msg, _id=""):
_id = msg.id
path = f"{DOWNLOAD_DIR}Thumbnails"
else:
path = 'Thumbnails'
path = "Thumbnails"
await makedirs(
path,
exist_ok=True
Expand All @@ -184,6 +184,7 @@ async def create_thumb(msg, _id=""):
await remove(photo_dir)
return output


global_streams = {}
async def is_multi_streams(path):
try:
Expand Down
29 changes: 14 additions & 15 deletions bot/helper/listeners/jdownloader_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,21 @@ async def _jd_listener():
k,
v
) in list(jd_downloads.items()):
if (
v["status"] == "down" and
k not in all_packages
):
cdi = jd_downloads[k]["ids"]
if len(cdi) > 1:
await update_download(k, v)
if v["status"] == "down":
if k in all_packages:
for (
index,
pid
) in enumerate(v["ids"]):
if pid not in all_packages:
del jd_downloads[k]["ids"][index]

else:
await remove_download(k)
else:
for (
index,
pid
) in enumerate(v["ids"]):
if pid not in all_packages:
del jd_downloads[k]["ids"][index]
cdi = jd_downloads[k]["ids"]
if len(cdi) > 1:
await update_download(k, v)
else:
await remove_download(k)

for gid in finished:
if (
Expand Down
52 changes: 39 additions & 13 deletions bot/helper/task_utils/download_utils/jd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ async def add_jd_download(listener, path):
jdownloader.device.linkgrabber.remove_links,
package_ids=packages_to_remove,
)
async with jd_lock:
del jd_downloads[gid]
del jd_downloads[gid]
return

jd_downloads[gid]["ids"] = online_packages
Expand Down Expand Up @@ -385,18 +384,43 @@ async def add_jd_download(listener, path):
)
return

if (
listener.select and
await JDownloaderHelper(listener).wait_for_configurations()
):
await retry_function(
jdownloader.device.linkgrabber.remove_links,
package_ids=online_packages,
)
listener.remove_from_same_dir()
return
if listener.select:
if await JDownloaderHelper(listener).wait_for_configurations():
await retry_function(
jdownloader.device.linkgrabber.remove_links,
package_ids=online_packages,
)
listener.remove_from_same_dir()
return
else:
queued_downloads = await retry_function(
jdownloader.device.linkgrabber.query_packages,
[{"saveTo": True}]
)
updated_packages = [
qd["uuid"]
for qd
in queued_downloads
if qd["saveTo"].startswith(path)
]
async with jd_lock:
online_packages = [
pack
for pack
in online_packages
if pack
in updated_packages
]
if gid not in online_packages:
del jd_downloads[gid]
gid = online_packages[0]
jd_downloads[gid] = {"status": "collect"}
jd_downloads[gid]["ids"] = online_packages

add_to_queue, event = await check_running_tasks(listener)
(
add_to_queue,
event
) = await check_running_tasks(listener)
if add_to_queue:
LOGGER.info(f"Added to Queue/Download: {listener.name}")
async with task_dict_lock:
Expand All @@ -406,9 +430,11 @@ async def add_jd_download(listener, path):
"dl"
)
await listener.on_download_start()

if listener.multi <= 1:
await send_status_message(listener.message)
await event.wait() # type: ignore

if listener.is_cancelled:
return
async with queue_dict_lock:
Expand Down
150 changes: 95 additions & 55 deletions bot/helper/task_utils/download_utils/rclone_download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from asyncio import gather
from json import loads
from secrets import token_urlsafe
from aiofiles.os import remove

from bot import (
task_dict,
Expand Down Expand Up @@ -42,6 +43,13 @@ async def add_rclone_download(listener, path):
listener.link
) = listener.link.split(":", 1)
listener.link = listener.link.strip("/")
rclone_select = False

if listener.link.startswith("rclone_select"):
rclone_select = True
rpath = ""
else:
rpath = listener.link

cmd1 = [
"rclone",
Expand All @@ -52,7 +60,7 @@ async def add_rclone_download(listener, path):
"--no-modtime",
"--config",
config_path,
f"{remote}:{listener.link}",
f"{remote}:{rpath}",
]
cmd2 = [
"rclone",
Expand All @@ -61,68 +69,98 @@ async def add_rclone_download(listener, path):
"--json",
"--config",
config_path,
f"{remote}:{listener.link}",
f"{remote}:{rpath}",
]
res1, res2 = await gather(
cmd_exec(cmd1),
cmd_exec(cmd2)
)
if res1[2] != res2[2] != 0:
if res1[2] != -9:
err = (
res1[1]
or res2[1]
or "Use <code>/shell cat rlog.txt</code> to see more information"
)
msg = f"Error: While getting rclone stat/size. Path: {remote}:{listener.link}. Stderr: {err[:4000]}"
await listener.on_download_error(msg)
return
try:
rstat = loads(res1[0])
rsize = loads(res2[0])
except Exception as err:
if not str(err):
err = "Use <code>/shell cat rlog.txt</code> to see more information"
await listener.on_download_error(f"RcloneDownload JsonLoad: {err}")
return
if rstat["IsDir"]:
if rclone_select:
cmd2.extend(("--files-from", listener.link))
res = await cmd_exec(cmd2)
if res[2] != 0:
if res[2] != -9:
err = (res[1]or "Use <code>/shell cat rlog.txt</code> to see more information")
msg = f"Error: While getting rclone stat/size. Path: {remote}:{listener.link}. Stderr: {err[:4000]}"
await listener.on_download_error(msg)
return
try:
rsize = loads(res[0])
except Exception as err:
if not str(err):
err = "Use <code>/shell cat rlog.txt</code> to see more information"
await listener.on_download_error(f"RcloneDownload JsonLoad: {err}")
return
if not listener.name:
listener.name = (
listener.link.rsplit("/", 1)[-1]
if listener.link
else remote
)
listener.name = listener.link
path += listener.name
else:
listener.name = listener.link.rsplit(
"/",
1
)[-1]
(
res1,
res2
) = await gather(
cmd_exec(cmd1),
cmd_exec(cmd2)
)
if res1[2] != res2[2] != 0:
if res1[2] != -9:
err = (
res1[1]
or res2[1]
or "Use <code>/shell cat rlog.txt</code> to see more information"
)
msg = f"Error: While getting rclone stat/size. Path: {remote}:{listener.link}. Stderr: {err[:4000]}"
await listener.on_download_error(msg)
return
try:
rstat = loads(res1[0])
rsize = loads(res2[0])
except Exception as err:
if not str(err):
err = "Use <code>/shell cat rlog.txt</code> to see more information"
await listener.on_download_error(f"RcloneDownload JsonLoad: {err}")
return
if rstat["IsDir"]:
if not listener.name:
listener.name = (
listener.link.rsplit(
"/",
1
)[-1]
if listener.link
else remote
)
path += listener.name
else:
listener.name = listener.link.rsplit(
"/",
1
)[-1]
listener.size = rsize["bytes"]
gid = token_urlsafe(12)

(
msg,
button
) = await stop_duplicate_check(listener)
if msg:
await listener.on_download_error(
if not rclone_select:
(
msg,
button
)
return
if limit_exceeded := await limit_checker(listener, is_rclone=True):
LOGGER.info(f"Rclone Limit Exceeded: {listener.name} | {get_readable_file_size(listener.size)}")
rmsg = await send_message(
listener.message,
limit_exceeded
)
await delete_links(listener.message)
await auto_delete_message(
listener.message,
rmsg
)
return
) = await stop_duplicate_check(listener)
if msg:
await listener.on_download_error(
msg,
button
)
return
if limit_exceeded := await limit_checker(
listener,
is_rclone=True
):
LOGGER.info(f"Rclone Limit Exceeded: {listener.name} | {get_readable_file_size(listener.size)}")
rmsg = await send_message(
listener.message,
limit_exceeded
)
await delete_links(listener.message)
await auto_delete_message(
listener.message,
rmsg
)
return

(
add_to_queue,
Expand Down Expand Up @@ -162,8 +200,10 @@ async def add_rclone_download(listener, path):
await send_status_message(listener.message)
LOGGER.info(f"Download with rclone: {listener.link}")

await RCTransfer.download(
await RCTransfer.download( # type: ignore
remote,
config_path,
path
)
if rclone_select:
await remove(listener.link)
5 changes: 5 additions & 0 deletions bot/helper/task_utils/download_utils/yt_dlp_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ async def add_download(self, path, qual, playlist, options):
"default": f"{path}/{self._listener.name}/%(title,fulltitle,alt_title)s%(season_number& |)s%(season_number&S|)s%(season_number|)02d%(episode_number&E|)s%(episode_number|)02d%(height& |)s%(height|)s%(height&p|)s%(fps|)s%(fps&fps|)s%(tbr& |)s%(tbr|)d.%(ext)s",
"thumbnail": f"{path}/yt-dlp-thumb/%(title,fulltitle,alt_title)s%(season_number& |)s%(season_number&S|)s%(season_number|)02d%(episode_number&E|)s%(episode_number|)02d%(height& |)s%(height|)s%(height&p|)s%(fps|)s%(fps&fps|)s%(tbr& |)s%(tbr|)d.%(ext)s",
}
elif "download_ranges" in options:
self.opts["outtmpl"] = {
"default": f"{path}/{base_name}/%(section_number|)s%(section_number&.|)s%(section_title|)s%(section_title&-|)s%(title,fulltitle,alt_title)s %(section_start)s to %(section_end)s.%(ext)s",
"thumbnail": f"{path}/yt-dlp-thumb/%(section_number|)s%(section_number&.|)s%(section_title|)s%(section_title&-|)s%(title,fulltitle,alt_title)s %(section_start)s to %(section_end)s.%(ext)s",
}
elif any(
key in options
for key in [
Expand Down
1 change: 1 addition & 0 deletions bot/helper/task_utils/gdrive_utils/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async def id_updates(_, query, obj):
obj.event.set()
elif data[1] == "ps":
if obj.page_step == int(data[2]):
obj.query_proc = False
return
obj.page_step = int(data[2])
await obj.get_items_buttons()
Expand Down
Loading

0 comments on commit baed38d

Please sign in to comment.