Skip to content

Commit

Permalink
Improvments
Browse files Browse the repository at this point in the history
- improve sabnzbd progress not full progress but better than before regarding verify and unpack
- ability to more than one -ff arg to use more than one key

Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Jan 3, 2025
1 parent aec25f0 commit a86669b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 44 deletions.
24 changes: 19 additions & 5 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,21 @@ async def before_start(self):

if self.ffmpeg_cmds and not isinstance(self.ffmpeg_cmds, list):
if self.user_dict.get("ffmpeg_cmds", None):
self.ffmpeg_cmds = self.user_dict["ffmpeg_cmds"].get(
self.ffmpeg_cmds, None
)
ffmpeg_dict = self.user_dict["ffmpeg_cmds"]
self.ffmpeg_cmds = [
value
for key in list(self.ffmpeg_cmds)
if key in ffmpeg_dict
for value in ffmpeg_dict[key]
]
elif "ffmpeg_cmds" not in self.user_dict and Config.FFMPEG_CMDS:
self.ffmpeg_cmds = Config.FFMPEG_CMDS.get(self.ffmpeg_cmds, None)
ffmpeg_dict = Config.FFMPEG_CMDS
self.ffmpeg_cmds = [
value
for key in list(self.ffmpeg_cmds)
if key in ffmpeg_dict
for value in ffmpeg_dict[key]
]
else:
self.ffmpeg_cmds = None

Expand Down Expand Up @@ -669,7 +679,11 @@ async def proceed_extract(self, dl_path, gid):
if code != 0:
try:
async with self.subprocess_lock:
stderr = (await self.subproc.stderr.read()).decode().strip()
stderr = (
(await self.subproc.stderr.read())
.decode()
.strip()
)
except:
stderr = "Unable to decode the error!"
LOGGER.error(
Expand Down
6 changes: 5 additions & 1 deletion bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ def arg_parser(items, arg_base):
break
sub_list.append(items[j])
if sub_list:
arg_base[part] = " ".join(sub_list)
value = " ".join(sub_list)
if part == "-ff" and not value.strip().startswith("["):
arg_base[part].add(value)
else:
arg_base[part] = value
i += len(sub_list)

i += 1
Expand Down
17 changes: 0 additions & 17 deletions bot/helper/listeners/nzb_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ async def _on_download_error(err, nzo_id, button=None):
)


@new_task
async def _change_status(nzo_id, status):
if task := await get_task_by_gid(nzo_id):
async with task_dict_lock:
task.cstatus = status


@new_task
async def _stop_duplicate(nzo_id):
if task := await get_task_by_gid(nzo_id):
Expand Down Expand Up @@ -82,16 +75,6 @@ async def _nzb_listener():
nzb_jobs[nzo_id]["status"] = "Completed"
elif job["status"] == "Failed":
await _on_download_error(job["fail_message"], nzo_id)
elif job["status"] in [
"QuickCheck",
"Verifying",
"Repairing",
"Fetching",
"Moving",
"Extracting",
]:
if job["status"] != nzb_jobs[nzo_id]["status"]:
await _change_status(nzo_id, job["status"])
for dl in downloads:
nzo_id = dl["nzo_id"]
if nzo_id not in nzb_jobs:
Expand Down
49 changes: 40 additions & 9 deletions bot/helper/mirror_leech_utils/status_utils/nzb_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,48 @@

async def get_download(nzo_id, old_info=None):
try:
res = await sabnzbd_client.get_downloads(nzo_ids=nzo_id)
if res["queue"]["slots"]:
slot = res["queue"]["slots"][0]
queue = await sabnzbd_client.get_downloads(nzo_ids=nzo_id)
if res := queue["queue"]["slots"]:
slot = res[0]
if msg := slot["labels"]:
LOGGER.warning(" | ".join(msg))
return slot
else:
history = await sabnzbd_client.get_history(nzo_ids=nzo_id)
if res := history["history"]["slots"]:
slot = res[0]
if slot["status"] == "Verifying":
percentage = slot["action_line"].split("Verifying: ")[-1].split("/")
percentage = round(
(int(percentage[0]) / int(percentage[1])) * 100, 2
)
old_info["percentage"] = percentage
elif slot["status"] == "Repairing":
action = slot["action_line"].split("Repairing: ")[-1].split()
percentage = action[0].strip("%")
eta = action[2]
old_info["percentage"] = percentage
old_info["timeleft"] = eta
elif slot["status"] == "Extracting":
action = slot["action_line"].split("Unpacking: ")[-1].split()
percentage = action[0].split("/")
percentage = round(
(int(percentage[0]) / int(percentage[1])) * 100, 2
)
eta = action[2]
old_info["percentage"] = percentage
old_info["timeleft"] = eta
old_info["status"] = slot["status"]
return old_info
except Exception as e:
LOGGER.error(f"{e}: Sabnzbd, while getting job info. ID: {nzo_id}")
return old_info


