diff --git a/bot/core/config_manager.py b/bot/core/config_manager.py
index f2bf01a82..5ad84d83e 100644
--- a/bot/core/config_manager.py
+++ b/bot/core/config_manager.py
@@ -66,6 +66,7 @@ class Config:
DELETE_LINKS = False
FSUB_IDS = ""
LOG_CHAT_ID = 0
+ LEECH_FILENAME_CAPTION = ""
@classmethod
def get(cls, key):
diff --git a/bot/core/startup.py b/bot/core/startup.py
index 7097fdc64..70b727995 100644
--- a/bot/core/startup.py
+++ b/bot/core/startup.py
@@ -198,7 +198,7 @@ async def update_variables():
if await aiopath.exists("list_drives.txt"):
async with aiopen("list_drives.txt", "r+") as f:
- lines = f.readlines()
+ lines = await f.readlines()
for line in lines:
temp = line.strip().split()
drives_ids.append(temp[1])
diff --git a/bot/helper/mirror_leech_utils/telegram_uploader.py b/bot/helper/mirror_leech_utils/telegram_uploader.py
index 2d47dcbd5..61f3c7f31 100644
--- a/bot/helper/mirror_leech_utils/telegram_uploader.py
+++ b/bot/helper/mirror_leech_utils/telegram_uploader.py
@@ -23,6 +23,7 @@
InputMediaPhoto,
InputMediaVideo,
)
+from bot.helper.aeon_utils.caption_gen import generate_caption
from tenacity import (
RetryError,
retry,
@@ -56,6 +57,7 @@ def __init__(self, listener, path):
self._last_uploaded = 0
self._processed_bytes = 0
self._listener = listener
+ self._user_id = listener.user_id
self._path = path
self._start_time = time()
self._total_files = 0
@@ -67,6 +69,7 @@ def __init__(self, listener, path):
self._last_msg_in_group = False
self._up_path = ""
self._lprefix = ""
+ self._lcaption = ""
self._media_group = False
self._is_private = False
self._sent_msg = None
@@ -94,6 +97,11 @@ async def _user_settings(self):
if "lprefix" not in self._listener.user_dict
else ""
)
+ self._lcaption = self._listener.user_dict.get("lcaption") or (
+ Config.LEECH_FILENAME_CAPTION
+ if "lcaption" not in self._listener.user_dict
+ else ""
+ )
if self._thumb != "none" and not await aiopath.exists(self._thumb):
self._thumb = None
@@ -142,8 +150,11 @@ async def _msg_to_reply(self):
return True
async def _prepare_file(self, file_, dirpath, delete_file):
+ if self._lcaption:
+ cap_mono = await generate_caption(file_, dirpath, self._lcaption)
if self._lprefix:
- cap_mono = f"{self._lprefix} {file_}
"
+ if not self._lcaption:
+ cap_mono = f"{self._lprefix} {file_}
"
self._lprefix = re_sub("<.*?>", "", self._lprefix)
if (
self._listener.seed
@@ -503,6 +514,8 @@ async def _upload_file(self, cap_mono, file, o_path, force_document=False):
progress=self._upload_progress,
)
+ await _copy_message()
+
if (
not self._listener.is_cancelled
and self._media_group
@@ -555,6 +568,29 @@ async def _upload_file(self, cap_mono, file, o_path, force_document=False):
return await self._upload_file(cap_mono, file, o_path, True)
raise err
+ async def _copy_message(self):
+ await sleep(1)
+
+ async def _copy(target, retries=3):
+ for attempt in range(retries):
+ try:
+ msg = await bot.get_messages(
+ self._sent_msg.chat.id, self._sent_msg.id
+ )
+ await msg.copy(target)
+ return
+ except Exception as e:
+ LOGGER.error(f"Attempt {attempt + 1} failed: {e} {msg.id}")
+ if attempt < retries - 1:
+ await sleep(0.5)
+ LOGGER.error(f"Failed to copy message after {retries} attempts")
+
+ # if self.dm_mode:
+ await _copy(self._user_id)
+
+ # if self._user_dump:
+ # await _copy(self._user_dump)
+
@property
def speed(self):
try:
diff --git a/bot/modules/mirror_leech.py b/bot/modules/mirror_leech.py
index 4f575f35d..29d91b0d8 100644
--- a/bot/modules/mirror_leech.py
+++ b/bot/modules/mirror_leech.py
@@ -299,8 +299,9 @@ async def new_event(self):
file_ = None
if (
- self.link and (is_magnet(self.link) or self.link.endswith(".torrent"))
- ) or (file_ and getattr(file_, "file_name", "").endswith(".torrent")):
+ self.link
+ and (is_magnet(self.link) or self.link.endswith(".torrent"))
+ ) or (file_ and file_.file_name and file_.file_name.endswith(".torrent")):
self.is_qbit = True
if (
diff --git a/bot/modules/users_settings.py b/bot/modules/users_settings.py
index 9e2deaee7..2f400cd55 100644
--- a/bot/modules/users_settings.py
+++ b/bot/modules/users_settings.py
@@ -44,12 +44,6 @@ async def get_user_settings(from_user):
# User Data
user_dict = user_data.get(user_id, {})
thumbnail = thumbpath if await aiopath.exists(thumbpath) else no_thumb
- split_size = Config.LEECH_SPLIT_SIZE
- lprefix = user_dict.get("lprefix", Config.LEECH_FILENAME_PREFIX or "None")
- leech_dest = user_dict.get("leech_dest", Config.LEECH_DUMP_CHAT or "None")
- gdrive_id = user_dict.get("gdrive_id", Config.GDRIVE_ID or "None")
- index = user_dict.get("index_url", "None")
- upload_paths = "Added" if user_dict.get("upload_paths", False) else "None"
ex_ex = user_dict.get("excluded_extensions", extension_filter or "None")
meta_msg = user_dict.get("metadata", Config.METADATA_KEY or "None")
ns_msg = "Added" if user_dict.get("name_sub", False) else "None"
@@ -81,11 +75,6 @@ async def get_user_settings(from_user):
rccmsg = "Exists" if await aiopath.exists(rclone_conf) else "Not Exists"
rccpath = user_dict.get("rclone_path", Config.RCLONE_PATH or "None")
tokenmsg = "Exists" if await aiopath.exists(token_pickle) else "Not Exists"
- sd_msg = (
- "Enabled"
- if user_dict.get("stop_duplicate", Config.STOP_DUPLICATE)
- else "Disabled"
- )
default_upload = user_dict.get("default_upload", Config.DEFAULT_UPLOAD)
du = "Gdrive API" if default_upload == "gd" else "Rclone"
dur = "Gdrive API" if default_upload != "gd" else "Rclone"
@@ -114,38 +103,23 @@ async def get_user_settings(from_user):
buttons.data_button("Close", f"userset {user_id} close")
# Text
- text = (
- f"Settings for {name}\n"
- f"Leech Type is {ltype}\n"
- f"Leech Split Size is {split_size}\n"
- f"Media Group is {media_group}\n"
- f"Leech Prefix is {escape(lprefix)}
\n"
- f"Leech Destination is {leech_dest}
\n"
- f"Leech by {leech_method} session\n"
- f"Mixed Leech is {mixed_leech}\n"
- f"Thumbnail Layout is {thumb_layout}\n"
- f"Rclone Config {rccmsg}\n"
- f"Rclone Path is {rccpath}
\n"
- f"Gdrive Token {tokenmsg}\n"
- f"Upload Paths is {upload_paths}\n"
- f"Gdrive ID is {gdrive_id}
\n"
- f"Index Link is {index}
\n"
- f"Stop Duplicate is {sd_msg}\n"
- f"Default Package is {du}\n"
- f"Upload using {tr} token/config\n"
- f"Name substitution is {ns_msg}\n"
- f"Metadata key is {meta_msg}\n"
- f"Excluded Extensions is {ex_ex}
\n"
- f"YT-DLP Options is {escape(ytopt)}
\n"
- f"FFMPEG Commands is {ffc}
"
- )
+ text = f""">Settings
+
+**Rclone Config:** {rccmsg}
+**Gdrive Token:** {tokenmsg}
+**Name Substitution:** `{ns_msg}`
+**FFmpeg Commands:** `{ffc}`
+**Metadata Title:** `{meta_msg}`
+**Excluded extension:** `{ex_ex}`
+**YT-DLP Options:** `{ytopt}`
+"""
return text, buttons.build_menu(2), thumbnail
async def update_user_settings(query):
msg, button, thumb = await get_user_settings(query.from_user)
- await edit_message(query.message, msg, button, thumb)
+ await edit_message(query.message, msg, button, thumb, markdown=True)
@new_task
@@ -153,7 +127,7 @@ async def send_user_settings(_, message):
from_user = message.from_user
handler_dict[from_user.id] = False
msg, button, thumb = await get_user_settings(from_user)
- await send_message(message, msg, button, thumb)
+ await send_message(message, msg, button, thumb, markdown=True)
@new_task
@@ -327,6 +301,7 @@ async def edit_user_settings(client, query):
elif data[2] in [
"yt_opt",
"lprefix",
+ "lcaption",
"index_url",
"excluded_extensions",
"name_sub",
@@ -371,6 +346,13 @@ async def edit_user_settings(client, query):
lprefix = Config.LEECH_FILENAME_PREFIX
else:
lprefix = "None"
+ buttons.data_button("Leech Caption", f"userset {user_id} leech_caption")
+ if user_dict.get("lcaption", False):
+ lcaption = user_dict["lcaption"]
+ elif "lcaption" not in user_dict and Config.LEECH_FILENAME_CAPTION:
+ lcaption = Config.LEECH_FILENAME_CAPTION
+ else:
+ lcaption = "None"
if user_dict.get("as_doc", False) or (
"as_doc" not in user_dict and Config.AS_DOCUMENT
):
@@ -437,19 +419,21 @@ async def edit_user_settings(client, query):
buttons.data_button("Back", f"userset {user_id} back")
buttons.data_button("Close", f"userset {user_id} close")
- text = f"""Leech Settings for {name}
-Leech Type is {ltype}
-Custom Thumbnail {thumbmsg}
-Leech Split Size is {split_size}
-Media Group is {media_group}
-Leech Prefix is {escape(lprefix)}
-Leech Destination is {leech_dest}
-Leech by {leech_method} session
-Mixed Leech is {mixed_leech}
-Session string: {session_string}
-Thumbnail Layout is {thumb_layout}
+ text = f""">Leech Settings
+
+**Leech Type:** {ltype}
+**Custom Thumbnail:** {thumbmsg}
+**Media Group:** {media_group}
+**Leech Split Size:** {split_size}
+**Session string:** {session_string}
+**Thumbnail Layout:** {thumb_layout}
+**Leech Prefix:** `{lprefix}`
+**Leech Caption:** `{lcaption}`
"""
- await edit_message(message, text, buttons.build_menu(2))
+# **User Custom Dump:** `{user_dump}`
+
+
+ await edit_message(message, text, buttons.build_menu(2), markdown=True)
elif data[2] == "rclone":
await query.answer()
buttons = ButtonMaker()
@@ -464,10 +448,11 @@ async def edit_user_settings(client, query):
rccpath = RP
else:
rccpath = "None"
- text = f"""Rclone Settings for {name}
-Rclone Config {rccmsg}
-Rclone Path is {rccpath}
"""
- await edit_message(message, text, buttons.build_menu(1))
+ text = f""">Rclone Settings
+
+**Rclone Config:** {rccmsg}
+**Rclone Path:** `{rccpath}`"""
+ await edit_message(message, text, buttons.build_menu(1), markdown=True)
elif data[2] == "gdrive":
await query.answer()
buttons = ButtonMaker()
@@ -500,12 +485,13 @@ async def edit_user_settings(client, query):
index = (
user_dict["index_url"] if user_dict.get("index_url", False) else "None"
)
- text = f"""Gdrive Tools Settings for {name}
-Gdrive Token {tokenmsg}
-Gdrive ID is {gdrive_id}
-Index URL is {index}
-Stop Duplicate is {sd_msg}"""
- await edit_message(message, text, buttons.build_menu(1))
+ text = f""">Gdrive Tools Settings
+
+**Gdrive Token:** {tokenmsg}
+**Gdrive ID:** `{gdrive_id}`
+**Index URL:** `{index}`
+**Stop Duplicate:** {sd_msg}"""
+ await edit_message(message, text, buttons.build_menu(1), markdown=True)
elif data[2] == "sthumb":
await query.answer()
buttons = ButtonMaker()
@@ -516,7 +502,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send a photo to save it as custom thumbnail. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_thumb, pre_event=query)
await event_handler(client, query, pfunc, True)
@@ -537,7 +523,7 @@ async def edit_user_settings(client, query):
Example: format:bv*+mergeall[vcodec=none]|nocheckcertificate:True
Check all yt-dlp api options from this FILE or use this script to convert cli arguments to api options.
"""
- await edit_message(message, rmsg, buttons.build_menu(1))
+ await edit_message(message, rmsg, buttons.build_menu(1), markdown=True)
pfunc = partial(set_option, pre_event=query, option="yt_opt")
await event_handler(client, query, pfunc)
elif data[2] == "ffc":
@@ -562,7 +548,7 @@ async def edit_user_settings(client, query):
2. Second cmd: the input is mltb.video so this cmd will work on all videos and the output is only mltb so the extenstion is same as input files.
3. Third cmd: the input in mltb.m4a so this cmd will work only on m4a audios and the output is mltb.mp3 so the output extension is mp3.
4. Fourth cmd: the input is mltb.audio so this cmd will work on all audios and the output is mltb.mp3 so the output extension is mp3."""
- await edit_message(message, rmsg, buttons.build_menu(1))
+ await edit_message(message, rmsg, buttons.build_menu(1), markdown=True)
pfunc = partial(set_option, pre_event=query, option="ffmpeg_cmds")
await event_handler(client, query, pfunc)
elif data[2] == "rcc":
@@ -578,7 +564,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send rclone.conf. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(add_rclone, pre_event=query)
await event_handler(client, query, pfunc, document=True)
@@ -593,7 +579,7 @@ async def edit_user_settings(client, query):
buttons.data_button("Back", f"userset {user_id} rclone")
buttons.data_button("Close", f"userset {user_id} close")
rmsg = "Send Rclone Path. Timeout: 60 sec"
- await edit_message(message, rmsg, buttons.build_menu(1))
+ await edit_message(message, rmsg, buttons.build_menu(1), markdown=True)
pfunc = partial(set_option, pre_event=query, option="rclone_path")
await event_handler(client, query, pfunc)
elif data[2] == "token":
@@ -609,7 +595,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send token.pickle. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(add_token_pickle, pre_event=query)
await event_handler(client, query, pfunc, document=True)
@@ -621,7 +607,7 @@ async def edit_user_settings(client, query):
buttons.data_button("Back", f"userset {user_id} gdrive")
buttons.data_button("Close", f"userset {user_id} close")
rmsg = "Send Gdrive ID. Timeout: 60 sec"
- await edit_message(message, rmsg, buttons.build_menu(1))
+ await edit_message(message, rmsg, buttons.build_menu(1), markdown=True)
pfunc = partial(set_option, pre_event=query, option="gdrive_id")
await event_handler(client, query, pfunc)
elif data[2] == "index":
@@ -632,7 +618,7 @@ async def edit_user_settings(client, query):
buttons.data_button("Back", f"userset {user_id} gdrive")
buttons.data_button("Close", f"userset {user_id} close")
rmsg = "Send Index URL. Timeout: 60 sec"
- await edit_message(message, rmsg, buttons.build_menu(1))
+ await edit_message(message, rmsg, buttons.build_menu(1), markdown=True)
pfunc = partial(set_option, pre_event=query, option="index_url")
await event_handler(client, query, pfunc)
elif data[2] == "leech_prefix":
@@ -647,10 +633,26 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send Leech Filename Prefix. You can add HTML tags. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_option, pre_event=query, option="lprefix")
await event_handler(client, query, pfunc)
+ elif data[2] == "leech_caption":
+ await query.answer()
+ buttons = ButtonMaker()
+ if user_dict.get("lcaption", False) or (
+ "lcaption" not in user_dict and Config.LEECH_FILENAME_CAPTION
+ ):
+ buttons.data_button("Remove", f"userset {user_id} lcaption")
+ buttons.data_button("Back", f"userset {user_id} leech")
+ buttons.data_button("Close", f"userset {user_id} close")
+ await edit_message(
+ message,
+ "Send Leech Filename Caption. You can add HTML tags. Timeout: 60 sec",
+ buttons.build_menu(1), markdown=True
+ )
+ pfunc = partial(set_option, pre_event=query, option="lcaption")
+ await event_handler(client, query, pfunc)
elif data[2] == "ldest":
await query.answer()
buttons = ButtonMaker()
@@ -666,7 +668,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send leech destination ID/USERNAME/PM. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_option, pre_event=query, option="leech_dest")
await event_handler(client, query, pfunc)
@@ -685,7 +687,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send thumbnail layout (widthxheight, 2x2, 3x3, 2x4, 4x4, ...). Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_option, pre_event=query, option="thumb_layout")
await event_handler(client, query, pfunc)
@@ -722,7 +724,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send exluded extenions seperated by space without dot at beginning. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_option, pre_event=query, option="excluded_extensions")
await event_handler(client, query, pfunc)
@@ -753,7 +755,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
emsg,
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_option, pre_event=query, option="name_sub")
await event_handler(client, query, pfunc)
@@ -795,7 +797,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Add or remove upload path.\n",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
elif data[2] == "new_path":
await query.answer()
@@ -805,7 +807,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send path name(no space in name) which you will use it as a shortcut and the path/id seperated by space. You can add multiple names and paths separated by new line. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(set_option, pre_event=query, option="upload_paths")
await event_handler(client, query, pfunc)
@@ -817,7 +819,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
"Send paths names which you want to delete, separated by space. Timeout: 60 sec",
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
pfunc = partial(delete_path, pre_event=query)
await event_handler(client, query, pfunc)
@@ -834,7 +836,7 @@ async def edit_user_settings(client, query):
await edit_message(
message,
msg,
- buttons.build_menu(1),
+ buttons.build_menu(1), markdown=True
)
elif data[2] == "reset":
await query.answer()
diff --git a/config_sample.py b/config_sample.py
index f94d8035c..975eefbc8 100644
--- a/config_sample.py
+++ b/config_sample.py
@@ -32,6 +32,7 @@
SET_COMMANDS = True
METADATA_KEY = ""
LOG_CHAT_ID = 0
+LEECH_FILENAME_CAPTION = ""
# GDrive Tools
GDRIVE_ID = ""