Skip to content

Commit 626e970

Browse files
committed
some fixes
Signed-off-by: anasty17 <e.anastayyar@gmail.com>
1 parent 8307f60 commit 626e970

4 files changed

Lines changed: 31 additions & 32 deletions

File tree

bot/core/startup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from aiofiles.os import path as aiopath, remove, makedirs
22
from aiofiles import open as aiopen
33
from aioshutil import rmtree
4-
from asyncio import create_subprocess_exec, create_subprocess_shell
4+
from asyncio import create_subprocess_exec, create_subprocess_shell, sleep
55
from importlib import import_module
66

77
from .. import (
@@ -26,6 +26,7 @@
2626

2727

2828
async def update_qb_options():
29+
LOGGER.info("Get qBittorrent options from server")
2930
if not qbit_options:
3031
opt = await TorrentManager.qbittorrent.app.preferences()
3132
qbit_options.update(opt)
@@ -42,6 +43,7 @@ async def update_qb_options():
4243

4344

4445
async def update_aria2_options():
46+
LOGGER.info("Get aria2 options from server")
4547
if not aria2_options:
4648
op = await TorrentManager.aria2.getGlobalOption()
4749
aria2_options.update(op)
@@ -50,8 +52,15 @@ async def update_aria2_options():
5052

5153

5254
async def update_nzb_options():
53-
no = (await sabnzbd_client.get_config())["config"]["misc"]
54-
nzb_options.update(no)
55+
LOGGER.info("Get SABnzbd options from server")
56+
while True:
57+
try:
58+
no = (await sabnzbd_client.get_config())["config"]["misc"]
59+
nzb_options.update(no)
60+
except:
61+
await sleep(0.5)
62+
continue
63+
break
5564

5665

5766
async def load_settings():

bot/helper/ext_utils/bot_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ def arg_parser(items, arg_base):
144144
else:
145145
sub_list = []
146146
for j in range(i + 1, total):
147-
if items[j] in arg_base:
147+
if (
148+
items[j] in arg_base
149+
and not arg_base[items[j]]
150+
and items[j] != part
151+
):
148152
if part in bool_arg_set and not sub_list:
149153
arg_base[part] = True
150154
break

bot/helper/ext_utils/media_utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ async def take_ss(video_file, ss_nb) -> bool:
138138
"1",
139139
"-frames:v",
140140
"1",
141-
"-threads",
142-
f"{max(1, cpu_no // 2)}",
143141
output,
144142
]
145143
cap_time += interval
@@ -178,8 +176,6 @@ async def get_audio_thumbnail(audio_file):
178176
"-an",
179177
"-vcodec",
180178
"copy",
181-
"-threads",
182-
f"{max(1, cpu_no // 2)}",
183179
output,
184180
]
185181
try:
@@ -221,8 +217,6 @@ async def get_video_thumbnail(video_file, duration):
221217
"1",
222218
"-frames:v",
223219
"1",
224-
"-threads",
225-
f"{max(1, cpu_no // 2)}",
226220
output,
227221
]
228222
try:
@@ -266,8 +260,6 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
266260
"1",
267261
"-f",
268262
"mjpeg",
269-
"-threads",
270-
f"{max(1, cpu_no // 2)}",
271263
output,
272264
]
273265
try:
@@ -446,8 +438,6 @@ async def convert_video(self, video_file, ext, retry=False):
446438
"libx264",
447439
"-c:a",
448440
"aac",
449-
"-threads",
450-
f"{max(1, cpu_no // 2)}",
451441
output,
452442
]
453443
if ext == "mp4":
@@ -470,8 +460,6 @@ async def convert_video(self, video_file, ext, retry=False):
470460
"0",
471461
"-c",
472462
"copy",
473-
"-threads",
474-
f"{max(1, cpu_no // 2)}",
475463
output,
476464
]
477465
if self._listener.is_cancelled:
@@ -517,8 +505,6 @@ async def convert_audio(self, audio_file, ext):
517505
"pipe:1",
518506
"-i",
519507
audio_file,
520-
"-threads",
521-
f"{max(1, cpu_no // 2)}",
522508
output,
523509
]
524510
if self._listener.is_cancelled:
@@ -597,8 +583,6 @@ async def sample_video(self, video_file, sample_duration, part_duration):
597583
"libx264",
598584
"-c:a",
599585
"aac",
600-
"-threads",
601-
f"{max(1, cpu_no // 2)}",
602586
output_file,
603587
]
604588

@@ -662,8 +646,6 @@ async def split(self, f_path, file_, parts, split_size):
662646
"-2",
663647
"-c",
664648
"copy",
665-
"-threads",
666-
f"{max(1, cpu_no // 2)}",
667649
out_path,
668650
]
669651
if not multi_streams:

bot/helper/mirror_leech_utils/status_utils/nzb_status.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
async def get_download(nzo_id, old_info=None):
13+
if old_info is None:
14+
old_info = {}
1315
try:
1416
queue = await sabnzbd_client.get_downloads(nzo_ids=nzo_id)
1517
if res := queue["queue"]["slots"]:
@@ -59,49 +61,51 @@ def __init__(self, listener, gid, queued=False):
5961
self.queued = queued
6062
self.listener = listener
6163
self._gid = gid
62-
self._info = None
64+
self._info = {}
6365
self.tool = "sabnzbd"
6466

6567
async def update(self):
6668
self._info = await get_download(self._gid, self._info)
6769

6870
def progress(self):
69-
return f"{self._info['percentage']}%"
71+
return f"{self._info.get('percentage', "0")}%"
7072

7173
def processed_raw(self):
72-
return (float(self._info["mb"]) - float(self._info["mbleft"])) * 1048576
74+
return (
75+
float(self._info.get("mb", "0")) - float(self._info.get("mbleft", "0"))
76+
) * 1048576
7377

7478
def processed_bytes(self):
7579
return get_readable_file_size(self.processed_raw())
7680

7781
def speed_raw(self):
78-
if self._info["mb"] == self._info["mbleft"]:
82+
if self._info.get("mb", "0") == self._info.get("mbleft", "0"):
7983
return 0
8084
try:
81-
return int(float(self._info["mbleft"]) * 1048576) / self.eta_raw()
85+
return int(float(self._info.get("mbleft", "0")) * 1048576) / self.eta_raw()
8286
except:
8387
return 0
8488

8589
def speed(self):
8690
return f"{get_readable_file_size(self.speed_raw())}/s"
8791

8892
def name(self):
89-
return self._info["filename"]
93+
return self._info.get("filename", "")
9094

9195
def size(self):
92-
return self._info["size"]
96+
return self._info.get("size", 0)
9397

9498
def eta_raw(self):
95-
return int(time_to_seconds(self._info["timeleft"]))
99+
return int(time_to_seconds(self._info.get("timeleft", "0")))
96100

97101
def eta(self):
98102
return get_readable_time(self.eta_raw())
99103

100104
async def status(self):
101105
await self.update()
102-
if self._info["mb"] == self._info["mbleft"]:
106+
if self._info.get("mb", "0") == self._info.get("mbleft", "0"):
103107
return MirrorStatus.STATUS_QUEUEDL
104-
state = self._info["status"]
108+
state = self._info.get("status")
105109
if state == "Paused" and self.queued:
106110
return MirrorStatus.STATUS_QUEUEDL
107111
elif state in [

0 commit comments

Comments
 (0)