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 5, 2024
1 parent e6579a8 commit 3473cd5
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 278 deletions.
421 changes: 206 additions & 215 deletions bot/helper/common.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import contextlib
from os import path as ospath
from os import cpu_count
from re import escape
Expand Down
39 changes: 18 additions & 21 deletions bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,29 @@ async def get_task_by_gid(gid: str):
def get_specific_tasks(status, user_id):
if status == "All":
if user_id:
return [tk for tk in task_dict.values() if tk.listener.user_id == user_id]
else:
return list(task_dict.values())
elif user_id:
return [
tk for tk in task_dict.values() if tk.listener.user_id == user_id
]
return list(task_dict.values())
if user_id:
return [
tk
for tk in task_dict.values()
if tk.listener.user_id == user_id
and (
(st := tk.status())
and st == status
or status == MirrorStatus.STATUS_DOWNLOAD
and st not in STATUSES.values()
((st := tk.status()) and st == status)
or (
status == MirrorStatus.STATUS_DOWNLOAD
and st not in STATUSES.values()
)
)
]
else:
return [
tk
for tk in task_dict.values()
if (st := tk.status())
and st == status
or status == MirrorStatus.STATUS_DOWNLOAD
and st not in STATUSES.values()
]
return [
tk
for tk in task_dict.values()
if ((st := tk.status()) and st == status)
or (status == MirrorStatus.STATUS_DOWNLOAD and st not in STATUSES.values())
]


async def get_all_tasks(req_status: str, user_id):
Expand Down Expand Up @@ -209,10 +208,8 @@ async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=
msg += f"\n<b>Processed:</b> {task.processed_bytes()} of {task.size()}"
msg += f"\n<b>Speed:</b> {task.speed()} | <b>ETA:</b> {task.eta()}"
if hasattr(task, "seeders_num"):
try:
with contextlib.suppress(Exception):
msg += f"\n<b>Seeders:</b> {task.seeders_num()} | <b>Leechers:</b> {task.leechers_num()}"
except Exception:
pass
elif tstatus == MirrorStatus.STATUS_SEED:
msg += f"\n<b>Size: </b>{task.size()}"
msg += f"\n<b>Speed: </b>{task.seed_speed()}"
Expand Down Expand Up @@ -245,4 +242,4 @@ async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=
button = buttons.build_menu(8)
msg += f"<b>CPU:</b> {cpu_percent()}% | <b>FREE:</b> {get_readable_file_size(disk_usage(DOWNLOAD_DIR).free)}"
msg += f"\n<b>RAM:</b> {virtual_memory().percent}% | <b>UPTIME:</b> {get_readable_time(time() - botStartTime)}"
return msg, button
return msg, button
14 changes: 3 additions & 11 deletions bot/helper/listeners/task_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from bot import (
LOGGER,
DATABASE_URL,
DOWNLOAD_DIR,
aria2,
intervals,
Expand All @@ -24,7 +23,6 @@
)
from bot.helper.common import TaskConfig
from bot.helper.ext_utils.bot_utils import sync_to_async
from bot.helper.ext_utils.db_handler import Database
from bot.helper.ext_utils.files_utils import (
join_files,
clean_target,
Expand Down Expand Up @@ -309,21 +307,15 @@ async def on_upload_complete(
if mime_type == "Folder":
msg += f"\n<b>SubFolders: </b>{folders}"
msg += f"\n<b>Files: </b>{files}"
if link or (
rclonePath
and not self.private_link
):
if link or (rclonePath and not self.private_link):
buttons = ButtonMaker()
if link:
buttons.url_button("☁️ Cloud Link", link)
else:
msg += f"\n\nPath: <code>{rclonePath}</code>"
if (
rclonePath
and not self.private_link
):
if rclonePath and not self.private_link:
remote, path = rclonePath.split(":", 1)
url_path = rutils.quote(f"{path}")
rutils.quote(f"{path}")
if not rclonePath and dir_id:
INDEX_URL = ""
if self.private_link:
Expand Down
7 changes: 3 additions & 4 deletions bot/helper/mirror_leech_utils/status_utils/ffmpeg_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def size(self):
def status(self):
if self.cstatus == "Convert":
return MirrorStatus.STATUS_CONVERT
elif self.cstatus == "Split":
if self.cstatus == "Split":
return MirrorStatus.STATUS_SPLIT
elif self.cstatus == "Sample Video":
if self.cstatus == "Sample Video":
return MirrorStatus.STATUS_SAMVID
else:
return MirrorStatus.STATUS_FFMPEG
return MirrorStatus.STATUS_FFMPEG

def task(self):
return self
Expand Down
3 changes: 1 addition & 2 deletions bot/helper/mirror_leech_utils/status_utils/sevenz_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def eta(self):
def status(self):
if self.cstatus == "Extract":
return MirrorStatus.STATUS_EXTRACT
else:
return MirrorStatus.STATUS_ARCHIVE
return MirrorStatus.STATUS_ARCHIVE

def processed_bytes(self):
return get_readable_file_size(self._proccessed_bytes)
Expand Down
18 changes: 10 additions & 8 deletions bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
from pyrogram.handlers import MessageHandler, CallbackQueryHandler

from bot import (
global_extension_filter,
intervals,
bot,
intervals,
task_dict,
user_data,
drives_ids,
index_urls,
drives_names,
config_dict,
drives_names,
global_extension_filter,
)
from bot.helper.ext_utils.bot_utils import (
new_task,
SetInterval,
new_task,
)
from bot.helper.ext_utils.db_handler import Database
from bot.helper.ext_utils.task_manager import start_from_queued
Expand Down Expand Up @@ -235,7 +235,7 @@ async def event_filter(_, __, event):
return bool(
user.id == query.from_user.id
and event.chat.id == chat_id
and (event.text or event.document and document)
and (event.text or (event.document and document))
)

handler = client.add_handler(
Expand Down Expand Up @@ -381,7 +381,7 @@ async def load_config():
except Exception:
LOGGER.error(f"Wrong FFMPEG_CMDS format: {FFMPEG_CMDS}")
FFMPEG_CMDS = []

EXTENSION_FILTER = environ.get("EXTENSION_FILTER", "")
if len(EXTENSION_FILTER) > 0:
fx = EXTENSION_FILTER.split()
Expand Down Expand Up @@ -446,7 +446,9 @@ async def load_config():
)

UPSTREAM_BRANCH = environ.get("UPSTREAM_BRANCH", "main")
UPSTREAM_REPO = environ.get("UPSTREAM_REPO", "https://github.com/AeonOrg/Aeon-MLTB")
UPSTREAM_REPO = environ.get(
"UPSTREAM_REPO", "https://github.com/AeonOrg/Aeon-MLTB"
)
drives_ids.clear()
drives_names.clear()
index_urls.clear()
Expand Down Expand Up @@ -523,4 +525,4 @@ async def load_config():
CallbackQueryHandler(
edit_bot_settings, filters=regex("^botset") & CustomFilters.sudo
)
)
)
4 changes: 1 addition & 3 deletions bot/modules/cancel_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def create_cancel_buttons(is_sudo, user_id=""):
buttons.data_button(
"Uploading", f"canall ms {MirrorStatus.STATUS_UPLOAD} {user_id}"
)
buttons.data_button(
"Seeding", f"canall ms {MirrorStatus.STATUS_SEED} {user_id}"
)
buttons.data_button("Seeding", f"canall ms {MirrorStatus.STATUS_SEED} {user_id}")
buttons.data_button(
"Spltting", f"canall ms {MirrorStatus.STATUS_SPLIT} {user_id}"
)
Expand Down
3 changes: 1 addition & 2 deletions web/nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from os import environ
from re import findall as re_findall

