Minor improvments and fix args

- Improve jdownloader progress ad fix minor issue in it
- Improve ffmpeg and 7z progress
- other minor fixes

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2025-01-02 12:55:51 +02:00
parent a8101c1386
commit cef1ec4918
No known key found for this signature in database
GPG Key ID: EAAC8A2DF2861DE4
7 changed files with 95 additions and 49 deletions

View File

@ -210,7 +210,9 @@ class TaskConfig:
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)
self.ffmpeg_cmds = self.user_dict["ffmpeg_cmds"].get(
self.ffmpeg_cmds, None
)
elif "ffmpeg_cmds" not in self.user_dict and Config.FFMPEG_CMDS:
self.ffmpeg_cmds = Config.FFMPEG_CMDS.get(self.ffmpeg_cmds, None)
else:
@ -573,7 +575,12 @@ class TaskConfig:
return ""
if code != 0:
try:
stderr = (await self.subproc.stderr.read()).decode().strip()
async with self.subprocess_lock:
stderr = (
(await self.subproc.stderr.read())
.decode()
.strip()
)
except:
stderr = "Unable to decode the error!"
LOGGER.error(
@ -595,7 +602,8 @@ class TaskConfig:
return ""
if code != 0:
try:
stderr = (await self.subproc.stderr.read()).decode().strip()
async with self.subprocess_lock:
stderr = (await self.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Unable to extract zst file!. Path: {dl_path}")
@ -660,17 +668,14 @@ class TaskConfig:
return ""
if code != 0:
try:
stderr = (await self.subproc.stderr.read()).decode().strip()
async with self.subprocess_lock:
stderr = (await self.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Unable to extract archive splits!. Path: {f_path}"
)
if (
not self.seed
and self.subproc is not None
and code == 0
):
if not self.seed and self.subproc is not None and code == 0:
for file_ in files:
if is_archive_split(file_) or is_archive(file_):
del_path = ospath.join(dirpath, file_)
@ -723,7 +728,8 @@ class TaskConfig:
return up_path
else:
try:
stderr = (await self.subproc.stderr.read()).decode().strip()
async with self.subprocess_lock:
stderr = (await self.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
@ -814,7 +820,8 @@ class TaskConfig:
if not delete:
self.new_dir = ""
try:
stderr = (await self.subproc.stderr.read()).decode().strip()
async with self.subprocess_lock:
stderr = (await self.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Unable to zip this path: {dl_path}")

View File

@ -113,20 +113,6 @@ def arg_parser(items, arg_base):
"-med",
}
def process_argument_with_values(start_index):
values = []
for j in range(start_index + 1, total):
if items[j] in arg_base:
check = " ".join(values).strip()
if check.startswith("[") and check.endswith("]"):
break
elif check.startswith("["):
pass
else:
break
values.append(items[j])
return values
while i < total:
part = items[i]
@ -142,7 +128,20 @@ def arg_parser(items, arg_base):
):
arg_base[part] = True
else:
sub_list = process_argument_with_values(i)
sub_list = []
for j in range(i + 1, total):
if items[j] in arg_base:
if part in bool_arg_set and not sub_list:
arg_base[part] = True
break
if not sub_list:
break
check = " ".join(sub_list).strip()
if check.startswith("[") and check.endswith("]"):
break
elif not check.startswith("["):
break
sub_list.append(items[j])
if sub_list:
arg_base[part] = " ".join(sub_list)
i += len(sub_list)

View File

@ -80,7 +80,8 @@ async def convert_video(listener, video_file, ext, retry=False):
return await convert_video(listener, video_file, ext, True)
else:
try:
stderr = (await listener.subproc.stderr.read()).decode().strip()
async with listener.subprocess_lock:
stderr = (await listener.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
@ -120,7 +121,8 @@ async def convert_audio(listener, audio_file, ext):
return False
else:
try:
stderr = (await listener.subproc.stderr.read()).decode().strip()
async with listener.subprocess_lock:
stderr = (await listener.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
@ -493,7 +495,8 @@ async def split_file(
return False
elif code != 0:
try:
stderr = (await listener.subproc.stderr.read()).decode().strip()
async with listener.subprocess_lock:
stderr = (await listener.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
try:
@ -578,7 +581,8 @@ async def split_file(
return False
elif code != 0:
try:
stderr = (await listener.subproc.stderr.read()).decode().strip()
async with listener.subprocess_lock:
stderr = (await listener.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Split Document: {path}")
@ -652,7 +656,8 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
return output_file
else:
try:
stderr = (await listener.subproc.stderr.read()).decode().strip()
async with listener.subprocess_lock:
stderr = (await listener.subproc.stderr.read()).decode().strip()
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
@ -785,7 +790,8 @@ async def run_ffmpeg_cmd(listener, ffmpeg, path):
return False
else:
try:
stderr = (await listener.subproc.stderr.read()).decode().strip()
async with listener.subprocess_lock:
stderr = (await listener.subproc.stderr.read()).decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(

View File

@ -116,6 +116,7 @@ async def get_jd_download_directory():
async def add_jd_download(listener, path):
try:
async with jd_lock:
gid = token_urlsafe(12)
if not jdownloader.is_connected:
raise MYJDException(jdownloader.error)
@ -137,7 +138,6 @@ async def add_jd_download(listener, path):
package_ids=odl_list
)
gid = token_urlsafe(12)
jd_downloads[gid] = {"status": "collect", "path": path}
if await aiopath.exists(listener.link):
@ -349,7 +349,8 @@ async def add_jd_download(listener, path):
except (Exception, MYJDException) as e:
await listener.on_download_error(f"{e}".strip())
async with jd_lock:
del jd_downloads[gid]
if gid in jd_downloads:
del jd_downloads[gid]
finally:
if await aiopath.exists(listener.link):
await remove(listener.link)

View File

@ -21,7 +21,11 @@ class FFmpegStatus:
async def _ffmpeg_progress(self):
while True:
async with self.listener.subprocess_lock:
if self.listener.subproc is None or self.listener.is_cancelled:
if (
self.listener.subproc is None
or self.listener.subproc.returncode is not None
or self.listener.is_cancelled
):
break
line = await self.listener.subproc.stdout.readline()
if not line:
@ -37,6 +41,10 @@ class FFmpegStatus:
)
elif key == "bitrate":
self._speed_raw = (float(value.strip("kbits/s")) / 8) * 1000
self._processed_bytes = 0
self._speed_raw = 0
self._progress_raw = 0
self._active = False
def speed(self):
@ -46,7 +54,11 @@ class FFmpegStatus:
return get_readable_file_size(self._processed_bytes)
async def progress(self):
if not self._active and self.listener.subsize and self.listener.subproc is not None:
if (
not self._active
and self.listener.subsize
and self.listener.subproc is not None
):
await self._ffmpeg_progress()
self._active = True
return f"{round(self._progress_raw, 2)}%"

View File

@ -1,3 +1,5 @@
from time import time
from .... import LOGGER, jd_lock, jd_downloads
from ...ext_utils.bot_utils import async_to_sync
from ...ext_utils.jdownloader_booter import jdownloader
@ -8,7 +10,7 @@ from ...ext_utils.status_utils import (
)
def _get_combined_info(result):
def _get_combined_info(result, old_info):
name = result[0].get("name")
hosts = result[0].get("hosts")
bytesLoaded = 0
@ -16,15 +18,18 @@ def _get_combined_info(result):
speed = 0
status = ""
for res in result:
st = res.get("status", "").lower()
if st and st != "finished":
status = st
bytesLoaded += res.get("bytesLoaded", 0)
bytesTotal += res.get("bytesTotal", 0)
speed += res.get("speed", 0)
if len(status) == 0:
status = "UnknownError Check WebUI"
if res.get("enabled"):
st = res.get("status", "")
if st and st.lower() != "finished":
status = st
bytesLoaded += res.get("bytesLoaded", 0)
bytesTotal += res.get("bytesTotal", 0)
speed += res.get("speed", 0)
try:
if not speed:
speed = (bytesLoaded - old_info.get("bytesLoaded", 0)) / (
time() - old_info.get("last_update", 0)
)
eta = (bytesTotal - bytesLoaded) / speed
except:
eta = 0
@ -36,6 +41,7 @@ def _get_combined_info(result):
"hosts": hosts,
"bytesLoaded": bytesLoaded,
"bytesTotal": bytesTotal,
"last_update": time(),
}
@ -48,6 +54,8 @@ async def get_download(gid, old_info):
"bytesTotal": True,
"enabled": True,
"packageUUIDs": jd_downloads[gid]["ids"],
"maxResults": -1,
"running": True,
"speed": True,
"eta": True,
"status": True,
@ -55,7 +63,7 @@ async def get_download(gid, old_info):
}
]
)
return _get_combined_info(result) if len(result) > 1 else result[0]
return _get_combined_info(result, old_info) if len(result) > 1 else result[0]
except:
return old_info
@ -94,7 +102,10 @@ class JDownloaderStatus:
async_to_sync(self._update)
state = self._info.get("status", "jdlimit").capitalize()
if len(state) == 0:
return "UnknownError Check WebUI"
if self._info.get("bytesLoaded", 0) == 0:
return MirrorStatus.STATUS_QUEUEDL
else:
return MirrorStatus.STATUS_DOWNLOAD
return MirrorStatus.STATUS_QUEUEDL if state == "Jdlimit" else state
def task(self):

View File

@ -25,7 +25,11 @@ class SevenZStatus:
pattern = r"\b(?:Add\s+new\s+data\s+to\s+archive:.*?,\s+(\d+)\s+bytes|Physical\s+Size\s*=\s*(\d+))"
while True:
async with self.listener.subprocess_lock:
if self.listener.subproc is None or self.listener.is_cancelled:
if (
self.listener.subproc is None
or self.listener.subproc.returncode is not None
or self.listener.is_cancelled
):
break
line = await self.listener.subproc.stdout.readline()
line = line.decode().strip()
@ -39,7 +43,11 @@ class SevenZStatus:
s = b""
while True:
async with self.listener.subprocess_lock:
if self.listener.is_cancelled or self.listener.subproc is None:
if (
self.listener.is_cancelled
or self.listener.subproc is None
or self.listener.subproc.returncode is not None
):
break
char = await self.listener.subproc.stdout.read(1)
if not char:
@ -56,6 +64,8 @@ class SevenZStatus:
self._progress_str = "0%"
s = b""
self._processed_bytes = 0
self._progress_str = "0%"
self._active = False
def gid(self):