Skip to content

Commit

Permalink
sync mltb
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 2, 2025
1 parent 25b2169 commit 36fcc9d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 40 deletions.
38 changes: 25 additions & 13 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ async def decompress_zst(self, dl_path, is_dir=False):
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 Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
Expand All @@ -606,7 +606,11 @@ async def decompress_zst(self, dl_path, is_dir=False):
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 Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
Expand Down Expand Up @@ -676,11 +680,11 @@ async def proceed_extract(self, dl_path, gid):
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 Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
Expand Down Expand Up @@ -739,7 +743,11 @@ async def proceed_extract(self, dl_path, gid):
self.subproc = None
return up_path
try:
stderr = (await self.subproc.stderr.read()).decode().strip()
async with self.subprocess_lock:
stderr = (
(await self.subproc.stderr.read())
.decode()
.strip())
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
Expand Down Expand Up @@ -827,7 +835,11 @@ async def proceed_compress(self, dl_path, gid, o_files, ft_delete):
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 Exception:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Unable to zip this path: {dl_path}")
Expand Down
29 changes: 14 additions & 15 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,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
if check.startswith("["):
pass
else:
break
values.append(items[j])
return values

while i < total:
part = items[i]
if part in arg_base:
Expand All @@ -148,7 +134,20 @@ def process_argument_with_values(start_index):
]:
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)
Expand Down
18 changes: 12 additions & 6 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ async def convert_video(listener, video_file, ext, retry=False):
await remove(output)
return await convert_video(listener, video_file, ext, True)
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(
Expand Down Expand Up @@ -131,7 +132,8 @@ async def convert_audio(listener, audio_file, ext):
listener.is_cancelled = True
return False
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(
Expand Down Expand Up @@ -509,7 +511,8 @@ async def split_file(
return False
if 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 Exception:
stderr = "Unable to decode the error!"
with contextlib.suppress(Exception):
Expand Down Expand Up @@ -589,7 +592,8 @@ async def split_file(
return False
if 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 Exception:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Split Document: {path}")
Expand Down Expand Up @@ -666,7 +670,8 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
if code == 0:
return output_file
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(
Expand Down Expand Up @@ -715,7 +720,8 @@ async def run_ffmpeg_cmd(listener, cmd, path=None, is_ffmpeg=False):
return False

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!"

Expand Down
9 changes: 8 additions & 1 deletion bot/helper/mirror_leech_utils/status_utils/ffmpeg_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def __init__(self, listener, gid, status=""):
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:
Expand All @@ -42,6 +46,9 @@ async def _ffmpeg_progress(self):
) * 1000
except ValueError:
self._speed_raw = 0
self._processed_bytes = 0
self._speed_raw = 0
self._progress_raw = 0
self._active = False

def speed(self):
Expand Down
14 changes: 12 additions & 2 deletions bot/helper/mirror_leech_utils/status_utils/sevenz_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ async def _sevenz_progress(self):
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()
Expand All @@ -37,7 +41,11 @@ async def _sevenz_progress(self):
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:
Expand All @@ -54,6 +62,8 @@ async def _sevenz_progress(self):
self._progress_str = "0%"
s = b""

self._processed_bytes = 0
self._progress_str = "0%"
self._active = False

def gid(self):
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def new_event(self):
"-ns": "",
"-md": "",
"-tl": "",
"-ff": "None",
"-ff": None,
}

arg_parser(input_list[1:], args)
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_speedtest_results():
test.upload()
return test.results

result = get_speedtest_results
result = get_speedtest_results()

if not result:
await edit_message(speed, "Speedtest failed to complete.")
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async def new_event(self):
"-ns": "",
"-md": "",
"-tl": "",
"-ff": "None",
"-ff": None,
}

arg_parser(input_list[1:], args)
Expand Down

0 comments on commit 36fcc9d

Please sign in to comment.