Spaces:
Running on Zero
Running on Zero
Update TechVJ/start.py
Browse files- TechVJ/start.py +505 -240
TechVJ/start.py
CHANGED
|
@@ -6,16 +6,30 @@ import re
|
|
| 6 |
import subprocess
|
| 7 |
from pyrogram import Client, filters, enums
|
| 8 |
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
|
| 9 |
-
from pyrogram.errors import
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from db import db
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class batch_temp(object):
|
| 14 |
IS_BATCH = {}
|
| 15 |
CLONE_DATA = {}
|
| 16 |
LAST_SAVED_ID = {}
|
| 17 |
-
|
| 18 |
-
LAST_UPDATE_TIME = {}
|
| 19 |
|
| 20 |
def humanbytes(size):
|
| 21 |
if not size:
|
|
@@ -38,38 +52,89 @@ def time_formatter(seconds: int) -> str:
|
|
| 38 |
((str(seconds) + "s") if seconds else "")
|
| 39 |
return tmp if tmp else "0s"
|
| 40 |
|
| 41 |
-
async def progress_bar(current, total, ud_type, message, start, fname=""):
|
| 42 |
now = time.time()
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
def generate_auto_thumb(video_path: str, thumb_path: str):
|
| 75 |
try:
|
|
@@ -84,148 +149,220 @@ def generate_auto_thumb(video_path: str, thumb_path: str):
|
|
| 84 |
pass
|
| 85 |
return None
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
except Exception as e:
|
| 111 |
-
print(f"FFmpeg Error: {e}")
|
| 112 |
-
return False
|
| 113 |
|
| 114 |
def parse_telegram_link(link: str):
|
| 115 |
-
link = link.strip().replace("?single", "")
|
| 116 |
-
|
| 117 |
-
if t_match:
|
| 118 |
-
return int("-100" + t_match.group(1)), int(t_match.group(3)), int(t_match.group(2))
|
| 119 |
-
|
| 120 |
-
c_match = re.search(r"t\.me/c/(\d+)/(\d+)", link)
|
| 121 |
if c_match:
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
b_match = re.search(r"t\.me/b/([^/]+)/(\d+)", link)
|
| 125 |
if b_match:
|
| 126 |
return b_match.group(1), int(b_match.group(2)), None
|
| 127 |
|
| 128 |
-
p_match = re.search(r"t\.me/([^/]+)
|
| 129 |
if p_match:
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
return None, None, None
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
@Client.on_message(filters.command(["resume"]) & filters.private)
|
| 143 |
async def resume_command(client: Client, message: Message):
|
| 144 |
user_id = message.from_user.id
|
|
|
|
|
|
|
|
|
|
| 145 |
task = batch_temp.CLONE_DATA.get(user_id)
|
| 146 |
last_id = batch_temp.LAST_SAVED_ID.get(user_id)
|
| 147 |
if not task or not last_id:
|
| 148 |
-
return await message.reply_text("⚠️ कोई रुका हुआ पिछला टास्क नहीं मिला।
|
| 149 |
|
| 150 |
if last_id >= task["end_id"]:
|
| 151 |
return await message.reply_text("✅ पिछला टास्क पहले ही पूरा हो चुका था।")
|
| 152 |
|
| 153 |
task["start_id"] = last_id + 1
|
| 154 |
await message.reply_text(f"🔄 **टास्क रिज्यूम किया जा रहा है...** (ID `{task['start_id']}` से `{task['end_id']}` तक)")
|
| 155 |
-
|
| 156 |
-
batch_temp.RUNNING_TASKS[user_id] = t
|
| 157 |
|
| 158 |
-
|
| 159 |
-
@Client.on_message(filters.command(["clone"]) & filters.private)
|
| 160 |
async def clone_command(client: Client, message: Message):
|
| 161 |
-
await
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
await init_clone_flow(client, message, is_topic_mode=True)
|
| 167 |
|
| 168 |
-
async def
|
| 169 |
user_id = message.from_user.id
|
| 170 |
if not db.is_user_vip(user_id, ADMINS):
|
| 171 |
-
return await message.reply_text(
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
| 175 |
|
| 176 |
user_session = db.get_session(user_id)
|
| 177 |
if not user_session:
|
| 178 |
return await message.reply_text("🔑 पहले **/login** करें।")
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
first_msg = await client.ask(user_id, guide_text, filters=filters.text, timeout=300)
|
| 184 |
if first_msg.text == "/cancel":
|
| 185 |
return await first_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
|
| 186 |
|
| 187 |
-
|
|
|
|
| 188 |
if not s_id:
|
| 189 |
-
return await first_msg.reply("❌ अमान्य टेलीग्राम लिंक! दोबारा
|
| 190 |
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
if last_msg.text == "/cancel":
|
| 198 |
return await last_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
|
| 199 |
|
| 200 |
-
if last_msg.text.strip() == "/single":
|
| 201 |
-
e_chat, e_id = s_chat, s_id
|
| 202 |
else:
|
| 203 |
-
|
|
|
|
| 204 |
if not e_id:
|
| 205 |
-
return await last_msg.reply("❌ अमान्य अंतिम लिंक! दोबारा
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
-
dest_prompt = "👉 **स्टेप 3:** टारगेट सुपरग्रुप (Forum Enabled) की ID भेजें:" if is_topic_mode else "👉 **स्टेप 3:** टारगेट चैनल/ग्रुप की ID भेजें (या बॉट चैट के लिए `/skip`):"
|
| 208 |
dest_msg = await client.ask(user_id, dest_prompt, filters=filters.text, timeout=300)
|
| 209 |
if dest_msg.text == "/cancel":
|
| 210 |
return await dest_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
|
| 211 |
|
| 212 |
dest_val = dest_msg.text.strip()
|
| 213 |
-
|
|
|
|
|
|
|
| 214 |
target_chat = user_id
|
|
|
|
| 215 |
else:
|
| 216 |
try:
|
| 217 |
target_chat = int(dest_val)
|
| 218 |
except ValueError:
|
| 219 |
target_chat = dest_val.replace("https://t.me/", "@")
|
| 220 |
|
|
|
|
|
|
|
|
|
|
| 221 |
batch_temp.CLONE_DATA[user_id] = {
|
| 222 |
"source_chat": s_chat,
|
| 223 |
-
"
|
| 224 |
-
"
|
| 225 |
-
"end_id": max(s_id, e_id),
|
| 226 |
"target_chat": target_chat,
|
| 227 |
-
"
|
| 228 |
-
"
|
| 229 |
"custom_caption": None,
|
| 230 |
"extra_caption": None,
|
| 231 |
"replace_find": None,
|
|
@@ -237,32 +374,36 @@ async def init_clone_flow(client: Client, message: Message, is_topic_mode: bool)
|
|
| 237 |
|
| 238 |
async def show_customization_menu(client: Client, user_id: int):
|
| 239 |
data = batch_temp.CLONE_DATA.get(user_id, {})
|
| 240 |
-
cap_status = "सेट है ✅" if data.get("custom_caption") else "
|
| 241 |
ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
|
| 242 |
-
thm_status = "सेट है ✅" if data.get("thumb_path") else "
|
| 243 |
-
wm_status = f"`{data.get('watermark_text')}` ✅" if data.get("watermark_text") else "बंद ❌"
|
| 244 |
rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
panel_text = (
|
| 247 |
"⚙️ **कंटेंट कस्टमाइज़ेशन सेटिंग्स:**\n"
|
| 248 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 249 |
-
f"
|
| 250 |
-
f"
|
|
|
|
| 251 |
f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
|
| 252 |
f"🖼️ कस्टम थंबनेल: `{thm_status}`\n"
|
| 253 |
-
f"
|
| 254 |
-
f"
|
| 255 |
-
f"📊 रेंज: `{data.get('start_id')}` से `{data.get('end_id')}`\n"
|
| 256 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 257 |
-
"सेटिंग
|
| 258 |
)
|
| 259 |
buttons = InlineKeyboardMarkup([
|
| 260 |
-
[InlineKeyboardButton("📝
|
| 261 |
-
InlineKeyboardButton("🔄
|
| 262 |
-
[InlineKeyboardButton("➕
|
| 263 |
-
InlineKeyboardButton("🖼️
|
| 264 |
-
[InlineKeyboardButton("
|
| 265 |
-
InlineKeyboardButton("🗑️
|
| 266 |
[InlineKeyboardButton("🚀 Confirm & Start", callback_data="confirm_start")]
|
| 267 |
])
|
| 268 |
await client.send_message(user_id, panel_text, reply_markup=buttons)
|
|
@@ -270,8 +411,11 @@ async def show_customization_menu(client: Client, user_id: int):
|
|
| 270 |
@Client.on_callback_query()
|
| 271 |
async def callback_handler(client: Client, query: CallbackQuery):
|
| 272 |
user_id = query.from_user.id
|
|
|
|
|
|
|
|
|
|
| 273 |
if user_id not in batch_temp.CLONE_DATA:
|
| 274 |
-
return await query.answer("⚠️ सेशन स
|
| 275 |
|
| 276 |
data = query.data
|
| 277 |
if data == "set_caption":
|
|
@@ -281,10 +425,12 @@ async def callback_handler(client: Client, query: CallbackQuery):
|
|
| 281 |
await show_customization_menu(client, user_id)
|
| 282 |
elif data == "set_replace":
|
| 283 |
await query.message.delete()
|
| 284 |
-
find_msg = await client.ask(user_id, "🔍 क्या खोजना/हटाना चाहते हैं? शब्द
|
| 285 |
if find_msg.text == "/cancel":
|
| 286 |
return await show_customization_menu(client, user_id)
|
| 287 |
-
with_msg = await client.ask(user_id, f"✏️ `{find_msg.text}` की जगह क्या लगाना है? (
|
|
|
|
|
|
|
| 288 |
batch_temp.CLONE_DATA[user_id]["replace_find"] = find_msg.text
|
| 289 |
batch_temp.CLONE_DATA[user_id]["replace_with"] = "" if with_msg.text.strip() == "/empty" else with_msg.text.markdown
|
| 290 |
await show_customization_menu(client, user_id)
|
|
@@ -301,13 +447,18 @@ async def callback_handler(client: Client, query: CallbackQuery):
|
|
| 301 |
thumb_file = os.path.join(user_thumb_dir, "thumb.jpg")
|
| 302 |
await client.download_media(msg.photo, file_name=thumb_file)
|
| 303 |
batch_temp.CLONE_DATA[user_id]["thumb_path"] = thumb_file
|
| 304 |
-
await msg.reply_text("✅ थंबनेल स
|
| 305 |
await show_customization_menu(client, user_id)
|
| 306 |
elif data == "set_wm":
|
| 307 |
await query.message.delete()
|
| 308 |
-
msg = await client.ask(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
if msg.text != "/cancel":
|
| 310 |
-
batch_temp.CLONE_DATA[user_id]["watermark_text"] = msg.text.strip()
|
| 311 |
await show_customization_menu(client, user_id)
|
| 312 |
elif data == "clear_settings":
|
| 313 |
batch_temp.CLONE_DATA[user_id]["custom_caption"] = None
|
|
@@ -324,8 +475,7 @@ async def callback_handler(client: Client, query: CallbackQuery):
|
|
| 324 |
await show_customization_menu(client, user_id)
|
| 325 |
elif data == "confirm_start":
|
| 326 |
await query.message.delete()
|
| 327 |
-
|
| 328 |
-
batch_temp.RUNNING_TASKS[user_id] = t
|
| 329 |
|
| 330 |
async def start_clone_task(client: Client, user_id: int):
|
| 331 |
task = batch_temp.CLONE_DATA.get(user_id)
|
|
@@ -336,21 +486,21 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 336 |
start_id = task["start_id"]
|
| 337 |
end_id = task["end_id"]
|
| 338 |
target_chat = task["target_chat"]
|
| 339 |
-
|
|
|
|
| 340 |
|
| 341 |
user_session = db.get_session(user_id)
|
| 342 |
user_api_id = int(db.get_api_id(user_id) or API_ID)
|
| 343 |
user_api_hash = db.get_api_hash(user_id) or API_HASH
|
| 344 |
|
| 345 |
-
# स्थिर व हाई-स्पीड MTProto कनेक्शन (बिना रेट लिमिट पेनल्टी के 8-12 MB/s)
|
| 346 |
acc = Client(
|
| 347 |
-
f"
|
| 348 |
session_string=user_session,
|
| 349 |
api_hash=user_api_hash,
|
| 350 |
api_id=user_api_id,
|
| 351 |
in_memory=True,
|
| 352 |
-
workers=
|
| 353 |
-
max_concurrent_transmissions=
|
| 354 |
)
|
| 355 |
try:
|
| 356 |
await acc.start()
|
|
@@ -363,25 +513,25 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 363 |
except Exception:
|
| 364 |
pass
|
| 365 |
|
| 366 |
-
|
| 367 |
-
topic_id = None
|
| 368 |
-
if is_topic:
|
| 369 |
try:
|
| 370 |
-
|
| 371 |
-
if
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
| 385 |
|
| 386 |
batch_temp.IS_BATCH[user_id] = False
|
| 387 |
success = 0
|
|
@@ -389,50 +539,70 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 389 |
retrying = 0
|
| 390 |
total_bytes = 0
|
| 391 |
start_time = time.time()
|
|
|
|
| 392 |
|
| 393 |
status_msg = await client.send_message(user_id, "🚀 **कंटेंट ट्रांसफर शुरू हो रहा है...**")
|
|
|
|
| 394 |
|
| 395 |
try:
|
| 396 |
-
for msgid in range(start_id, end_id + 1):
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
await status_msg.edit_text("🚫 **आपका वीआईपी एक्सेस समाप्त हो चुका है। टास्क तुरंत रोक दिया गया।**")
|
| 400 |
break
|
| 401 |
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
| 403 |
break
|
| 404 |
|
| 405 |
attempts = 0
|
| 406 |
-
while attempts <
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
try:
|
| 408 |
-
ok, sz = await process_media(
|
|
|
|
|
|
|
|
|
|
| 409 |
if ok:
|
| 410 |
success += 1
|
| 411 |
total_bytes += sz
|
| 412 |
batch_temp.LAST_SAVED_ID[user_id] = msgid
|
| 413 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
not_found += 1
|
| 415 |
break
|
| 416 |
except FloodWait as fw:
|
| 417 |
await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
|
| 418 |
-
await asyncio.sleep(fw.value +
|
| 419 |
attempts += 1
|
| 420 |
-
except RPCError
|
| 421 |
await asyncio.sleep(2)
|
| 422 |
attempts += 1
|
| 423 |
except Exception:
|
| 424 |
retrying += 1
|
| 425 |
break
|
| 426 |
|
|
|
|
|
|
|
|
|
|
| 427 |
await asyncio.sleep(WAITING_TIME)
|
|
|
|
| 428 |
finally:
|
| 429 |
try:
|
| 430 |
await acc.stop()
|
| 431 |
except Exception:
|
| 432 |
pass
|
| 433 |
-
batch_temp.IS_BATCH[user_id] = True
|
| 434 |
-
batch_temp.RUNNING_TASKS.pop(user_id, None)
|
| 435 |
|
|
|
|
| 436 |
tpath = task.get("thumb_path")
|
| 437 |
if tpath and os.path.exists(tpath):
|
| 438 |
os.remove(tpath)
|
|
@@ -448,10 +618,13 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 448 |
f"🔁 Retrying: {retrying}\n"
|
| 449 |
f"📦 Total Size: {humanbytes(total_bytes)}\n"
|
| 450 |
f"⚡ Avg Speed: {avg_speed}\n"
|
| 451 |
-
f"⏱️ Time:
|
| 452 |
"━━━━━━━━━━━━━━━━━━━━"
|
| 453 |
)
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
def get_file_name_from_msg(msg: Message) -> str:
|
| 457 |
name = None
|
|
@@ -460,18 +633,28 @@ def get_file_name_from_msg(msg: Message) -> str:
|
|
| 460 |
elif msg.video and msg.video.file_name:
|
| 461 |
name = msg.video.file_name
|
| 462 |
elif msg.video:
|
| 463 |
-
name = f"
|
| 464 |
elif msg.audio and msg.audio.file_name:
|
| 465 |
name = msg.audio.file_name
|
| 466 |
elif msg.audio:
|
| 467 |
-
name = f"
|
| 468 |
elif msg.photo:
|
| 469 |
-
name = f"
|
| 470 |
else:
|
| 471 |
-
name = f"
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
-
async def process_media(client: Client, acc: Client, user_id: int, source_chat, msgid: int, target_chat, task: dict, status_msg: Message, topic_id: int = None):
|
| 475 |
msg = None
|
| 476 |
try:
|
| 477 |
msg = await acc.get_messages(source_chat, msgid)
|
|
@@ -479,13 +662,34 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 479 |
try:
|
| 480 |
msg = await client.get_messages(source_chat, msgid)
|
| 481 |
except Exception:
|
| 482 |
-
return False, 0
|
| 483 |
-
|
| 484 |
-
if not msg or msg.empty:
|
| 485 |
-
return False, 0
|
| 486 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
final_caption = msg.caption.markdown if msg.caption else ""
|
| 488 |
-
|
| 489 |
if task.get("custom_caption"):
|
| 490 |
final_caption = task["custom_caption"]
|
| 491 |
elif task.get("replace_find"):
|
|
@@ -495,96 +699,157 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 495 |
final_caption = final_caption.replace(find_w, with_w)
|
| 496 |
|
| 497 |
if task.get("extra_caption"):
|
| 498 |
-
|
|
|
|
|
|
|
|
|
|
| 499 |
|
| 500 |
if msg.text:
|
| 501 |
text_to_send = msg.text.markdown
|
| 502 |
if task.get("custom_caption"):
|
| 503 |
text_to_send = task["custom_caption"]
|
| 504 |
elif task.get("replace_find"):
|
| 505 |
-
|
|
|
|
|
|
|
| 506 |
if task.get("extra_caption"):
|
| 507 |
text_to_send += f"\n\n{task['extra_caption']}"
|
| 508 |
-
|
| 509 |
-
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
-
|
| 512 |
user_down_dir = os.path.join("downloads", str(user_id))
|
| 513 |
os.makedirs(user_down_dir, exist_ok=True)
|
| 514 |
-
down_path = os.path.join(user_down_dir,
|
| 515 |
|
| 516 |
down_start = time.time()
|
| 517 |
-
await status_msg.edit_text(f"📥 **Downloading
|
| 518 |
|
| 519 |
-
|
| 520 |
-
msg,
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
if not file_path or not os.path.exists(file_path):
|
| 527 |
-
return False, 0
|
| 528 |
-
|
| 529 |
-
# रनिंग वॉटरमार्क प्रोसेसिंग
|
| 530 |
-
processed_video = None
|
| 531 |
-
if msg.video and task.get("watermark_text"):
|
| 532 |
-
await status_msg.edit_text(f"🌈 **रनिंग वॉटरमार्क प्रोसेस हो रहा है...**\n📁 `{raw_name}`")
|
| 533 |
-
wm_out_path = os.path.join(user_down_dir, f"wm_{raw_name}")
|
| 534 |
-
if apply_scrolling_watermark(file_path, wm_out_path, task["watermark_text"]):
|
| 535 |
-
processed_video = wm_out_path
|
| 536 |
-
upload_target_path = wm_out_path
|
| 537 |
-
else:
|
| 538 |
-
upload_target_path = file_path
|
| 539 |
-
else:
|
| 540 |
-
upload_target_path = file_path
|
| 541 |
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
up_start = time.time()
|
| 544 |
-
await status_msg.edit_text(f"📤 **Uploading
|
| 545 |
|
| 546 |
thumb_to_use = task.get("thumb_path")
|
| 547 |
created_temp_thumb = None
|
| 548 |
|
| 549 |
if not thumb_to_use and msg.video:
|
| 550 |
auto_thumb_path = os.path.join(user_down_dir, f"thumb_{msgid}.jpg")
|
| 551 |
-
created_temp_thumb = generate_auto_thumb(
|
| 552 |
thumb_to_use = created_temp_thumb
|
| 553 |
|
| 554 |
try:
|
| 555 |
if msg.photo:
|
| 556 |
-
await
|
| 557 |
-
target_chat,
|
| 558 |
-
message_thread_id=topic_id, parse_mode=enums.ParseMode.MARKDOWN
|
| 559 |
-
)
|
| 560 |
-
elif msg.video:
|
| 561 |
-
await client.send_video(
|
| 562 |
-
target_chat, upload_target_path, thumb=thumb_to_use, caption=final_caption,
|
| 563 |
-
message_thread_id=topic_id, parse_mode=enums.ParseMode.MARKDOWN,
|
| 564 |
-
duration=msg.video.duration or 0, width=msg.video.width or 0, height=msg.video.height or 0,
|
| 565 |
-
progress=progress_bar, progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, raw_name)
|
| 566 |
-
)
|
| 567 |
-
elif msg.audio:
|
| 568 |
-
await client.send_audio(
|
| 569 |
-
target_chat, upload_target_path, thumb=thumb_to_use, caption=final_caption,
|
| 570 |
-
message_thread_id=topic_id, parse_mode=enums.ParseMode.MARKDOWN,
|
| 571 |
-
progress=progress_bar, progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, raw_name)
|
| 572 |
)
|
| 573 |
else:
|
| 574 |
-
await
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
|
|
|
| 578 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
except Exception as e:
|
| 580 |
-
print(f"
|
| 581 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
finally:
|
| 583 |
if os.path.exists(file_path):
|
| 584 |
os.remove(file_path)
|
| 585 |
-
if processed_video and os.path.exists(processed_video):
|
| 586 |
-
os.remove(processed_video)
|
| 587 |
if created_temp_thumb and os.path.exists(created_temp_thumb):
|
| 588 |
os.remove(created_temp_thumb)
|
| 589 |
|
| 590 |
-
return True, size
|
|
|
|
| 6 |
import subprocess
|
| 7 |
from pyrogram import Client, filters, enums
|
| 8 |
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
|
| 9 |
+
from pyrogram.errors import (
|
| 10 |
+
FloodWait,
|
| 11 |
+
RPCError,
|
| 12 |
+
ChatAdminRequired,
|
| 13 |
+
RightForbidden,
|
| 14 |
+
TopicClosed
|
| 15 |
+
)
|
| 16 |
+
from pyrogram.raw.functions.channels import GetForumTopicsByID, CreateForumTopic
|
| 17 |
+
from config import API_ID, API_HASH, ADMINS, CHANNEL_ID, WAITING_TIME
|
| 18 |
from db import db
|
| 19 |
|
| 20 |
+
try:
|
| 21 |
+
from TechVJ.TechVJ.fast_download import fast_download_file, fast_upload_file
|
| 22 |
+
except ImportError:
|
| 23 |
+
try:
|
| 24 |
+
from TechVJ.fast_download import fast_download_file, fast_upload_file
|
| 25 |
+
except ImportError:
|
| 26 |
+
from fast_download import fast_download_file, fast_upload_file
|
| 27 |
+
|
| 28 |
class batch_temp(object):
|
| 29 |
IS_BATCH = {}
|
| 30 |
CLONE_DATA = {}
|
| 31 |
LAST_SAVED_ID = {}
|
| 32 |
+
CREATED_TOPICS = {}
|
|
|
|
| 33 |
|
| 34 |
def humanbytes(size):
|
| 35 |
if not size:
|
|
|
|
| 52 |
((str(seconds) + "s") if seconds else "")
|
| 53 |
return tmp if tmp else "0s"
|
| 54 |
|
| 55 |
+
async def progress_bar(current, total, ud_type, message, start, fname="", current_idx=1, total_msgs=1):
|
| 56 |
now = time.time()
|
| 57 |
+
diff = max(1e-3, now - start)
|
| 58 |
+
percentage = current * 100 / total if total > 0 else 0
|
| 59 |
+
speed = current / diff if diff > 0 else 0
|
| 60 |
+
elapsed_time = round(diff)
|
| 61 |
+
eta_file = round((total - current) / speed) if speed > 0 else 0
|
| 62 |
+
|
| 63 |
+
remaining_files = max(0, total_msgs - current_idx)
|
| 64 |
+
avg_file_size = total if total > 0 else 50 * 1024 * 1024
|
| 65 |
+
remaining_batch_bytes = (total - current) + (remaining_files * avg_file_size)
|
| 66 |
+
eta_batch = round(remaining_batch_bytes / speed) if speed > 0 else 0
|
| 67 |
+
|
| 68 |
+
bar_length = 10
|
| 69 |
+
filled_length = int(bar_length * current // total) if total > 0 else 0
|
| 70 |
+
bar = '▰' * filled_length + '▱' * (bar_length - filled_length)
|
| 71 |
+
|
| 72 |
+
fname_clean = fname.split('_', 1)[-1] if '_' in fname else fname
|
| 73 |
+
fname_text = f"📁 **File:** `{fname_clean[:28]}...`\n" if fname_clean else ""
|
| 74 |
+
|
| 75 |
+
status_text = (
|
| 76 |
+
f"**{ud_type}** ({current_idx}/{total_msgs})\n"
|
| 77 |
+
f"{fname_text}"
|
| 78 |
+
f"[{bar}] {percentage:.1f}%\n"
|
| 79 |
+
f"⚡ **Speed:** {humanbytes(speed)}/s\n"
|
| 80 |
+
f"📦 **Done:** {humanbytes(current)} / {humanbytes(total)}\n"
|
| 81 |
+
f"⏱️ **File ETA:** {time_formatter(eta_file)} | **Time:** {time_formatter(elapsed_time)}\n"
|
| 82 |
+
f"⏳ **Batch Total ETA:** {time_formatter(eta_batch)} (बाकी {remaining_files} संदेश)"
|
| 83 |
+
)
|
| 84 |
+
try:
|
| 85 |
+
await message.edit_text(status_text)
|
| 86 |
+
except Exception:
|
| 87 |
+
pass
|
| 88 |
+
|
| 89 |
+
def get_system_font():
|
| 90 |
+
# लिनक्स और डॉकर वातावरण में मौजूद फ़ॉन्ट्स की जाँच
|
| 91 |
+
fonts = [
|
| 92 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
|
| 93 |
+
"/usr/share/fonts/truetype/freefont/FreeSansBold.ttf",
|
| 94 |
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf"
|
| 95 |
+
]
|
| 96 |
+
for f in fonts:
|
| 97 |
+
if os.path.exists(f):
|
| 98 |
+
return f
|
| 99 |
+
return None
|
| 100 |
+
|
| 101 |
+
def apply_video_watermark(input_path: str, output_path: str, text: str):
|
| 102 |
+
clean_text = text.upper().strip()
|
| 103 |
+
font_file = get_system_font()
|
| 104 |
+
font_arg = f":fontfile='{font_file}'" if font_file else ""
|
| 105 |
+
|
| 106 |
+
# 5-रंगों का चक्रीय रोटेशन (Red, Purple, Pink, White, Gold)
|
| 107 |
+
color_expr = (
|
| 108 |
+
"if(lt(mod(t\,25)\,5)\,0xff3333\,"
|
| 109 |
+
"if(lt(mod(t\,25)\,10)\,0xbf00ff\,"
|
| 110 |
+
"if(lt(mod(t\,25)\,15)\,0xff66cc\,"
|
| 111 |
+
"if(lt(mod(t\,25)\,20)\,0xffffff\,0xffd700))))"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# दाईं से बाईं ओर स्क्रोलिंग (100 पिक्सल प्रति सेकंड)
|
| 115 |
+
draw_filter = (
|
| 116 |
+
f"drawtext=text='{clean_text}'{font_arg}:"
|
| 117 |
+
f"x=w-mod(t*100\\,w+tw):y=h-th-30:"
|
| 118 |
+
f"fontsize=32:fontcolor_expr={color_expr}:"
|
| 119 |
+
f"box=1:boxcolor=black@0.4:boxborderw=8:shadowcolor=black@0.8:shadowx=2:shadowy=2"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
cmd = [
|
| 123 |
+
"ffmpeg", "-i", input_path,
|
| 124 |
+
"-vf", draw_filter,
|
| 125 |
+
"-c:v", "libx264", "-preset", "ultrafast", "-crf", "23",
|
| 126 |
+
"-c:a", "copy",
|
| 127 |
+
output_path, "-y"
|
| 128 |
+
]
|
| 129 |
+
try:
|
| 130 |
+
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 131 |
+
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
|
| 132 |
+
return output_path
|
| 133 |
+
else:
|
| 134 |
+
print(f"FFmpeg stderr: {res.stderr.decode('utf-8', errors='ignore')[-500:]}")
|
| 135 |
+
except Exception as e:
|
| 136 |
+
print(f"Watermark execution error: {e}")
|
| 137 |
+
return input_path
|
| 138 |
|
| 139 |
def generate_auto_thumb(video_path: str, thumb_path: str):
|
| 140 |
try:
|
|
|
|
| 149 |
pass
|
| 150 |
return None
|
| 151 |
|
| 152 |
+
@Client.on_message(filters.command("id"))
|
| 153 |
+
async def get_id(client: Client, message: Message):
|
| 154 |
+
chat_id = message.chat.id
|
| 155 |
+
user_id = message.from_user.id if message.from_user else (message.sender_chat.id if message.sender_chat else "Unknown")
|
| 156 |
+
thread_id = getattr(message, "message_thread_id", None)
|
| 157 |
+
|
| 158 |
+
response = f"📍 **चैट/ग्रुप ID:** `{chat_id}`\n👤 **आपकी ID:** `{user_id}`"
|
| 159 |
+
if thread_id:
|
| 160 |
+
response += f"\n🧵 **टॉपिक/थ्रेड ID:** `{thread_id}`"
|
| 161 |
+
|
| 162 |
+
if message.reply_to_message:
|
| 163 |
+
rep = message.reply_to_message
|
| 164 |
+
rep_user = rep.from_user.id if rep.from_user else (rep.sender_chat.id if rep.sender_chat else "Anonymous")
|
| 165 |
+
response += f"\n\n↩️ **रिप्लाई यूजर ID:** `{rep_user}`"
|
| 166 |
+
if rep.forward_from_chat:
|
| 167 |
+
response += f"\n📢 **फॉरवर्ड चैट ID:** `{rep.forward_from_chat.id}`"
|
| 168 |
+
await message.reply_text(response)
|
| 169 |
+
|
| 170 |
+
@Client.on_message(filters.command(["cancel"]))
|
| 171 |
+
async def send_cancel(client: Client, message: Message):
|
| 172 |
+
user_id = message.from_user.id
|
| 173 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 174 |
+
await message.reply_text("🛑 **टास्क तुरंत रोक दिया गया है।** यदि इसे वापस वहीं से चलाना हो तो `/resume` भेजें।")
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
def parse_telegram_link(link: str):
|
| 177 |
+
link = link.strip().replace("?single", "").rstrip("/")
|
| 178 |
+
c_match = re.search(r"t\.me/c/(\d+)(.*)", link)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
if c_match:
|
| 180 |
+
chat_id = int("-100" + c_match.group(1))
|
| 181 |
+
parts = [int(p) for p in c_match.group(2).split("/") if p.isdigit()]
|
| 182 |
+
if len(parts) >= 2:
|
| 183 |
+
return chat_id, parts[1], parts[0]
|
| 184 |
+
elif len(parts) == 1:
|
| 185 |
+
return chat_id, parts[0], None
|
| 186 |
|
| 187 |
b_match = re.search(r"t\.me/b/([^/]+)/(\d+)", link)
|
| 188 |
if b_match:
|
| 189 |
return b_match.group(1), int(b_match.group(2)), None
|
| 190 |
|
| 191 |
+
p_match = re.search(r"t\.me/([^/]+)(.*)", link)
|
| 192 |
if p_match:
|
| 193 |
+
uname = p_match.group(1)
|
| 194 |
+
if uname not in ["c", "b"]:
|
| 195 |
+
parts = [int(p) for p in p_match.group(2).split("/") if p.isdigit()]
|
| 196 |
+
if len(parts) >= 2:
|
| 197 |
+
return uname, parts[1], parts[0]
|
| 198 |
+
elif len(parts) == 1:
|
| 199 |
+
return uname, parts[0], None
|
| 200 |
|
| 201 |
return None, None, None
|
| 202 |
|
| 203 |
+
async def get_or_create_target_topic(sender_client: Client, acc: Client, target_chat, topic_title: str):
|
| 204 |
+
if not topic_title:
|
| 205 |
+
return None
|
| 206 |
+
|
| 207 |
+
str_target = str(target_chat)
|
| 208 |
+
if str_target not in batch_temp.CREATED_TOPICS:
|
| 209 |
+
batch_temp.CREATED_TOPICS[str_target] = {}
|
| 210 |
+
|
| 211 |
+
if topic_title in batch_temp.CREATED_TOPICS[str_target]:
|
| 212 |
+
return batch_temp.CREATED_TOPICS[str_target][topic_title]
|
| 213 |
+
|
| 214 |
+
try:
|
| 215 |
+
new_topic = await sender_client.create_forum_topic(chat_id=target_chat, title=topic_title[:120])
|
| 216 |
+
batch_temp.CREATED_TOPICS[str_target][topic_title] = new_topic.id
|
| 217 |
+
return new_topic.id
|
| 218 |
+
except Exception:
|
| 219 |
+
try:
|
| 220 |
+
new_topic = await acc.create_forum_topic(chat_id=target_chat, title=topic_title[:120])
|
| 221 |
+
batch_temp.CREATED_TOPICS[str_target][topic_title] = new_topic.id
|
| 222 |
+
return new_topic.id
|
| 223 |
+
except Exception:
|
| 224 |
+
return None
|
| 225 |
+
|
| 226 |
+
async def get_source_topic_title(acc: Client, source_chat, topic_id: int) -> str:
|
| 227 |
+
if not topic_id:
|
| 228 |
+
return ""
|
| 229 |
+
try:
|
| 230 |
+
peer = await acc.resolve_peer(source_chat)
|
| 231 |
+
res = await acc.invoke(GetForumTopicsByID(channel=peer, topics=[int(topic_id)]))
|
| 232 |
+
if res and res.topics:
|
| 233 |
+
return res.topics[0].title
|
| 234 |
+
except Exception:
|
| 235 |
+
pass
|
| 236 |
+
return f"Topic {topic_id}"
|
| 237 |
|
| 238 |
@Client.on_message(filters.command(["resume"]) & filters.private)
|
| 239 |
async def resume_command(client: Client, message: Message):
|
| 240 |
user_id = message.from_user.id
|
| 241 |
+
if not db.is_user_vip(user_id, ADMINS):
|
| 242 |
+
return await message.reply_text("🔒 आपका VIP एक्सेस समाप्त हो चुका है।")
|
| 243 |
+
|
| 244 |
task = batch_temp.CLONE_DATA.get(user_id)
|
| 245 |
last_id = batch_temp.LAST_SAVED_ID.get(user_id)
|
| 246 |
if not task or not last_id:
|
| 247 |
+
return await message.reply_text("⚠️ कोई रुका हुआ पिछला टास्क नहीं मिला।")
|
| 248 |
|
| 249 |
if last_id >= task["end_id"]:
|
| 250 |
return await message.reply_text("✅ पिछला टास्क पहले ही पूरा हो चुका था।")
|
| 251 |
|
| 252 |
task["start_id"] = last_id + 1
|
| 253 |
await message.reply_text(f"🔄 **टास्क रिज्यूम किया जा रहा है...** (ID `{task['start_id']}` से `{task['end_id']}` तक)")
|
| 254 |
+
await start_clone_task(client, user_id)
|
|
|
|
| 255 |
|
| 256 |
+
@Client.on_message(filters.command(["clone", "clon"]) & filters.private)
|
|
|
|
| 257 |
async def clone_command(client: Client, message: Message):
|
| 258 |
+
await init_clone_workflow(client, message, is_topic_mode=False)
|
| 259 |
|
| 260 |
+
@Client.on_message(filters.command(["topicclone", "forumclone"]) & filters.private)
|
| 261 |
+
async def topicclone_command(client: Client, message: Message):
|
| 262 |
+
await init_clone_workflow(client, message, is_topic_mode=True)
|
|
|
|
| 263 |
|
| 264 |
+
async def init_clone_workflow(client: Client, message: Message, is_topic_mode: bool):
|
| 265 |
user_id = message.from_user.id
|
| 266 |
if not db.is_user_vip(user_id, ADMINS):
|
| 267 |
+
return await message.reply_text(
|
| 268 |
+
"🔒 **यह फीचर केवल एक्टिव VIP मेंबर्स के लिए है!**\n\nप्लान देखने के लिए /plans और पेमेंट के लिए /pay भेजें।"
|
| 269 |
+
)
|
| 270 |
+
if batch_temp.IS_BATCH.get(user_id) == False:
|
| 271 |
+
return await message.reply_text("⚠️ आपका एक टास्क पहले से चल रहा है। इंतज़ार करें या `/cancel` करें।")
|
| 272 |
|
| 273 |
user_session = db.get_session(user_id)
|
| 274 |
if not user_session:
|
| 275 |
return await message.reply_text("🔑 पहले **/login** करें।")
|
| 276 |
|
| 277 |
+
if is_topic_mode:
|
| 278 |
+
guide_text = (
|
| 279 |
+
"🔥 **ग्रुप टॉपिक क्लोनर (Forum Topics Clone):**\n"
|
| 280 |
+
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 281 |
+
"👉 **स्टेप 1:** टॉपिक वाले ग्रुप की **पहली लिंक (Start Link)** भेजें:\n\n"
|
| 282 |
+
"(रद्द करने के लिए /cancel लिखें)"
|
| 283 |
+
)
|
| 284 |
+
else:
|
| 285 |
+
guide_text = (
|
| 286 |
+
"📖 **सामान्य कंटेंट क्लोनिंग:**\n"
|
| 287 |
+
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 288 |
+
"👉 **स्टेप 1:** जहाँ से कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें:\n\n"
|
| 289 |
+
"(रद्द करने के लिए /cancel लिखें)"
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
first_msg = await client.ask(user_id, guide_text, filters=filters.text, timeout=300)
|
| 293 |
if first_msg.text == "/cancel":
|
| 294 |
return await first_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
|
| 295 |
|
| 296 |
+
start_link = first_msg.text.strip()
|
| 297 |
+
s_chat, s_id, s_topic = parse_telegram_link(start_link)
|
| 298 |
if not s_id:
|
| 299 |
+
return await first_msg.reply("❌ अमान्य टेलीग्राम लिंक! दोबारा कमांड दें।")
|
| 300 |
|
| 301 |
+
if is_topic_mode:
|
| 302 |
+
step2_text = (
|
| 303 |
+
"👉 **स्टेप 2:** अब **अंतिम लिंक (End Link)** भेजें:\n"
|
| 304 |
+
"(केवल 1 फ़ाइल के लिए `/single` लिखें)\n\n"
|
| 305 |
+
"💡 *टिप: आप पहले से आख़िरी टॉपिक तक की पूरी रेंज दे सकते हैं।*"
|
| 306 |
+
)
|
| 307 |
+
else:
|
| 308 |
+
step2_text = (
|
| 309 |
+
"👉 **स्टेप 2:** अब **अंतिम लिंक (End Link)** भेजें:\n"
|
| 310 |
+
"(केवल 1 फ़ाइल के लिए `/single` लिखें)"
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
last_msg = await client.ask(user_id, step2_text, filters=filters.text, timeout=300)
|
| 314 |
if last_msg.text == "/cancel":
|
| 315 |
return await last_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
|
| 316 |
|
| 317 |
+
if last_msg.text.strip().lower() == "/single":
|
| 318 |
+
e_chat, e_id, e_topic = s_chat, s_id, s_topic
|
| 319 |
else:
|
| 320 |
+
end_link = last_msg.text.strip()
|
| 321 |
+
e_chat, e_id, e_topic = parse_telegram_link(end_link)
|
| 322 |
if not e_id:
|
| 323 |
+
return await last_msg.reply("❌ अमान्य अंतिम लिंक! दोबारा कमांड दें।")
|
| 324 |
+
|
| 325 |
+
if is_topic_mode:
|
| 326 |
+
dest_prompt = (
|
| 327 |
+
"👉 **स्टेप 3:** अपना टारगेट **ग्रुप (Group ID)** भेजें:\n"
|
| 328 |
+
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 329 |
+
"⚠️ **ज़रूरी नियम:** टॉपिक कंटेंट चैनल में नहीं जा सकता, इसके लिए ग्रुप चाहिए!\n"
|
| 330 |
+
"1. ग्रुप में **Topics/Forums** ऑन रखें।\n"
|
| 331 |
+
"2. बॉट और अकाउंट को **'Manage Topics'** एडमिन परमिशन दें।\n\n"
|
| 332 |
+
"ग्रुप ID भेजें (उदा: `-1001234567890`) या सीधे बॉट में पाने के लिए `/skip` लिखें:"
|
| 333 |
+
)
|
| 334 |
+
else:
|
| 335 |
+
dest_prompt = (
|
| 336 |
+
"👉 **स्टेप 3:** जहाँ अपलोड करवाना है, उस **चैनल/ग्रुप की ID या लिंक** भेजें:\n"
|
| 337 |
+
"(सीधे इसी बॉट चैट में पाने के लिए `/skip` लिखें)"
|
| 338 |
+
)
|
| 339 |
|
|
|
|
| 340 |
dest_msg = await client.ask(user_id, dest_prompt, filters=filters.text, timeout=300)
|
| 341 |
if dest_msg.text == "/cancel":
|
| 342 |
return await dest_msg.reply("❌ प्रोसेस रद्द कर दिया गया।")
|
| 343 |
|
| 344 |
dest_val = dest_msg.text.strip()
|
| 345 |
+
is_direct_bot = False
|
| 346 |
+
|
| 347 |
+
if dest_val.lower() == "/skip":
|
| 348 |
target_chat = user_id
|
| 349 |
+
is_direct_bot = True
|
| 350 |
else:
|
| 351 |
try:
|
| 352 |
target_chat = int(dest_val)
|
| 353 |
except ValueError:
|
| 354 |
target_chat = dest_val.replace("https://t.me/", "@")
|
| 355 |
|
| 356 |
+
start_num = min(s_id, e_id)
|
| 357 |
+
end_num = max(s_id, e_id)
|
| 358 |
+
|
| 359 |
batch_temp.CLONE_DATA[user_id] = {
|
| 360 |
"source_chat": s_chat,
|
| 361 |
+
"start_id": start_num,
|
| 362 |
+
"end_id": end_num,
|
|
|
|
| 363 |
"target_chat": target_chat,
|
| 364 |
+
"is_direct_bot": is_direct_bot,
|
| 365 |
+
"is_topic_mode": is_topic_mode,
|
| 366 |
"custom_caption": None,
|
| 367 |
"extra_caption": None,
|
| 368 |
"replace_find": None,
|
|
|
|
| 374 |
|
| 375 |
async def show_customization_menu(client: Client, user_id: int):
|
| 376 |
data = batch_temp.CLONE_DATA.get(user_id, {})
|
| 377 |
+
cap_status = "सेट है ✅" if data.get("custom_caption") else "मूल (Original) सुरक्षित"
|
| 378 |
ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
|
| 379 |
+
thm_status = "सेट है ✅" if data.get("thumb_path") else "मूल (Default)"
|
|
|
|
| 380 |
rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
|
| 381 |
+
wm_status = f"`{data.get('watermark_text')}` (5-कलर स्क्रोलिंग) ✅" if data.get("watermark_text") else "कोई नहीं"
|
| 382 |
+
dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
|
| 383 |
+
mode_display = "🔥 ऑटो-टॉपिक मोड" if data.get("is_topic_mode") else "🚀 डायरेक्ट मोड"
|
| 384 |
+
total_count = data.get('end_id', 0) - data.get('start_id', 0) + 1
|
| 385 |
|
| 386 |
panel_text = (
|
| 387 |
"⚙️ **कंटेंट कस्टमाइज़ेशन सेटिंग्स:**\n"
|
| 388 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 389 |
+
f"🎯 ट्रांसमिशन मोड: `{mode_display}`\n"
|
| 390 |
+
f"📝 कैप्शन: `{cap_status}`\n"
|
| 391 |
+
f"🔄 रिप्लेस टेक्स्ट: {rep_status}\n"
|
| 392 |
f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
|
| 393 |
f"🖼️ कस्टम थंबनेल: `{thm_status}`\n"
|
| 394 |
+
f"🏷️ रनिंग वीडियो वॉटरमार्क: {wm_status}\n"
|
| 395 |
+
f"📍 टारगेट डेस्टिनेशन: {dest_display}\n"
|
| 396 |
+
f"📊 कुल ���ंदेश रेंज: `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_count} फाइल्स)\n"
|
| 397 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 398 |
+
"नीचे से मनपसंद सेटिंग बदलें या तुरंत **🚀 Confirm & Start** दबाएँ:"
|
| 399 |
)
|
| 400 |
buttons = InlineKeyboardMarkup([
|
| 401 |
+
[InlineKeyboardButton("📝 Edit Caption", callback_data="set_caption"),
|
| 402 |
+
InlineKeyboardButton("🔄 Replace Text", callback_data="set_replace")],
|
| 403 |
+
[InlineKeyboardButton("➕ Add Extra", callback_data="set_extra"),
|
| 404 |
+
InlineKeyboardButton("🖼️ Set Thumbnail", callback_data="set_thumb")],
|
| 405 |
+
[InlineKeyboardButton("🏷️ Set Video Watermark", callback_data="set_wm"),
|
| 406 |
+
InlineKeyboardButton("🗑️ Clear Settings", callback_data="clear_settings")],
|
| 407 |
[InlineKeyboardButton("🚀 Confirm & Start", callback_data="confirm_start")]
|
| 408 |
])
|
| 409 |
await client.send_message(user_id, panel_text, reply_markup=buttons)
|
|
|
|
| 411 |
@Client.on_callback_query()
|
| 412 |
async def callback_handler(client: Client, query: CallbackQuery):
|
| 413 |
user_id = query.from_user.id
|
| 414 |
+
if query.data.startswith("nav_") or query.data.startswith("bc_") or query.data.startswith("setlang_"):
|
| 415 |
+
return
|
| 416 |
+
|
| 417 |
if user_id not in batch_temp.CLONE_DATA:
|
| 418 |
+
return await query.answer("⚠️ सेशन एक्सपायर हो गया, दोबारा कमांड दें।", show_alert=True)
|
| 419 |
|
| 420 |
data = query.data
|
| 421 |
if data == "set_caption":
|
|
|
|
| 425 |
await show_customization_menu(client, user_id)
|
| 426 |
elif data == "set_replace":
|
| 427 |
await query.message.delete()
|
| 428 |
+
find_msg = await client.ask(user_id, "🔍 क्या खोजना/हटाना चाहते हैं? वह शब्द भेजें:", filters=filters.text, timeout=180)
|
| 429 |
if find_msg.text == "/cancel":
|
| 430 |
return await show_customization_menu(client, user_id)
|
| 431 |
+
with_msg = await client.ask(user_id, f"✏️ `{find_msg.text}` की जगह क्या लगाना चाहते हैं? (खाली रखने के लिए `/empty`):", filters=filters.text, timeout=180)
|
| 432 |
+
if with_msg.text == "/cancel":
|
| 433 |
+
return await show_customization_menu(client, user_id)
|
| 434 |
batch_temp.CLONE_DATA[user_id]["replace_find"] = find_msg.text
|
| 435 |
batch_temp.CLONE_DATA[user_id]["replace_with"] = "" if with_msg.text.strip() == "/empty" else with_msg.text.markdown
|
| 436 |
await show_customization_menu(client, user_id)
|
|
|
|
| 447 |
thumb_file = os.path.join(user_thumb_dir, "thumb.jpg")
|
| 448 |
await client.download_media(msg.photo, file_name=thumb_file)
|
| 449 |
batch_temp.CLONE_DATA[user_id]["thumb_path"] = thumb_file
|
| 450 |
+
await msg.reply_text("✅ थंबनेल सेव कर लिया गया!")
|
| 451 |
await show_customization_menu(client, user_id)
|
| 452 |
elif data == "set_wm":
|
| 453 |
await query.message.delete()
|
| 454 |
+
msg = await client.ask(
|
| 455 |
+
user_id,
|
| 456 |
+
"🏷️ **वीडियो रनिंग वॉटरमार्क के लिए नाम भेजें:**\n(उदा: `SACHIN SHARMA`)",
|
| 457 |
+
filters=filters.text,
|
| 458 |
+
timeout=180
|
| 459 |
+
)
|
| 460 |
if msg.text != "/cancel":
|
| 461 |
+
batch_temp.CLONE_DATA[user_id]["watermark_text"] = msg.text.strip().upper()
|
| 462 |
await show_customization_menu(client, user_id)
|
| 463 |
elif data == "clear_settings":
|
| 464 |
batch_temp.CLONE_DATA[user_id]["custom_caption"] = None
|
|
|
|
| 475 |
await show_customization_menu(client, user_id)
|
| 476 |
elif data == "confirm_start":
|
| 477 |
await query.message.delete()
|
| 478 |
+
await start_clone_task(client, user_id)
|
|
|
|
| 479 |
|
| 480 |
async def start_clone_task(client: Client, user_id: int):
|
| 481 |
task = batch_temp.CLONE_DATA.get(user_id)
|
|
|
|
| 486 |
start_id = task["start_id"]
|
| 487 |
end_id = task["end_id"]
|
| 488 |
target_chat = task["target_chat"]
|
| 489 |
+
is_direct_bot = task.get("is_direct_bot", False)
|
| 490 |
+
is_topic_mode = task.get("is_topic_mode", False)
|
| 491 |
|
| 492 |
user_session = db.get_session(user_id)
|
| 493 |
user_api_id = int(db.get_api_id(user_id) or API_ID)
|
| 494 |
user_api_hash = db.get_api_hash(user_id) or API_HASH
|
| 495 |
|
|
|
|
| 496 |
acc = Client(
|
| 497 |
+
f"user_session_{user_id}",
|
| 498 |
session_string=user_session,
|
| 499 |
api_hash=user_api_hash,
|
| 500 |
api_id=user_api_id,
|
| 501 |
in_memory=True,
|
| 502 |
+
workers=64,
|
| 503 |
+
max_concurrent_transmissions=32
|
| 504 |
)
|
| 505 |
try:
|
| 506 |
await acc.start()
|
|
|
|
| 513 |
except Exception:
|
| 514 |
pass
|
| 515 |
|
| 516 |
+
if not is_direct_bot and is_topic_mode:
|
|
|
|
|
|
|
| 517 |
try:
|
| 518 |
+
target_chat_info = await acc.get_chat(target_chat)
|
| 519 |
+
if target_chat_info.type == enums.ChatType.CHANNEL:
|
| 520 |
+
await acc.stop()
|
| 521 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 522 |
+
return await client.send_message(
|
| 523 |
+
user_id,
|
| 524 |
+
"❌ **अमान्य टारगेट (चैनल सपोर्टेड नहीं)!**\nटॉपिक कंटेंट चैनल में नहीं जा सकता।"
|
| 525 |
+
)
|
| 526 |
+
if not getattr(target_chat_info, "is_forum", False):
|
| 527 |
+
await acc.stop()
|
| 528 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 529 |
+
return await client.send_message(
|
| 530 |
+
user_id,
|
| 531 |
+
"❌ **ग्रुप में Topics (फोरम) बंद हैं!** ग्रुप सेटिंग्स में Topics ऑन करें।"
|
| 532 |
+
)
|
| 533 |
+
except Exception:
|
| 534 |
+
pass
|
| 535 |
|
| 536 |
batch_temp.IS_BATCH[user_id] = False
|
| 537 |
success = 0
|
|
|
|
| 539 |
retrying = 0
|
| 540 |
total_bytes = 0
|
| 541 |
start_time = time.time()
|
| 542 |
+
total_msgs = (end_id - start_id + 1)
|
| 543 |
|
| 544 |
status_msg = await client.send_message(user_id, "🚀 **कंटेंट ट्रांसफर शुरू हो रहा है...**")
|
| 545 |
+
source_topics_cache = {}
|
| 546 |
|
| 547 |
try:
|
| 548 |
+
for idx, msgid in enumerate(range(start_id, end_id + 1), start=1):
|
| 549 |
+
if batch_temp.IS_BATCH.get(user_id):
|
| 550 |
+
await status_msg.edit_text("🛑 **टास्क सफलतापूर्वक रोक दिया गया है।**")
|
|
|
|
| 551 |
break
|
| 552 |
|
| 553 |
+
# लाइव वीआईपी चेक (रिमूव करते ही टास्क तुरंत टर्मिनेट)
|
| 554 |
+
if not db.is_user_vip(user_id, ADMINS):
|
| 555 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 556 |
+
await status_msg.edit_text("🚫 **आपका VIP एक्सेस समाप्त या हटा दिया गया है। टास्क तुरंत रोक दिया गया।**")
|
| 557 |
break
|
| 558 |
|
| 559 |
attempts = 0
|
| 560 |
+
while attempts < 5:
|
| 561 |
+
if batch_temp.IS_BATCH.get(user_id):
|
| 562 |
+
break
|
| 563 |
+
if not db.is_user_vip(user_id, ADMINS):
|
| 564 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 565 |
+
break
|
| 566 |
+
|
| 567 |
try:
|
| 568 |
+
ok, sz, err_msg = await process_media(
|
| 569 |
+
client, acc, user_id, source_chat, msgid, target_chat,
|
| 570 |
+
is_topic_mode, source_topics_cache, task, status_msg, idx, total_msgs
|
| 571 |
+
)
|
| 572 |
if ok:
|
| 573 |
success += 1
|
| 574 |
total_bytes += sz
|
| 575 |
batch_temp.LAST_SAVED_ID[user_id] = msgid
|
| 576 |
else:
|
| 577 |
+
if err_msg:
|
| 578 |
+
await client.send_message(user_id, err_msg)
|
| 579 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 580 |
+
break
|
| 581 |
not_found += 1
|
| 582 |
break
|
| 583 |
except FloodWait as fw:
|
| 584 |
await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
|
| 585 |
+
await asyncio.sleep(fw.value + 2)
|
| 586 |
attempts += 1
|
| 587 |
+
except RPCError:
|
| 588 |
await asyncio.sleep(2)
|
| 589 |
attempts += 1
|
| 590 |
except Exception:
|
| 591 |
retrying += 1
|
| 592 |
break
|
| 593 |
|
| 594 |
+
if batch_temp.IS_BATCH.get(user_id):
|
| 595 |
+
break
|
| 596 |
+
|
| 597 |
await asyncio.sleep(WAITING_TIME)
|
| 598 |
+
|
| 599 |
finally:
|
| 600 |
try:
|
| 601 |
await acc.stop()
|
| 602 |
except Exception:
|
| 603 |
pass
|
|
|
|
|
|
|
| 604 |
|
| 605 |
+
batch_temp.IS_BATCH[user_id] = True
|
| 606 |
tpath = task.get("thumb_path")
|
| 607 |
if tpath and os.path.exists(tpath):
|
| 608 |
os.remove(tpath)
|
|
|
|
| 618 |
f"🔁 Retrying: {retrying}\n"
|
| 619 |
f"📦 Total Size: {humanbytes(total_bytes)}\n"
|
| 620 |
f"⚡ Avg Speed: {avg_speed}\n"
|
| 621 |
+
f"⏱️ Total Time: {time_formatter(elapsed_time)}\n"
|
| 622 |
"━━━━━━━━━━━━━━━━━━━━"
|
| 623 |
)
|
| 624 |
+
try:
|
| 625 |
+
await status_msg.edit_text(summary_card)
|
| 626 |
+
except Exception:
|
| 627 |
+
pass
|
| 628 |
|
| 629 |
def get_file_name_from_msg(msg: Message) -> str:
|
| 630 |
name = None
|
|
|
|
| 633 |
elif msg.video and msg.video.file_name:
|
| 634 |
name = msg.video.file_name
|
| 635 |
elif msg.video:
|
| 636 |
+
name = f"video_{msg.id}.mp4"
|
| 637 |
elif msg.audio and msg.audio.file_name:
|
| 638 |
name = msg.audio.file_name
|
| 639 |
elif msg.audio:
|
| 640 |
+
name = f"audio_{msg.id}.mp3"
|
| 641 |
elif msg.photo:
|
| 642 |
+
name = f"photo_{msg.id}.jpg"
|
| 643 |
else:
|
| 644 |
+
name = f"file_{msg.id}.bin"
|
| 645 |
+
|
| 646 |
+
# मैसेज ID हटाकर साफ़ नाम रखना
|
| 647 |
+
clean_name = re.sub(r"^\d+_", "", name)
|
| 648 |
+
return clean_name if clean_name else name
|
| 649 |
+
|
| 650 |
+
async def process_media(
|
| 651 |
+
client: Client, acc: Client, user_id: int, source_chat, msgid: int,
|
| 652 |
+
target_chat, is_topic_mode: bool, source_topics_cache: dict, task: dict,
|
| 653 |
+
status_msg: Message, current_idx: int, total_msgs: int
|
| 654 |
+
):
|
| 655 |
+
if batch_temp.IS_BATCH.get(user_id):
|
| 656 |
+
return False, 0, None
|
| 657 |
|
|
|
|
| 658 |
msg = None
|
| 659 |
try:
|
| 660 |
msg = await acc.get_messages(source_chat, msgid)
|
|
|
|
| 662 |
try:
|
| 663 |
msg = await client.get_messages(source_chat, msgid)
|
| 664 |
except Exception:
|
| 665 |
+
return False, 0, None
|
| 666 |
+
|
| 667 |
+
if not msg or msg.empty or msg.service:
|
| 668 |
+
return False, 0, None
|
| 669 |
+
|
| 670 |
+
target_thread_id = None
|
| 671 |
+
is_direct_bot = task.get("is_direct_bot", False)
|
| 672 |
+
sender_client = client if is_direct_bot else acc
|
| 673 |
+
|
| 674 |
+
if not is_direct_bot and is_topic_mode:
|
| 675 |
+
src_thread = getattr(msg, "message_thread_id", None) or getattr(msg, "reply_to_top_message_id", None)
|
| 676 |
+
if src_thread:
|
| 677 |
+
if src_thread not in source_topics_cache:
|
| 678 |
+
title = await get_source_topic_title(acc, source_chat, src_thread)
|
| 679 |
+
source_topics_cache[src_thread] = title
|
| 680 |
+
topic_title = source_topics_cache.get(src_thread, f"Topic {src_thread}")
|
| 681 |
+
|
| 682 |
+
try:
|
| 683 |
+
target_thread_id = await get_or_create_target_topic(sender_client, acc, target_chat, topic_title)
|
| 684 |
+
except (ChatAdminRequired, RightForbidden):
|
| 685 |
+
return False, 0, "❌ **एडमिन एरर:** टारगेट ग्रुप में **'Manage Topics'** परमिशन नहीं है।"
|
| 686 |
+
except Exception:
|
| 687 |
+
pass
|
| 688 |
+
|
| 689 |
+
topic_kwargs = {"message_thread_id": target_thread_id} if target_thread_id else {}
|
| 690 |
+
|
| 691 |
+
# मूल कैप्शन सुरक्षित रखना
|
| 692 |
final_caption = msg.caption.markdown if msg.caption else ""
|
|
|
|
| 693 |
if task.get("custom_caption"):
|
| 694 |
final_caption = task["custom_caption"]
|
| 695 |
elif task.get("replace_find"):
|
|
|
|
| 699 |
final_caption = final_caption.replace(find_w, with_w)
|
| 700 |
|
| 701 |
if task.get("extra_caption"):
|
| 702 |
+
if final_caption:
|
| 703 |
+
final_caption = f"{final_caption}\n\n{task['extra_caption']}"
|
| 704 |
+
else:
|
| 705 |
+
final_caption = task["extra_caption"]
|
| 706 |
|
| 707 |
if msg.text:
|
| 708 |
text_to_send = msg.text.markdown
|
| 709 |
if task.get("custom_caption"):
|
| 710 |
text_to_send = task["custom_caption"]
|
| 711 |
elif task.get("replace_find"):
|
| 712 |
+
find_w = task["replace_find"]
|
| 713 |
+
with_w = task.get("replace_with") or ""
|
| 714 |
+
text_to_send = text_to_send.replace(find_w, with_w)
|
| 715 |
if task.get("extra_caption"):
|
| 716 |
text_to_send += f"\n\n{task['extra_caption']}"
|
| 717 |
+
try:
|
| 718 |
+
await sender_client.send_message(target_chat, text_to_send, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
|
| 719 |
+
return True, len(text_to_send.encode('utf-8')), None
|
| 720 |
+
except Exception:
|
| 721 |
+
return False, 0, None
|
| 722 |
|
| 723 |
+
file_name = get_file_name_from_msg(msg)
|
| 724 |
user_down_dir = os.path.join("downloads", str(user_id))
|
| 725 |
os.makedirs(user_down_dir, exist_ok=True)
|
| 726 |
+
down_path = os.path.join(user_down_dir, file_name)
|
| 727 |
|
| 728 |
down_start = time.time()
|
| 729 |
+
await status_msg.edit_text(f"📥 **Downloading:** `{file_name}`\n⏳ (फाइल {current_idx} / {total_msgs})...")
|
| 730 |
|
| 731 |
+
if msg.photo:
|
| 732 |
+
file_path = await acc.download_media(msg, file_name=down_path)
|
| 733 |
+
else:
|
| 734 |
+
try:
|
| 735 |
+
file_path = await fast_download_file(
|
| 736 |
+
acc,
|
| 737 |
+
msg,
|
| 738 |
+
out_path=down_path,
|
| 739 |
+
progress_func=progress_bar,
|
| 740 |
+
progress_args=("📥 Downloading", status_msg, down_start, file_name, current_idx, total_msgs)
|
| 741 |
+
)
|
| 742 |
+
except Exception:
|
| 743 |
+
file_path = await acc.download_media(
|
| 744 |
+
msg,
|
| 745 |
+
file_name=down_path,
|
| 746 |
+
progress=progress_bar,
|
| 747 |
+
progress_args=("📥 Downloading", status_msg, down_start, file_name, current_idx, total_msgs)
|
| 748 |
+
)
|
| 749 |
+
|
| 750 |
+
if batch_temp.IS_BATCH.get(user_id):
|
| 751 |
+
if file_path and os.path.exists(file_path):
|
| 752 |
+
os.remove(file_path)
|
| 753 |
+
return False, 0, None
|
| 754 |
|
| 755 |
if not file_path or not os.path.exists(file_path):
|
| 756 |
+
return False, 0, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 757 |
|
| 758 |
+
# रनिंग वॉटरमार्क
|
| 759 |
+
wm_text = task.get("watermark_text")
|
| 760 |
+
if wm_text and msg.video:
|
| 761 |
+
await status_msg.edit_text(f"🏷️ **Applying Watermark:** `{wm_text}`...")
|
| 762 |
+
wm_output_path = os.path.join(user_down_dir, f"wm_{file_name}")
|
| 763 |
+
file_path = apply_video_watermark(file_path, wm_output_path, wm_text)
|
| 764 |
+
|
| 765 |
+
size = os.path.getsize(file_path)
|
| 766 |
up_start = time.time()
|
| 767 |
+
await status_msg.edit_text(f"📤 **Uploading:** `{file_name}`\n⏳ (फाइल {current_idx} / {total_msgs})...")
|
| 768 |
|
| 769 |
thumb_to_use = task.get("thumb_path")
|
| 770 |
created_temp_thumb = None
|
| 771 |
|
| 772 |
if not thumb_to_use and msg.video:
|
| 773 |
auto_thumb_path = os.path.join(user_down_dir, f"thumb_{msgid}.jpg")
|
| 774 |
+
created_temp_thumb = generate_auto_thumb(file_path, auto_thumb_path)
|
| 775 |
thumb_to_use = created_temp_thumb
|
| 776 |
|
| 777 |
try:
|
| 778 |
if msg.photo:
|
| 779 |
+
await sender_client.send_photo(
|
| 780 |
+
target_chat, file_path, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 781 |
)
|
| 782 |
else:
|
| 783 |
+
uploaded_file = await fast_upload_file(
|
| 784 |
+
sender_client,
|
| 785 |
+
file_path,
|
| 786 |
+
progress_func=progress_bar,
|
| 787 |
+
progress_args=("📤 Uploading", status_msg, up_start, file_name, current_idx, total_msgs)
|
| 788 |
)
|
| 789 |
+
|
| 790 |
+
if batch_temp.IS_BATCH.get(user_id):
|
| 791 |
+
return False, 0, None
|
| 792 |
+
|
| 793 |
+
if msg.video:
|
| 794 |
+
await sender_client.send_video(
|
| 795 |
+
target_chat,
|
| 796 |
+
video=uploaded_file,
|
| 797 |
+
thumb=thumb_to_use,
|
| 798 |
+
caption=final_caption,
|
| 799 |
+
parse_mode=enums.ParseMode.MARKDOWN,
|
| 800 |
+
duration=msg.video.duration or 0,
|
| 801 |
+
width=msg.video.width or 0,
|
| 802 |
+
height=msg.video.height or 0,
|
| 803 |
+
**topic_kwargs
|
| 804 |
+
)
|
| 805 |
+
elif msg.audio:
|
| 806 |
+
await sender_client.send_audio(
|
| 807 |
+
target_chat,
|
| 808 |
+
audio=uploaded_file,
|
| 809 |
+
thumb=thumb_to_use,
|
| 810 |
+
caption=final_caption,
|
| 811 |
+
parse_mode=enums.ParseMode.MARKDOWN,
|
| 812 |
+
**topic_kwargs
|
| 813 |
+
)
|
| 814 |
+
else:
|
| 815 |
+
await sender_client.send_document(
|
| 816 |
+
target_chat,
|
| 817 |
+
document=uploaded_file,
|
| 818 |
+
thumb=thumb_to_use,
|
| 819 |
+
caption=final_caption,
|
| 820 |
+
parse_mode=enums.ParseMode.MARKDOWN,
|
| 821 |
+
**topic_kwargs
|
| 822 |
+
)
|
| 823 |
+
except (ChatAdminRequired, RightForbidden):
|
| 824 |
+
return False, 0, "❌ **एडमिन एरर:** टारगेट ग्रुप में फ़ाइल पोस्ट करने की अनुमति नहीं है।"
|
| 825 |
except Exception as e:
|
| 826 |
+
print(f"Standard upload fallback: {e}")
|
| 827 |
+
if not batch_temp.IS_BATCH.get(user_id):
|
| 828 |
+
if msg.video:
|
| 829 |
+
await sender_client.send_video(
|
| 830 |
+
target_chat, file_path, thumb=thumb_to_use, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN,
|
| 831 |
+
duration=msg.video.duration or 0, width=msg.video.width or 0, height=msg.video.height or 0,
|
| 832 |
+
progress=progress_bar, progress_args=("📤 Uploading", status_msg, up_start, file_name, current_idx, total_msgs),
|
| 833 |
+
**topic_kwargs
|
| 834 |
+
)
|
| 835 |
+
elif msg.document:
|
| 836 |
+
await sender_client.send_document(
|
| 837 |
+
target_chat, file_path, thumb=thumb_to_use, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN,
|
| 838 |
+
progress=progress_bar, progress_args=("📤 Uploading", status_msg, up_start, file_name, current_idx, total_msgs),
|
| 839 |
+
**topic_kwargs
|
| 840 |
+
)
|
| 841 |
+
elif msg.audio:
|
| 842 |
+
await sender_client.send_audio(
|
| 843 |
+
target_chat, file_path, thumb=thumb_to_use, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN,
|
| 844 |
+
progress=progress_bar, progress_args=("📤 Uploading", status_msg, up_start, file_name, current_idx, total_msgs),
|
| 845 |
+
**topic_kwargs
|
| 846 |
+
)
|
| 847 |
+
else:
|
| 848 |
+
await sender_client.send_document(target_chat, file_path, thumb=thumb_to_use, caption=final_caption, parse_mode=enums.ParseMode.MARKDOWN, **topic_kwargs)
|
| 849 |
finally:
|
| 850 |
if os.path.exists(file_path):
|
| 851 |
os.remove(file_path)
|
|
|
|
|
|
|
| 852 |
if created_temp_thumb and os.path.exists(created_temp_thumb):
|
| 853 |
os.remove(created_temp_thumb)
|
| 854 |
|
| 855 |
+
return True, size, None
|