Skip to content

Commit

Permalink
Auto-format code [skip actions]
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 26, 2024
1 parent d6932d3 commit 1a98555
Show file tree
Hide file tree
Showing 38 changed files with 202 additions and 136 deletions.
4 changes: 2 additions & 2 deletions bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
from asyncio import Lock, new_event_loop, set_event_loop
from logging import (
ERROR,
Expand All @@ -10,7 +11,7 @@
)
from socket import setdefaulttimeout
from time import time
import subprocess

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from aria2p import API as ariaAPI
from aria2p import Client as ariaClient
Expand Down Expand Up @@ -111,5 +112,4 @@
shorteners_list.append({"domain": temp[0], "api_key": temp[1]})



scheduler = AsyncIOScheduler(timezone=str(get_localzone()), event_loop=bot_loop)
7 changes: 3 additions & 4 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from asyncio import gather
from signal import SIGINT, signal

from .core.config_manager import Config

from . import LOGGER, bot_loop
from .core.handlers import add_handlers
from .core.aeon_client import TgClient
from .core.config_manager import Config
from .core.handlers import add_handlers
from .core.startup import (
load_configurations,
load_settings,
Expand All @@ -25,9 +24,9 @@
restart_notification,
)


Config.load()


async def main():
await load_settings()
await gather(TgClient.start_bot(), TgClient.start_user())
Expand Down
2 changes: 1 addition & 1 deletion bot/core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def add_handlers():
),
)
TgClient.bot.add_handler(
CallbackQueryHandler(rss_listener, filters=regex("^rss"))
CallbackQueryHandler(rss_listener, filters=regex("^rss")),
)
TgClient.bot.add_handler(
MessageHandler(
Expand Down
17 changes: 8 additions & 9 deletions bot/core/startup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from asyncio import create_subprocess_exec, create_subprocess_shell

import subprocess
from asyncio import create_subprocess_exec, create_subprocess_shell
from os import environ

from aiofiles import open as aiopen
from aiofiles.os import makedirs, remove
from aiofiles.os import path as aiopath
from aioshutil import rmtree
from os import environ, getcwd

from bot import (
LOGGER,
Expand All @@ -17,14 +16,14 @@
extension_filter,
index_urls,
qbit_options,
xnox_client,
rss_dict,
user_data,
xnox_client,
)
from bot.helper.ext_utils.db_handler import database

from .config_manager import Config
from .aeon_client import TgClient
from .config_manager import Config


def update_qb_options():
Expand Down Expand Up @@ -55,7 +54,7 @@ async def load_settings():
BOT_ID = Config.BOT_TOKEN.split(":", 1)[0]
config_file = Config.get_all()
old_config = await database.db.settings.deployConfig.find_one(
{"_id": BOT_ID}
{"_id": BOT_ID},
)
if old_config is None:
database.db.settings.deployConfig.replace_one(
Expand Down Expand Up @@ -223,9 +222,9 @@ async def load_configurations():

PORT = environ.get("BASE_URL_PORT") or environ.get("PORT")
await create_subprocess_shell(
f"gunicorn web.wserver:app --bind 0.0.0.0:{PORT} --worker-class gevent",
)
f"gunicorn web.wserver:app --bind 0.0.0.0:{PORT} --worker-class gevent",
)

if await aiopath.exists("accounts.zip"):
if await aiopath.exists("accounts"):
await rmtree("accounts")
Expand Down
55 changes: 34 additions & 21 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
task_dict_lock,
user_data,
)
from bot.core.config_manager import Config
from bot.core.aeon_client import TgClient
from bot.core.config_manager import Config

from .ext_utils.bot_utils import get_size_bytes, new_task, sync_to_async
from .ext_utils.bulk_links import extract_bulk_links
Expand Down Expand Up @@ -165,19 +165,19 @@ async def before_start(self):
else ["aria2", "!qB"]
)
if self.link not in ["rcl", "gdl"]:
if is_rclone_path(self.link):
if not self.link.startswith("mrcc:") and self.user_dict.get(
"user_tokens",
False,
):
self.link = f"mrcc:{self.link}"
await self.is_token_exists(self.link, "dl")
elif is_gdrive_link(self.link):
if not self.link.startswith(
("mtp:", "tp:", "sa:"),
) and self.user_dict.get("user_tokens", False):
self.link = f"mtp:{self.link}"
await self.is_token_exists(self.link, "dl")
if is_rclone_path(self.link):
if not self.link.startswith("mrcc:") and self.user_dict.get(
"user_tokens",
False,
):
self.link = f"mrcc:{self.link}"
await self.is_token_exists(self.link, "dl")
elif is_gdrive_link(self.link):
if not self.link.startswith(
("mtp:", "tp:", "sa:"),
) and self.user_dict.get("user_tokens", False):
self.link = f"mtp:{self.link}"
await self.is_token_exists(self.link, "dl")
elif self.link == "rcl":
if not self.is_ytdlp:
self.link = await RcloneList(self).get_rclone_path("rcd")
Expand Down Expand Up @@ -545,7 +545,9 @@ async def init_bulk(self, input_list, bulk_start, bulk_end, obj):
async def decompress_zst(self, dl_path, is_dir=False):
if is_dir:
for dirpath, _, files in await sync_to_async(
walk, dl_path, topdown=False
walk,
dl_path,
topdown=False,
):
for file_ in files:
if file_.endswith(".zst"):
Expand Down Expand Up @@ -591,7 +593,7 @@ async def decompress_zst(self, dl_path, is_dir=False):
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Unable to extract zst file!. Path: {dl_path}"
f"{stderr}. Unable to extract zst file!. Path: {dl_path}",
)
elif not self.seed:
await remove(dl_path)
Expand Down Expand Up @@ -890,7 +892,9 @@ async def generate_sample_video(self, dl_path, gid, unwanted_files, ft_delete):
return new_folder
else:
for dirpath, _, files in await sync_to_async(
walk, dl_path, topdown=False
walk,
dl_path,
topdown=False,
):
for file_ in files:
f_path = ospath.join(dirpath, file_)
Expand Down Expand Up @@ -1019,7 +1023,9 @@ async def proceed_convert(m_path):
return output_file
else:
for dirpath, _, files in await sync_to_async(
walk, dl_path, topdown=False
walk,
dl_path,
topdown=False,
):
for file_ in files:
if self.is_cancelled:
Expand Down Expand Up @@ -1068,7 +1074,9 @@ async def generate_screenshots(self, dl_path):
else:
LOGGER.info(f"Creating Screenshot for: {dl_path}")
for dirpath, _, files in await sync_to_async(
walk, dl_path, topdown=False
walk,
dl_path,
topdown=False,
):
for file_ in files:
f_path = ospath.join(dirpath, file_)
Expand All @@ -1094,7 +1102,10 @@ async def substitute(self, dl_path):
res = ""
try:
name = sub(
rf"{pattern}", res, name, flags=IGNORECASE if sen else 0
rf"{pattern}",
res,
name,
flags=IGNORECASE if sen else 0,
)
except Exception as e:
LOGGER.error(
Expand Down Expand Up @@ -1213,7 +1224,9 @@ async def proceed_ffmpeg(self, dl_path, gid):
checked = True
async with task_dict_lock:
task_dict[self.mid] = FFmpegStatus(
self, gid, "FFmpeg"
self,
gid,
"FFmpeg",
)
await cpu_eater_lock.acquire()
LOGGER.info(f"Running ffmpeg cmd for: {f_path}")
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pymongo.server_api import ServerApi

from bot import LOGGER, qbit_options, rss_dict, user_data
from bot.core.config_manager import Config
from bot.core.aeon_client import TgClient
from bot.core.config_manager import Config


class DbManager:
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/ext_utils/files_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ async def count_files_and_folders(path, extension_filter, unwanted_files=None):

def get_base_name(orig_path):
extension = next(
(ext for ext in ARCH_EXT if orig_path.lower().endswith(ext)), ""
(ext for ext in ARCH_EXT if orig_path.lower().endswith(ext)),
"",
)
if extension != "":
return re_split(f"{extension}$", orig_path, maxsplit=1, flags=IGNORECASE)[0]
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def is_multi_streams(path):
)
except Exception as e:
LOGGER.error(
f"Get Video Streams: {e}. Mostly File not found! - File: {path}"
f"Get Video Streams: {e}. Mostly File not found! - File: {path}",
)
return False
if result[0] and result[2] == 0:
Expand Down Expand Up @@ -230,12 +230,12 @@ async def get_document_type(path):
is_video = True
except Exception as e:
LOGGER.error(
f"Get Document Type: {e}. Mostly File not found! - File: {path}"
f"Get Document Type: {e}. Mostly File not found! - File: {path}",
)
if mime_type.startswith("audio"):
return False, True, False
if not mime_type.startswith("video") and not mime_type.endswith(
"octet-stream"
"octet-stream",
):
return is_video, is_audio, is_image
if mime_type.startswith("video"):
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ async def _on_bt_download_complete(api, gid):
async with task_dict_lock:
if task.listener.mid not in task_dict:
await sync_to_async(
api.remove, [download], force=True, files=True
api.remove,
[download],
force=True,
files=True,
)
return
task_dict[task.listener.mid] = Aria2Status(task.listener, gid, True)
Expand Down
5 changes: 3 additions & 2 deletions bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
intervals,
qb_listener_lock,
qb_torrents,
xnox_client,
task_dict,
task_dict_lock,
xnox_client,
)
from bot.core.config_manager import Config
from bot.helper.ext_utils.bot_utils import new_task, sync_to_async
Expand Down Expand Up @@ -61,7 +61,8 @@ async def _stop_duplicate(tor):
if task := await get_task_by_gid(tor.hash[:12]):
if task.listener.stop_duplicate:
task.listener.name = tor.content_path.rsplit("/", 1)[-1].rsplit(
".!qB", 1
".!qB",
1,
)[0]
msg, button = await stop_duplicate_check(task.listener)
if msg:
Expand Down
9 changes: 6 additions & 3 deletions bot/helper/listeners/task_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ async def on_download_complete(self):
self.same_dir[self.folder_name]["total"] -= 1
spath = f"{self.dir}{self.folder_name}"
des_id = next(
iter(self.same_dir[self.folder_name]["tasks"])
iter(self.same_dir[self.folder_name]["tasks"]),
)
des_path = f"{Config.DOWNLOAD_DIR}{des_id}{self.folder_name}"
await makedirs(des_path, exist_ok=True)
LOGGER.info(
f"Moving files from {self.mid} to {des_id}"
f"Moving files from {self.mid} to {des_id}",
)
for item in await listdir(spath):
if item.endswith((".aria2", ".!qB")):
Expand Down Expand Up @@ -245,7 +245,10 @@ async def on_download_complete(self):

if self.is_leech and not self.compress:
await self.proceed_split(
up_dir, unwanted_files_size, unwanted_files, gid
up_dir,
unwanted_files_size,
unwanted_files,
gid,
)
if self.is_cancelled:
return
Expand Down
Loading

0 comments on commit 1a98555

Please sign in to comment.