Skip to content

Commit

Permalink
sync mltb, remove equal splits
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 30, 2024
1 parent 1db34cd commit 9684485
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 66 deletions.
2 changes: 1 addition & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from time import time

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from aria2p import API as ariaAPI
from aria2p import API as ariaAPI # noqa: N811
from aria2p import Client as ariaClient
from qbittorrentapi import Client as QbClient
from tzlocal import get_localzone
Expand Down
7 changes: 3 additions & 4 deletions bot/core/config_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from importlib import import_module

from typing import ClassVar

class Config:
AS_DOCUMENT = False
Expand All @@ -12,10 +12,9 @@ class Config:
DEFAULT_UPLOAD = "rc"
DOWNLOAD_DIR = "/usr/src/app/downloads/"
DELETE_LINKS = False
EQUAL_SPLITS = False
EXTENSION_FILTER = ""
FSUB_IDS = ""
FFMPEG_CMDS = []
FFMPEG_CMDS: ClassVar[list[str]] = []
FILELION_API = ""
GDRIVE_ID = ""
INCOMPLETE_TASK_NOTIFIER = False
Expand Down Expand Up @@ -45,7 +44,7 @@ class Config:
RSS_DELAY = 600
SEARCH_API_LINK = ""
SEARCH_LIMIT = 0
SEARCH_PLUGINS = []
SEARCH_PLUGINS: ClassVar[list[str]] = []
STATUS_LIMIT = 10
STATUS_UPDATE_INTERVAL = 15
STOP_DUPLICATE = False
Expand Down
4 changes: 2 additions & 2 deletions bot/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ async def load_configurations():
if not await aiopath.exists(".netrc"):
async with aiopen(".netrc", "w"):
pass
subprocess.run(["chmod", "600", ".netrc"], check=False)
subprocess.run(["cp", ".netrc", "/root/.netrc"], check=False)
await (await create_subprocess_shell("chmod 600 .netrc")).wait()
await (await create_subprocess_shell("cp .netrc /root/.netrc")).wait()

