Skip to content

Commit 9694eea

Browse files
committed
format: auto-format code by ruff.
Signed-off-by: 5hojib <yesiamshojib@gmail.com>
1 parent 442b3aa commit 9694eea

File tree

10 files changed

+96
-75
lines changed

10 files changed

+96
-75
lines changed

bot/helper/common.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ async def before_start(self):
230230
else ["aria2", "!qB"]
231231
)
232232
self.included_extensions = self.user_dict.get("INCLUDED_EXTENSIONS") or (
233-
included_extensions if "INCLUDED_EXTENSIONS" not in self.user_dict else []
233+
included_extensions
234+
if "INCLUDED_EXTENSIONS" not in self.user_dict
235+
else []
234236
)
235237
if not self.rc_flags:
236238
if self.user_dict.get("RCLONE_FLAGS"):
@@ -274,11 +276,14 @@ async def before_start(self):
274276
if self.up_dest in self.user_dict["UPLOAD_PATHS"]:
275277
self.up_dest = self.user_dict["UPLOAD_PATHS"][self.up_dest]
276278
elif (
277-
"UPLOAD_PATHS" not in self.user_dict
278-
or not self.user_dict["UPLOAD_PATHS"]
279-
) and Config.UPLOAD_PATHS:
280-
if self.up_dest in Config.UPLOAD_PATHS:
281-
self.up_dest = Config.UPLOAD_PATHS[self.up_dest]
279+
(
280+
"UPLOAD_PATHS" not in self.user_dict
281+
or not self.user_dict["UPLOAD_PATHS"]
282+
)
283+
and Config.UPLOAD_PATHS
284+
and self.up_dest in Config.UPLOAD_PATHS
285+
):
286+
self.up_dest = Config.UPLOAD_PATHS[self.up_dest]
282287

283288
if self.ffmpeg_cmds:
284289
if self.user_dict.get("FFMPEG_CMDS", None):

bot/helper/ext_utils/files_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ async def remove_excluded_files(fpath, ee):
243243
if f.strip().lower().endswith(tuple(ee)):
244244
await remove(ospath.join(root, f))
245245

246+
246247
async def remove_non_included_files(fpath, ie):
247248
for root, _, files in await sync_to_async(walk, fpath):
248249
if root.strip().endswith("/yt-dlp-thumb"):
@@ -252,6 +253,7 @@ async def remove_non_included_files(fpath, ie):
252253
continue
253254
await remove(ospath.join(root, f))
254255

256+
255257
async def join_files(opath):
256258
files = await listdir(opath)
257259
results = []

bot/helper/ext_utils/media_utils.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import contextlib
2-
from asyncio import create_subprocess_exec, gather, sleep, wait_for
2+
from asyncio import create_subprocess_exec, gather, wait_for
33
from asyncio.subprocess import PIPE
44
from os import path as ospath
55
from re import escape
@@ -11,7 +11,7 @@
1111
from aioshutil import rmtree
1212
from PIL import Image
1313

14-
from bot import DOWNLOAD_DIR, LOGGER, cpu_no, threads, cores
14+
from bot import DOWNLOAD_DIR, LOGGER, cores, threads
1515

