Improvments

- 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 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2025-01-03 03:17:09 +02:00
parent aec25f0858
commit a86669be78
No known key found for this signature in database
GPG Key ID: EAAC8A2DF2861DE4
6 changed files with 86 additions and 44 deletions

View File

@ -210,11 +210,21 @@ class TaskConfig:
if self.ffmpeg_cmds and not isinstance(self.ffmpeg_cmds, list): if self.ffmpeg_cmds and not isinstance(self.ffmpeg_cmds, list):
if self.user_dict.get("ffmpeg_cmds", None): if self.user_dict.get("ffmpeg_cmds", None):
self.ffmpeg_cmds = self.user_dict["ffmpeg_cmds"].get( ffmpeg_dict = self.user_dict["ffmpeg_cmds"]
self.ffmpeg_cmds, None 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: 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: else:
self.ffmpeg_cmds = None self.ffmpeg_cmds = None
@ -669,7 +679,11 @@ class TaskConfig:
if code != 0: if code != 0:
try: try:
async with self.subprocess_lock: async with self.subprocess_lock:
stderr = (await self.subproc.stderr.read()).decode().strip() stderr = (
(await self.subproc.stderr.read())
.decode()
.strip()
)
except: except:
stderr = "Unable to decode the error!" stderr = "Unable to decode the error!"
LOGGER.error( LOGGER.error(

View File

@ -143,7 +143,11 @@ def arg_parser(items, arg_base):
break break
sub_list.append(items[j]) sub_list.append(items[j])
if sub_list: 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 += len(sub_list)
i += 1 i += 1

View File

@ -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 @new_task
async def _stop_duplicate(nzo_id): async def _stop_duplicate(nzo_id):
if task := await get_task_by_gid(nzo_id): if task := await get_task_by_gid(nzo_id):
@ -82,16 +75,6 @@ async def _nzb_listener():
nzb_jobs[nzo_id]["status"] = "Completed" nzb_jobs[nzo_id]["status"] = "Completed"
elif job["status"] == "Failed": elif job["status"] == "Failed":
await _on_download_error(job["fail_message"], nzo_id) 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: for dl in downloads:
nzo_id = dl["nzo_id"] nzo_id = dl["nzo_id"]
if nzo_id not in nzb_jobs: if nzo_id not in nzb_jobs:

View File

@ -12,12 +12,38 @@ from ...ext_utils.status_utils import (
async def get_download(nzo_id, old_info=None): async def get_download(nzo_id, old_info=None):
try: try:
res = await sabnzbd_client.get_downloads(nzo_ids=nzo_id) queue = await sabnzbd_client.get_downloads(nzo_ids=nzo_id)
if res["queue"]["slots"]: if res := queue["queue"]["slots"]:
slot = res["queue"]["slots"][0] slot = res[0]
if msg := slot["labels"]: if msg := slot["labels"]:
LOGGER.warning(" | ".join(msg)) LOGGER.warning(" | ".join(msg))
return slot 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 return old_info
except Exception as e: except Exception as e:
LOGGER.error(f"{e}: Sabnzbd, while getting job info. ID: {nzo_id}") LOGGER.error(f"{e}: Sabnzbd, while getting job info. ID: {nzo_id}")
@ -25,10 +51,9 @@ async def get_download(nzo_id, old_info=None):
class SabnzbdStatus: class SabnzbdStatus:
def __init__(self, listener, gid, queued=False, status=None): def __init__(self, listener, gid, queued=False):
self.queued = queued self.queued = queued
self.listener = listener self.listener = listener
self.cstatus = status
self._gid = gid self._gid = gid
self._info = None self._info = None
@ -70,10 +95,15 @@ class SabnzbdStatus:
state = self._info["status"] state = self._info["status"]
if state == "Paused" and self.queued: if state == "Paused" and self.queued:
return MirrorStatus.STATUS_QUEUEDL return MirrorStatus.STATUS_QUEUEDL
elif self.cstatus: elif state in [
return self.cstatus "QuickCheck",
elif state == "Paused": "Verifying",
return MirrorStatus.STATUS_PAUSED "Repairing",
"Fetching",
"Moving",
"Extracting",
]:
return state
else: else:
return MirrorStatus.STATUS_DOWNLOAD return MirrorStatus.STATUS_DOWNLOAD
@ -91,6 +121,7 @@ class SabnzbdStatus:
self.listener.on_download_error("Stopped by user!"), self.listener.on_download_error("Stopped by user!"),
sabnzbd_client.delete_job(self._gid, delete_files=True), sabnzbd_client.delete_job(self._gid, delete_files=True),
sabnzbd_client.delete_category(f"{self.listener.mid}"), sabnzbd_client.delete_category(f"{self.listener.mid}"),
sabnzbd_client.delete_history(self._gid, delete_files=True),
) )
async with nzb_listener_lock: async with nzb_listener_lock:
if self._gid in nzb_jobs: if self._gid in nzb_jobs:

View File

@ -106,7 +106,7 @@ class Mirror(TaskListener):
"-cv": "", "-cv": "",
"-ns": "", "-ns": "",
"-tl": "", "-tl": "",
"-ff": None, "-ff": set(),
} }
arg_parser(input_list[1:], args) arg_parser(input_list[1:], args)
@ -153,10 +153,11 @@ class Mirror(TaskListener):
self.multi = 0 self.multi = 0
try: try:
if args["-ff"].strip().startswith("["): if args["-ff"]:
self.ffmpeg_cmds = eval(args["-ff"]) if isinstance(args["-ff"], set):
else: self.ffmpeg_cmds = args["-ff"]
self.ffmpeg_cmds = args["-ff"] else:
self.ffmpeg_cmds = eval(args["-ff"])
except Exception as e: except Exception as e:
self.ffmpeg_cmds = None self.ffmpeg_cmds = None
LOGGER.error(e) LOGGER.error(e)
@ -188,12 +189,20 @@ class Mirror(TaskListener):
if fd_name != self.folder_name: if fd_name != self.folder_name:
self.same_dir[fd_name]["total"] -= 1 self.same_dir[fd_name]["total"] -= 1
elif self.same_dir: 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: for fd_name in self.same_dir:
if fd_name != self.folder_name: if fd_name != self.folder_name:
self.same_dir[fd_name]["total"] -= 1 self.same_dir[fd_name]["total"] -= 1
else: 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: elif self.same_dir:
async with task_dict_lock: async with task_dict_lock:
for fd_name in self.same_dir: for fd_name in self.same_dir:

View File

@ -310,7 +310,7 @@ class YtDlp(TaskListener):
"-cv": "", "-cv": "",
"-ns": "", "-ns": "",
"-tl": "", "-tl": "",
"-ff": None, "-ff": set(),
} }
arg_parser(input_list[1:], args) arg_parser(input_list[1:], args)
@ -321,10 +321,11 @@ class YtDlp(TaskListener):
self.multi = 0 self.multi = 0
try: try:
if args["-ff"].strip().startswith("["): if args["-ff"]:
self.ffmpeg_cmds = eval(args["-ff"]) if isinstance(args["-ff"], set):
else: self.ffmpeg_cmds = args["-ff"]
self.ffmpeg_cmds = args["-ff"] else:
self.ffmpeg_cmds = eval(args["-ff"])
except Exception as e: except Exception as e:
self.ffmpeg_cmds = None self.ffmpeg_cmds = None
LOGGER.error(e) LOGGER.error(e)