PORT = environ.get("PORT") or environ.get("BASE_URL_PORT", 80)
await create_subprocess_shell(
Expand Down
26 changes: 12 additions & 14 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def __init__(self):
self.is_qbit = False
self.is_clone = False
self.is_ytdlp = False
self.equal_splits = False
self.user_transmission = False
self.mixed_leech = False
self.extract = False
Expand Down Expand Up @@ -367,7 +366,7 @@ async def before_start(self):
ChatAction.TYPING,
)
except Exception:
raise ValueError("Start the bot and try again!")
raise ValueError("Start the bot and try again!") from None
elif (
self.user_transmission or self.mixed_leech
) and not self.is_super_chat:
Expand All @@ -383,9 +382,6 @@ async def before_start(self):
or self.user_dict.get("split_size")
or Config.LEECH_SPLIT_SIZE
)
self.equal_splits = self.user_dict.get("equal_splits") or (
Config.EQUAL_SPLITS and "equal_splits" not in self.user_dict
)
self.max_split_size = (
TgClient.MAX_SPLIT_SIZE if self.user_transmission else 2097152000
)
Expand Down Expand Up @@ -735,11 +731,7 @@ async def proceed_compress(self, dl_path, gid, o_files, ft_delete):
async with task_dict_lock:
task_dict[self.mid] = SevenZStatus(self, gid, "Zip")
size = await get_path_size(dl_path)
if self.equal_splits:
parts = -(-size // self.split_size)
split_size = (size // parts) + (size % parts)
else:
split_size = self.split_size
split_size = self.split_size
cmd = [
"7z",
f"-v{split_size}b",
Expand Down Expand Up @@ -1198,8 +1190,11 @@ async def proceed_ffmpeg(self, dl_path, gid):
res = await run_ffmpeg_cmd(self, cmd, file_path)
if res and delete_files:
await remove(file_path)
if "ffmpeg." in res:
newres = res.replace("ffmpeg.", "")
directory = ospath.dirname(res)
file_name = ospath.basename(res)
if file_name.startswith("ffmpeg."):
newname = file_name.replace("ffmpeg.", "")
newres = ospath.join(directory, newname)
await move(res, newres)
else:
for dirpath, _, files in await sync_to_async(
Expand Down Expand Up @@ -1235,8 +1230,11 @@ async def proceed_ffmpeg(self, dl_path, gid):
res = await run_ffmpeg_cmd(self, cmd, f_path)
if res and delete_files:
await remove(f_path)
if "ffmpeg." in res:
newres = res.replace("ffmpeg.", "")
directory = ospath.dirname(res)
file_name = ospath.basename(res)
if file_name.startswith("ffmpeg."):
newname = file_name.replace("ffmpeg.", "")
newres = ospath.join(directory, newname)
await move(res, newres)
if checked:
cpu_eater_lock.release()
Expand Down
23 changes: 11 additions & 12 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ def process_argument_with_values(start_index):
values.append(items[j])
return values

def process_nested_list(start_index):
values = []
end_index = start_index + 1
while end_index < total and items[end_index] != "]":
values.append(items[end_index])
end_index += 1
return values, end_index - start_index

while i < total:
part = items[i]
if part in arg_base:
Expand All @@ -149,10 +141,17 @@ def process_nested_list(start_index):
"-med",
]:
arg_base[part] = True
elif part == "-ff" and i + 1 < total and items[i + 1].startswith("["):
nested_values, skip_count = process_nested_list(i + 1)
arg_base[part] = nested_values
i += skip_count
elif part == "-ff":
i += 1
if i < total:
values = []
while i < total:
values.append(items[i])
if items[i].endswith("]"):
break
else:
i += 1
arg_base[part] = " ".join(values)
else:
sub_list = process_argument_with_values(i)
if sub_list:
Expand Down
5 changes: 0 additions & 5 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,12 @@ async def split_file(
listener,
start_time=0,
i=1,
inLoop=False,
multi_streams=True,
):
if listener.seed and not listener.new_dir:
dirpath = f"{dirpath}/splited_files"
await makedirs(dirpath, exist_ok=True)
parts = -(-size // listener.split_size)
if listener.equal_splits and not inLoop:
split_size = (size // parts) + (size % parts)
if not listener.as_doc and (await get_document_type(path))[0]:
if multi_streams:
multi_streams = await is_multi_streams(path)
Expand Down Expand Up @@ -506,7 +503,6 @@ async def split_file(
listener,
start_time,
i,
True,
False,
)
LOGGER.warning(
Expand All @@ -527,7 +523,6 @@ async def split_file(
listener,
start_time,
i,
True,
multi_streams,
)
lpd = (await get_media_info(out_path))[0]
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/mirror_leech_utils/rclone_utils/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def rclone_serve_booter():
config.add_section("combine")
config.set("combine", "type", "combine")
config.set("combine", "upstreams", upstreams)
with open("rclone.conf", "w") as f:
async with aiopen("rclone.conf", "w") as f:
config.write(f, space_around_delimiters=False)
if RcloneServe:
try:
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/telegram_helper/message_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cachetools import TTLCache
from pyrogram import Client, enums
from pyrogram.errors import FloodWait, MessageEmpty, MessageNotModified
from pyrogram.errors import FloodWait, MessageEmpty, MessageNotModified, FloodPremiumWait
from pyrogram.types import InputMediaPhoto

from bot import (
Expand Down Expand Up @@ -279,7 +279,7 @@ async def get_tg_link_message(link, user_id=""):
raise TgLinkException("Private: Please report!")


async def check_permission(client, chat, uploader_id, up_dest):
async def check_permission(_, chat, uploader_id, __):
member = await chat.get_member(uploader_id)
if (
not member.privileges.can_manage_chat
Expand Down
2 changes: 2 additions & 0 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from bot.helper.telegram_helper.message_utils import (
delete_message,
send_message,
delete_links,
five_minute_del,
send_status_message,
)

Expand Down
1 change: 1 addition & 0 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: RUF006
from asyncio import create_task
from base64 import b64encode
from re import match as re_match
Expand Down
24 changes: 0 additions & 24 deletions bot/modules/users_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ async def get_user_settings(from_user):
else:
split_size = Config.LEECH_SPLIT_SIZE

if user_dict.get("equal_splits", False) or (
"equal_splits" not in user_dict and Config.EQUAL_SPLITS
):
equal_splits = "Enabled"
else:
equal_splits = "Disabled"

if user_dict.get("media_group", False) or (
"media_group" not in user_dict and Config.MEDIA_GROUP
):
Expand Down Expand Up @@ -182,7 +175,6 @@ async def get_user_settings(from_user):
Leech Type is <b>{ltype}</b>
Custom Thumbnail <b>{thumbmsg}</b>
Leech Split Size is <b>{split_size}</b>
Equal Splits is <b>{equal_splits}</b>
Media Group is <b>{media_group}</b>
Leech Prefix is <code>{escape(lprefix)}</code>
Leech Destination is <code>{leech_dest}</code>
Expand Down Expand Up @@ -366,7 +358,6 @@ async def edit_user_settings(client, query):
await query.answer("Not Yours!", show_alert=True)
elif data[2] in [
"as_doc",
"equal_splits",
"media_group",
"user_transmission",
"stop_duplicate",
Expand Down Expand Up @@ -444,20 +435,6 @@ async def edit_user_settings(client, query):
else:
ltype = "MEDIA"
buttons.data_button("Send As Document", f"userset {user_id} as_doc true")
if user_dict.get("equal_splits", False) or (
"equal_splits" not in user_dict and Config.EQUAL_SPLITS
):
buttons.data_button(
"Disable Equal Splits",
f"userset {user_id} equal_splits false",
)
equal_splits = "Enabled"
else:
buttons.data_button(
"Enable Equal Splits",
f"userset {user_id} equal_splits true",
)
equal_splits = "Disabled"
if user_dict.get("media_group", False) or (
"media_group" not in user_dict and Config.MEDIA_GROUP
):
Expand Down Expand Up @@ -520,7 +497,6 @@ async def edit_user_settings(client, query):
Leech Type is <b>{ltype}</b>
Custom Thumbnail <b>{thumbmsg}</b>
Leech Split Size is <b>{split_size}</b>
Equal Splits is <b>{equal_splits}</b>
Media Group is <b>{media_group}</b>
Leech Prefix is <code>{escape(lprefix)}</code>
Leech Destination is <code>{leech_dest}</code>
Expand Down
1 change: 0 additions & 1 deletion config_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
# Leech
LEECH_SPLIT_SIZE = 0
AS_DOCUMENT = False
EQUAL_SPLITS = False
MEDIA_GROUP = False
USER_TRANSMISSION = False
MIXED_LEECH = False
Expand Down

0 comments on commit 9684485

Please sign in to comment.