1616
from .bot_utils import cmd_exec, sync_to_async
1717
from .files_utils import get_mime_type, is_archive, is_archive_split
@@ -131,8 +131,8 @@ async def take_ss(video_file, ss_nb) -> bool:
131131
output = f"{dirpath}/SS.{name}_{i:02}.png"
132132
cmd = [
133133
"taskset",
134-
"-c",
135-
f"{cores}",
134+
"-c",
135+
f"{cores}",
136136
"xtra",
137137
"-hide_banner",
138138
"-loglevel",
@@ -176,8 +176,8 @@ async def get_audio_thumbnail(audio_file):
176176
output = ospath.join(output_dir, f"{time()}.jpg")
177177
cmd = [
178178
"taskset",
179-
"-c",
180-
f"{cores}",
179+
"-c",
180+
f"{cores}",
181181
"xtra",
182182
"-hide_banner",
183183
"-loglevel",
@@ -218,8 +218,8 @@ async def get_video_thumbnail(video_file, duration):
218218
duration = duration // 2
219219
cmd = [
220220
"taskset",
221-
"-c",
222-
f"{cores}",
221+
"-c",
222+
f"{cores}",
223223
"xtra",
224224
"-hide_banner",
225225
"-loglevel",
@@ -264,8 +264,8 @@ async def get_multiple_frames_thumbnail(video_file, layout, keep_screenshots):
264264
output = ospath.join(output_dir, f"{time()}.jpg")
265265
cmd = [
266266
"taskset",
267-
"-c",
268-
f"{cores}",
267+
"-c",
268+
f"{cores}",
269269
"xtra",
270270
"-hide_banner",
271271
"-loglevel",
@@ -388,7 +388,6 @@ async def _ffmpeg_progress(self):
388388
except Exception:
389389
self._progress_raw = 0
390390
self._eta_raw = 0
391-
392391

393392
async def ffmpeg_cmds(self, ffmpeg, f_path):
394393
self.clear()
@@ -484,8 +483,8 @@ async def convert_video(self, video_file, ext, retry=False):
484483
if retry:
485484
cmd = [
486485
"taskset",
487-
"-c",
488-
f"{cores}",
486+
"-c",
487+
f"{cores}",
489488
"xtra",
490489
"-hide_banner",
491490
"-loglevel",
@@ -513,8 +512,8 @@ async def convert_video(self, video_file, ext, retry=False):
513512
else:
514513
cmd = [
515514
"taskset",
516-
"-c",
517-
f"{cores}",
515+
"-c",
516+
f"{cores}",
518517
"xtra",
519518
"-hide_banner",
520519
"-loglevel",
@@ -568,8 +567,8 @@ async def convert_audio(self, audio_file, ext):
568567
output = f"{base_name}.{ext}"
569568
cmd = [
570569
"taskset",
571-
"-c",
572-
f"{cores}",
570+
"-c",
571+
f"{cores}",
573572
"xtra",
574573
"-hide_banner",
575574
"-loglevel",
@@ -642,8 +641,8 @@ async def sample_video(self, video_file, sample_duration, part_duration):
642641

643642
cmd = [
644643
"taskset",
645-
"-c",
646-
f"{cores}",
644+
"-c",
645+
f"{cores}",
647646
"xtra",
648647
"-hide_banner",
649648
"-loglevel",
@@ -707,8 +706,8 @@ async def split(self, f_path, file_, parts, split_size):
707706
out_path = f_path.replace(file_, f"{base_name}.part{i:03}{extension}")
708707
cmd = [
709708
"taskset",
710-
"-c",
711-
f"{cores}",
709+
"-c",
710+
f"{cores}",
712711
"xtra",
713712
"-hide_banner",
714713
"-loglevel",

bot/helper/listeners/task_listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
get_path_size,
3333
join_files,
3434
remove_excluded_files,
35-
remove_non_included_files
35+
remove_non_included_files,
3636
)
3737
from bot.helper.ext_utils.links_utils import is_gdrive_id
3838
from bot.helper.ext_utils.status_utils import get_readable_file_size

bot/helper/mirror_leech_utils/download_utils/yt_dlp_download.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
import builtins
2+
import contextlib
13
from logging import getLogger
2-
from os import path as ospath, listdir
4+
from os import listdir
5+
from os import path as ospath
36
from re import search as re_search
4-
from secrets import token_urlsafe
5-
from yt_dlp import YoutubeDL, DownloadError
67

8+
from yt_dlp import DownloadError, YoutubeDL
79

8-
from .... import task_dict_lock, task_dict
9-
from ...ext_utils.bot_utils import sync_to_async, async_to_sync
10-
from ...ext_utils.task_manager import check_running_tasks, stop_duplicate_check
11-
from ...mirror_leech_utils.status_utils.queue_status import QueueStatus
12-
from ...telegram_helper.message_utils import send_status_message
13-
from ..status_utils.yt_dlp_status import YtDlpStatus
10+
from bot import task_dict, task_dict_lock
11+
from bot.helper.ext_utils.bot_utils import async_to_sync, sync_to_async
12+
from bot.helper.ext_utils.task_manager import (
13+
check_running_tasks,
14+
stop_duplicate_check,
15+
)
16+
from bot.helper.mirror_leech_utils.status_utils.queue_status import QueueStatus
17+
from bot.helper.mirror_leech_utils.status_utils.yt_dlp_status import YtDlpStatus
18+
from bot.helper.telegram_helper.message_utils import send_status_message
1419

1520
LOGGER = getLogger(__name__)
1621

@@ -22,14 +27,14 @@ def __init__(self, obj, listener):
2227

2328
def debug(self, msg):
2429
# Hack to fix changing extension
25-
if not self._obj.is_playlist:
26-
if match := re_search(
27-
r".Merger..Merging formats into..(.*?).$", msg
28-
) or re_search(r".ExtractAudio..Destination..(.*?)$", msg):
29-
LOGGER.info(msg)
30-
newname = match.group(1)
31-
newname = newname.rsplit("/", 1)[-1]
32-
self._listener.name = newname
30+
if not self._obj.is_playlist and (
31+
match := re_search(r".Merger..Merging formats into..(.*?).$", msg)
32+
or re_search(r".ExtractAudio..Destination..(.*?)$", msg)
33+
):
34+
LOGGER.info(msg)
35+
newname = match.group(1)
36+
newname = newname.rsplit("/", 1)[-1]
37+
self._listener.name = newname
3338

3439
@staticmethod
3540
def warning(msg):
@@ -116,14 +121,14 @@ def _on_download_progress(self, d):
116121
self._listener.size = d["total_bytes_estimate"] or 0
117122
self._downloaded_bytes = d["downloaded_bytes"] or 0
118123
self._eta = d.get("eta", "-") or "-"
119-
try:
124+
with contextlib.suppress(builtins.BaseException):
120125
self._progress = (self._downloaded_bytes / self._listener.size) * 100
121-
except:
122-
pass
123126

124127
async def _on_download_start(self, from_queue=False):
125128
async with task_dict_lock:
126-
task_dict[self._listener.mid] = YtDlpStatus(self._listener, self, self._gid)
129+
task_dict[self._listener.mid] = YtDlpStatus(
130+
self._listener, self, self._gid
131+
)
127132
if not from_queue:
128133
await self._listener.on_download_start()
129134
if self._listener.multi <= 1:
@@ -147,7 +152,7 @@ def _extract_meta_data(self):
147152
for entry in result["entries"]:
148153
if not entry:
149154
continue
150-
elif "filesize_approx" in entry:
155+
if "filesize_approx" in entry:
151156
self._listener.size += entry.get("filesize_approx", 0) or 0
152157
elif "filesize" in entry:
153158
self._listener.size += entry.get("filesize", 0) or 0
@@ -163,10 +168,13 @@ def _extract_meta_data(self):
163168
realName = ydl.prepare_filename(result, outtmpl=outtmpl_)
164169
ext = ospath.splitext(realName)[-1]
165170
self._listener.name = (
166-
f"{self._listener.name}{ext}" if self._listener.name else realName
171+
f"{self._listener.name}{ext}"
172+
if self._listener.name
173+
else realName
167174
)
168175
if not self._ext:
169176
self._ext = ext
177+
return None
170178

171179
def _download(self, path):
172180
try:
@@ -356,4 +364,4 @@ def _set_options(self, options):
356364
else:
357365
if key == "writethumbnail" and value is True:
358366
self.keep_thumb = True
359-
self.opts[key] = value
367+
self.opts[key] = value

bot/helper/mirror_leech_utils/gdrive_utils/clone.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,19 @@ def _clone_folder(self, folder_name, folder_id, dest_id):
120120
file_path = ospath.join(folder_name, file.get("name"))
121121
current_dir_id = self.create_directory(file.get("name"), dest_id)
122122
self._clone_folder(file_path, file.get("id"), current_dir_id)
123-
elif self.listener.included_extensions and not file.get(
124-
"name"
125-
).strip().lower().endswith(tuple(self.listener.included_extensions)):
126-
continue
127-
elif not self.listener.included_extensions and file.get(
128-
"name"
129-
).strip().lower().endswith(tuple(self.listener.excluded_extensions)):
123+
elif (
124+
self.listener.included_extensions
125+
and not file.get("name")
126+
.strip()
127+
.lower()
128+
.endswith(tuple(self.listener.included_extensions))
129+
) or (
130+
not self.listener.included_extensions
131+
and file.get("name")
132+
.strip()
133+
.lower()
134+
.endswith(tuple(self.listener.excluded_extensions))
135+
):
130136
continue
131137
else:
132138
self.total_files += 1

bot/helper/mirror_leech_utils/gdrive_utils/download.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,20 @@ def _download_folder(self, folder_id, path, folder_name):
8686
mime_type = item.get("mimeType")
8787
if mime_type == self.G_DRIVE_DIR_MIME_TYPE:
8888
self._download_folder(file_id, path, filename)
89-
elif ospath.isfile(f"{path}{filename}"):
90-
continue
91-
elif (
92-
self.listener.included_extensions
93-
and not filename.strip()
94-
.lower()
95-
.endswith(tuple(self.listener.included_extensions))
96-
):
97-
continue
9889
elif (
99-
not self.listener.included_extensions
100-
and filename.strip()
101-
.lower()
102-
.endswith(tuple(self.listener.excluded_extensions))
90+
ospath.isfile(f"{path}{filename}")
91+
or (
92+
self.listener.included_extensions
93+
and not filename.strip()
94+
.lower()
95+
.endswith(tuple(self.listener.included_extensions))
96+
)
97+
or (
98+
not self.listener.included_extensions
99+
and filename.strip()
100+
.lower()
101+
.endswith(tuple(self.listener.excluded_extensions))
102+
)
103103
):
104104
continue
105105
else:

bot/helper/mirror_leech_utils/rclone_utils/transfer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __init__(self, listener):
3333
self._sa_index = 0
3434
self._sa_number = 0
3535
self._use_service_accounts = Config.USE_SERVICE_ACCOUNTS
36-
3736

3837
@property
3938
def transferred_size(self):

bot/modules/stats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ async def bot_stats(_, message):
4343
swap = swap_memory()
4444
memory = virtual_memory()
4545
per_cpu = cpu_percent(interval=1, percpu=True)
46-
per_cpu_str = " | ".join([f"CPU{i+1}: {round(p)}%" for i, p in enumerate(per_cpu)])
46+
per_cpu_str = " | ".join(
47+
[f"CPU{i + 1}: {round(p)}%" for i, p in enumerate(per_cpu)]
48+
)
4749
stats = f"""
4850
<b>Commit Date:</b> {commands["commit"]}
4951

bot/modules/users_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ async def get_user_settings(from_user, stype="main"):
289289
and Config.UPLOAD_PATHS
290290
):
291291
upload_paths = Config.UPLOAD_PATHS
292-
if not upload_paths:
292+
if not upload_paths:
293293
upload_paths = "None"
294294

295295
buttons.data_button("Upload Paths", f"userset {user_id} menu UPLOAD_PATHS")

0 commit comments

Comments
 (0)