class SabnzbdStatus:
def __init__(self, listener, gid, queued=False, status=None):
def __init__(self, listener, gid, queued=False):
self.queued = queued
self.listener = listener
self.cstatus = status
self._gid = gid
self._info = None

Expand Down Expand Up @@ -70,10 +95,15 @@ def status(self):
state = self._info["status"]
if state == "Paused" and self.queued:
return MirrorStatus.STATUS_QUEUEDL
elif self.cstatus:
return self.cstatus
elif state == "Paused":
return MirrorStatus.STATUS_PAUSED
elif state in [
"QuickCheck",
"Verifying",
"Repairing",
"Fetching",
"Moving",
"Extracting",
]:
return state
else:
return MirrorStatus.STATUS_DOWNLOAD

Expand All @@ -91,6 +121,7 @@ async def cancel_task(self):
self.listener.on_download_error("Stopped by user!"),
sabnzbd_client.delete_job(self._gid, delete_files=True),
sabnzbd_client.delete_category(f"{self.listener.mid}"),
sabnzbd_client.delete_history(self._gid, delete_files=True),
)
async with nzb_listener_lock:
if self._gid in nzb_jobs:
Expand Down
23 changes: 16 additions & 7 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def new_event(self):
"-cv": "",
"-ns": "",
"-tl": "",
"-ff": None,
"-ff": set(),
}

arg_parser(input_list[1:], args)
Expand Down Expand Up @@ -153,10 +153,11 @@ async def new_event(self):
self.multi = 0

try:
if args["-ff"].strip().startswith("["):
self.ffmpeg_cmds = eval(args["-ff"])
else:
self.ffmpeg_cmds = args["-ff"]
if args["-ff"]:
if isinstance(args["-ff"], set):
self.ffmpeg_cmds = args["-ff"]
else:
self.ffmpeg_cmds = eval(args["-ff"])
except Exception as e:
self.ffmpeg_cmds = None
LOGGER.error(e)
Expand Down Expand Up @@ -188,12 +189,20 @@ async def new_event(self):
if fd_name != self.folder_name:
self.same_dir[fd_name]["total"] -= 1
elif self.same_dir:
self.same_dir[self.folder_name] = {"total": self.multi, "tasks": {self.mid}}
self.same_dir[self.folder_name] = {
"total": self.multi,
"tasks": {self.mid},
}
for fd_name in self.same_dir:
if fd_name != self.folder_name:
self.same_dir[fd_name]["total"] -= 1
else:
self.same_dir = {self.folder_name: {"total": self.multi, "tasks": {self.mid}}}
self.same_dir = {
self.folder_name: {
"total": self.multi,
"tasks": {self.mid},
}
}
elif self.same_dir:
async with task_dict_lock:
for fd_name in self.same_dir:
Expand Down
11 changes: 6 additions & 5 deletions bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async def new_event(self):
"-cv": "",
"-ns": "",
"-tl": "",
"-ff": None,
"-ff": set(),
}

arg_parser(input_list[1:], args)
Expand All @@ -321,10 +321,11 @@ async def new_event(self):
self.multi = 0

try:
if args["-ff"].strip().startswith("["):
self.ffmpeg_cmds = eval(args["-ff"])
else:
self.ffmpeg_cmds = args["-ff"]
if args["-ff"]:
if isinstance(args["-ff"], set):
self.ffmpeg_cmds = args["-ff"]
else:
self.ffmpeg_cmds = eval(args["-ff"])
except Exception as e:
self.ffmpeg_cmds = None
LOGGER.error(e)
Expand Down

0 comments on commit a86669b

Please sign in to comment.