Skip to content

Commit 54617fd

Browse files
committed
fix upload path view in usetting and limit ffmpeg threads by taskset pkg
Signed-off-by: anasty17 <e.anastayyar@gmail.com>
1 parent 319350e commit 54617fd

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

bot/helper/ext_utils/media_utils.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from .files_utils import get_mime_type, is_archive, is_archive_split
1717
from .status_utils import time_to_seconds
1818

19+
threads = max(1, cpu_no // 2)
20+
cores = ",".join(str(i) for i in range(threads))
21+
1922

2023
async def create_thumb(msg, _id=""):
2124
if not _id:
@@ -125,6 +128,9 @@ async def take_ss(video_file, ss_nb) -> bool:
125128
for i in range(ss_nb):
126129
output = f"{dirpath}/SS.{name}_{i:02}.png"
127130
cmd = [
131+
"taskset",
132+
"-c",
133+
f"{cores}",
128134
"ffmpeg",
129135
"-hide_banner",
130136
"-loglevel",
@@ -138,7 +144,7 @@ async def take_ss(video_file, ss_nb) -> bool:
138144
"-frames:v",
139145
"1",
140146
"-threads",
141-
f"{max(1, cpu_no // 2)}",
147+
f"{threads}",
142148
output,
143149
]
144150
cap_time += interval
@@ -168,6 +174,9 @@ async def get_audio_thumbnail(audio_file):
168174
await makedirs(output_dir, exist_ok=True)
169175
output = ospath.join(output_dir, f"{time()}.jpg")
170176
cmd = [
177+
"taskset",
178+
"-c",
179+
f"{cores}",
171180
"ffmpeg",
172181
"-hide_banner",
173182
"-loglevel",
@@ -178,7 +187,7 @@ async def get_audio_thumbnail(audio_file):
178187
"-vcodec",
179188
"copy",
180189
"-threads",
181-
f"{max(1, cpu_no // 2)}",
190+
f"{threads}",
182191
output,
183192
]
184193
try:
@@ -206,6 +215,9 @@ async def get_video_thumbnail(video_file, duration):
206215
duration = 3
207216
duration = duration // 2
208217
cmd = [
218+
"taskset",
219+
"-c",
220+
f"{cores}",
209221
"ffmpeg",
210222
"-hide_banner",
211223
"-loglevel",
@@ -221,7 +233,7 @@ async def get_video_thumbnail(video_file, duration):
221233
"-frames:v",
222234
"1",
223235
"-threads",
224-
f"{max(1, cpu_no // 2)}",
236+
f"{threads}",
225237
output,
226238
]
227239
try:
@@ -249,6 +261,9 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
249261
await makedirs(output_dir, exist_ok=True)
250262
output = ospath.join(output_dir, f"{time()}.jpg")
251263
cmd = [
264+
"taskset",
265+
"-c",
266+
f"{cores}",
252267
"ffmpeg",
253268
"-hide_banner",
254269
"-loglevel",
@@ -266,7 +281,7 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
266281
"-f",
267282
"mjpeg",
268283
"-threads",
269-
f"{max(1, cpu_no // 2)}",
284+
f"{threads}",
270285
output,
271286
]
272287
try:
@@ -445,7 +460,7 @@ async def convert_video(self, video_file, ext, retry=False):
445460
"-c:a",
446461
"aac",
447462
"-threads",
448-
f"{max(1, cpu_no // 2)}",
463+
f"{threads}",
449464
output,
450465
]
451466
if ext == "mp4":
@@ -469,7 +484,7 @@ async def convert_video(self, video_file, ext, retry=False):
469484
"-c",
470485
"copy",
471486
"-threads",
472-
f"{max(1, cpu_no // 2)}",
487+
f"{threads}",
473488
output,
474489
]
475490
if self._listener.is_cancelled:
@@ -516,7 +531,7 @@ async def convert_audio(self, audio_file, ext):
516531
"-i",
517532
audio_file,
518533
"-threads",
519-
f"{max(1, cpu_no // 2)}",
534+
f"{threads}",
520535
output,
521536
]
522537
if self._listener.is_cancelled:
@@ -596,7 +611,7 @@ async def sample_video(self, video_file, sample_duration, part_duration):
596611
"-c:a",
597612
"aac",
598613
"-threads",
599-
f"{max(1, cpu_no // 2)}",
614+
f"{threads}",
600615
output_file,
601616
]
602617

@@ -661,7 +676,7 @@ async def split(self, f_path, file_, parts, split_size):
661676
"-c",
662677
"copy",
663678
"-threads",
664-
f"{max(1, cpu_no // 2)}",
679+
f"{threads}",
665680
out_path,
666681
]
667682
if not multi_streams:

bot/modules/users_settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def get_user_settings(from_user, stype="main"):
245245
upload_paths = user_dict.get("UPLOAD_PATHS", {})
246246
if not upload_paths and "UPLOAD_PATHS" not in user_dict and Config.UPLOAD_PATHS:
247247
upload_paths = Config.UPLOAD_PATHS
248-
else:
248+
if not upload_paths:
249249
upload_paths = "None"
250250

251251
buttons.data_button("Upload Paths", f"userset {user_id} menu UPLOAD_PATHS")
@@ -279,7 +279,9 @@ async def get_user_settings(from_user, stype="main"):
279279
ex_ex = "None"
280280

281281
ns_msg = "Added" if user_dict.get("NAME_SUBSTITUTE", False) else "None"
282-
buttons.data_button("Name Substitute", f"userset {user_id} menu NAME_SUBSTITUTE")
282+
buttons.data_button(
283+
"Name Substitute", f"userset {user_id} menu NAME_SUBSTITUTE"
284+
)
283285

284286
buttons.data_button("YT-DLP Options", f"userset {user_id} menu YT_DLP_OPTIONS")
285287
if user_dict.get("YT_DLP_OPTIONS", False):

0 commit comments

Comments
 (0)