from anytree import NodeMixin
Expand Down Expand Up @@ -189,4 +188,4 @@ def extract_file_ids(data):
child_selected, child_unselected = extract_file_ids(item["children"])
selected_files.extend(child_selected)
unselected_files.extend(child_unselected)
return selected_files, unselected_files
return selected_files, unselected_files
25 changes: 14 additions & 11 deletions web/wserver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from aria2p import API as ariaAPI, Client as ariaClient
from flask import Flask, request, render_template, jsonify
from logging import getLogger, FileHandler, StreamHandler, INFO, basicConfig
from qbittorrentapi import NotFound404Error, Client as qbClient
from time import sleep
from logging import INFO, FileHandler, StreamHandler, getLogger, basicConfig

from web.nodes import extract_file_ids, make_tree
from flask import Flask, jsonify, request, render_template
from aria2p import API as ariaAPI
from aria2p import Client as ariaClient
from qbittorrentapi import Client as qbClient
from qbittorrentapi import NotFound404Error

from web.nodes import make_tree, extract_file_ids

app = Flask(__name__)

Expand Down Expand Up @@ -125,11 +128,11 @@ def handle_torrent():
selected_files = ",".join(selected_files)
set_aria2(gid, selected_files)
content = {
"files": [],
"engine": "",
"error": "",
"message": "Your selection has been submitted successfully.",
}
"files": [],
"engine": "",
"error": "",
"message": "Your selection has been submitted successfully.",
}
else:
try:
if len(gid) > 20:
Expand Down Expand Up @@ -193,4 +196,4 @@ def page_not_found(e):


if __name__ == "__main__":
app.run()
app.run()

0 comments on commit 3473cd5

Please sign in to comment.