Spaces:
Running on Zero
Running on Zero
Update TechVJ/start.py
Browse files- TechVJ/start.py +132 -48
TechVJ/start.py
CHANGED
|
@@ -44,7 +44,7 @@ def time_formatter(seconds: int) -> str:
|
|
| 44 |
((str(seconds) + "s") if seconds else "")
|
| 45 |
return tmp if tmp else "0s"
|
| 46 |
|
| 47 |
-
async def progress_bar(current, total, ud_type, message, start, fname=""):
|
| 48 |
now = time.time()
|
| 49 |
diff = max(1e-3, now - start)
|
| 50 |
if round(diff % 2.0) == 0 or current == total:
|
|
@@ -57,15 +57,17 @@ async def progress_bar(current, total, ud_type, message, start, fname=""):
|
|
| 57 |
filled_length = int(bar_length * current // total) if total > 0 else 0
|
| 58 |
bar = '▰' * filled_length + '▱' * (bar_length - filled_length)
|
| 59 |
|
| 60 |
-
fname_text = f"📁 **
|
|
|
|
| 61 |
|
| 62 |
status_text = (
|
| 63 |
f"**{ud_type}**\n"
|
|
|
|
| 64 |
f"{fname_text}"
|
| 65 |
f"[{bar}] {percentage:.1f}%\n"
|
| 66 |
-
f"⚡ **
|
| 67 |
-
f"📦 **
|
| 68 |
-
f"⏱️ **ETA:** {time_formatter(eta)} | **
|
| 69 |
)
|
| 70 |
try:
|
| 71 |
await message.edit_text(status_text)
|
|
@@ -112,18 +114,22 @@ async def send_cancel(client: Client, message: Message):
|
|
| 112 |
def parse_telegram_link(link: str):
|
| 113 |
link = link.strip().replace("?single", "")
|
| 114 |
|
|
|
|
| 115 |
c_topic = re.search(r"t\.me/c/(\d+)/(\d+)/(\d+)", link)
|
| 116 |
if c_topic:
|
| 117 |
return int("-100" + c_topic.group(1)), int(c_topic.group(3)), int(c_topic.group(2))
|
| 118 |
|
|
|
|
| 119 |
c_match = re.search(r"t\.me/c/(\d+)/(\d+)", link)
|
| 120 |
if c_match:
|
| 121 |
return int("-100" + c_match.group(1)), int(c_match.group(2)), None
|
| 122 |
|
|
|
|
| 123 |
b_match = re.search(r"t\.me/b/([^/]+)/(\d+)", link)
|
| 124 |
if b_match:
|
| 125 |
return b_match.group(1), int(b_match.group(2)), None
|
| 126 |
|
|
|
|
| 127 |
p_match = re.search(r"t\.me/([^/]+)/(\d+)", link)
|
| 128 |
if p_match:
|
| 129 |
return p_match.group(1), int(p_match.group(2)), None
|
|
@@ -166,6 +172,7 @@ async def clone_command(client: Client, message: Message):
|
|
| 166 |
"📖 **कंटेंट क्लोनिंग निर्देश:**\n"
|
| 167 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 168 |
"👉 **स्टेप 1:** जहाँ से कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें:\n"
|
|
|
|
| 169 |
"(रद्द करने के लिए /cancel लिखें)"
|
| 170 |
)
|
| 171 |
first_msg = await client.ask(user_id, guide_text, filters=filters.text, timeout=300)
|
|
@@ -197,7 +204,6 @@ async def clone_command(client: Client, message: Message):
|
|
| 197 |
dest_msg = await client.ask(
|
| 198 |
user_id,
|
| 199 |
"👉 **स्टेप 3:** जहाँ अपलोड करवाना है, उस **चैनल/ग्रुप का लिंक या ID** भेजें:\n"
|
| 200 |
-
"💡 *अगर किसी विशेष टॉपिक में अपलोड करना हो तो ID के साथ टॉपिक ID दें (उदा: `-100xxxx:45`)*\n"
|
| 201 |
"(सीधे इसी बॉट में पाने के लिए `/skip` लिखें)",
|
| 202 |
filters=filters.text,
|
| 203 |
timeout=300
|
|
@@ -207,23 +213,40 @@ async def clone_command(client: Client, message: Message):
|
|
| 207 |
|
| 208 |
dest_val = dest_msg.text.strip()
|
| 209 |
is_direct_bot = False
|
| 210 |
-
|
| 211 |
|
| 212 |
if dest_val.lower() == "/skip":
|
| 213 |
target_chat = user_id
|
| 214 |
is_direct_bot = True
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
try:
|
| 224 |
-
|
| 225 |
except ValueError:
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
batch_temp.CLONE_DATA[user_id] = {
|
| 229 |
"source_chat": s_chat,
|
|
@@ -238,7 +261,19 @@ async def clone_command(client: Client, message: Message):
|
|
| 238 |
"replace_with": None,
|
| 239 |
"thumb_path": None
|
| 240 |
}
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
async def show_customization_menu(client: Client, user_id: int):
|
| 244 |
data = batch_temp.CLONE_DATA.get(user_id, {})
|
|
@@ -250,6 +285,8 @@ async def show_customization_menu(client: Client, user_id: int):
|
|
| 250 |
if data.get("target_topic_id"):
|
| 251 |
dest_display += f" (टॉपिक ID: `{data.get('target_topic_id')}`)"
|
| 252 |
|
|
|
|
|
|
|
| 253 |
panel_text = (
|
| 254 |
"⚙️ **कंटेंट कस्टमाइज़ेशन सेटिंग्स:**\n"
|
| 255 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
|
@@ -258,7 +295,7 @@ async def show_customization_menu(client: Client, user_id: int):
|
|
| 258 |
f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
|
| 259 |
f"🖼️ थंबनेल: `{thm_status}`\n"
|
| 260 |
f"🎯 टारगेट: {dest_display}\n"
|
| 261 |
-
f"📊 रेंज: `{data.get('start_id')}` से `{data.get('end_id')}`\n"
|
| 262 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 263 |
"एडिट करें या तुरंत ट्रांसफर के लिए **🚀 Confirm & Start** दबाएँ:"
|
| 264 |
)
|
|
@@ -282,27 +319,50 @@ async def callback_handler(client: Client, query: CallbackQuery):
|
|
| 282 |
return await query.answer("⚠️ सेशन एक्सपायर हो गया, दोबारा /clone करें।", show_alert=True)
|
| 283 |
|
| 284 |
data = query.data
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
await query.message.delete()
|
| 287 |
msg = await client.ask(user_id, "✍️ **नया कस्टम कैप्शन भेजें** (हाइपरलिंक मान्य हैं):", filters=filters.text, timeout=180)
|
| 288 |
batch_temp.CLONE_DATA[user_id]["custom_caption"] = msg.text.markdown
|
| 289 |
await show_customization_menu(client, user_id)
|
|
|
|
| 290 |
elif data == "set_replace":
|
| 291 |
await query.message.delete()
|
| 292 |
find_msg = await client.ask(user_id, "🔍 क्या खोजना/हटाना चाहते हैं? वह शब्द भेजें:", filters=filters.text, timeout=180)
|
| 293 |
if find_msg.text == "/cancel":
|
| 294 |
return await show_customization_menu(client, user_id)
|
| 295 |
-
with_msg = await client.ask(user_id, f"✏️ `{find_msg.text}` की जगह क्या लगाना चाहते हैं? (खाली रखने के लिए `/empty`):", filters=filters.text, timeout=180)
|
| 296 |
if with_msg.text == "/cancel":
|
| 297 |
return await show_customization_menu(client, user_id)
|
| 298 |
batch_temp.CLONE_DATA[user_id]["replace_find"] = find_msg.text
|
| 299 |
batch_temp.CLONE_DATA[user_id]["replace_with"] = "" if with_msg.text.strip() == "/empty" else with_msg.text.markdown
|
| 300 |
await show_customization_menu(client, user_id)
|
|
|
|
| 301 |
elif data == "set_extra":
|
| 302 |
await query.message.delete()
|
| 303 |
msg = await client.ask(user_id, "✍️ **अतिरिक्त कैप्शन भेजें** (हाइपरलिंक्स मान्य हैं):", filters=filters.text, timeout=180)
|
| 304 |
batch_temp.CLONE_DATA[user_id]["extra_caption"] = msg.text.markdown
|
| 305 |
await show_customization_menu(client, user_id)
|
|
|
|
| 306 |
elif data == "set_thumb":
|
| 307 |
await query.message.delete()
|
| 308 |
msg = await client.ask(user_id, "🖼️ **थंबनेल के लिए फ़ोटो भेजें:**", filters=filters.photo, timeout=180)
|
|
@@ -313,6 +373,7 @@ async def callback_handler(client: Client, query: CallbackQuery):
|
|
| 313 |
batch_temp.CLONE_DATA[user_id]["thumb_path"] = thumb_file
|
| 314 |
await msg.reply_text("✅ आपका थंबनेल सुरक्षित सेव कर लिया गया!")
|
| 315 |
await show_customization_menu(client, user_id)
|
|
|
|
| 316 |
elif data == "clear_settings":
|
| 317 |
batch_temp.CLONE_DATA[user_id]["custom_caption"] = None
|
| 318 |
batch_temp.CLONE_DATA[user_id]["extra_caption"] = None
|
|
@@ -325,6 +386,7 @@ async def callback_handler(client: Client, query: CallbackQuery):
|
|
| 325 |
await query.answer("सेटिंग्स रीसेट हो गईं।")
|
| 326 |
await query.message.delete()
|
| 327 |
await show_customization_menu(client, user_id)
|
|
|
|
| 328 |
elif data == "confirm_start":
|
| 329 |
await query.message.delete()
|
| 330 |
await start_clone_task(client, user_id)
|
|
@@ -344,7 +406,11 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 344 |
user_api_id = int(db.get_api_id(user_id) or API_ID)
|
| 345 |
user_api_hash = db.get_api_hash(user_id) or API_HASH
|
| 346 |
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
|
| 349 |
acc = Client(
|
| 350 |
f"user_session_{user_id}",
|
|
@@ -352,17 +418,16 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 352 |
api_hash=user_api_hash,
|
| 353 |
api_id=user_api_id,
|
| 354 |
in_memory=True,
|
| 355 |
-
workers=
|
| 356 |
-
max_concurrent_transmissions=
|
| 357 |
)
|
| 358 |
try:
|
| 359 |
await acc.start()
|
| 360 |
except Exception as e:
|
| 361 |
return await status_msg.edit_text(f"❌ सेशन कनेक्ट एरर: `{e}`")
|
| 362 |
|
| 363 |
-
# डायलॉग्स लोड करना ताकि प्राइवेट चैनल बिना अटके रिजॉल्व हो जाए
|
| 364 |
try:
|
| 365 |
-
async for dialog in acc.get_dialogs(limit=
|
| 366 |
pass
|
| 367 |
except Exception:
|
| 368 |
pass
|
|
@@ -374,9 +439,11 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 374 |
total_bytes = 0
|
| 375 |
start_time = time.time()
|
| 376 |
|
|
|
|
| 377 |
for msgid in range(start_id, end_id + 1):
|
|
|
|
| 378 |
if batch_temp.IS_BATCH.get(user_id):
|
| 379 |
-
await status_msg.edit_text("🛑 **टास्क
|
| 380 |
break
|
| 381 |
|
| 382 |
if not db.is_user_vip(user_id, ADMINS):
|
|
@@ -388,12 +455,16 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 388 |
while attempts < 3:
|
| 389 |
if batch_temp.IS_BATCH.get(user_id):
|
| 390 |
break
|
| 391 |
-
if not db.is_user_vip(user_id, ADMINS):
|
| 392 |
-
batch_temp.IS_BATCH[user_id] = True
|
| 393 |
-
break
|
| 394 |
-
|
| 395 |
try:
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
if ok:
|
| 398 |
success += 1
|
| 399 |
total_bytes += sz
|
|
@@ -405,6 +476,10 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 405 |
await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
|
| 406 |
await asyncio.sleep(fw.value + 1)
|
| 407 |
attempts += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
except Exception as e:
|
| 409 |
print(f"General error on {msgid}: {e}")
|
| 410 |
retrying += 1
|
|
@@ -431,9 +506,10 @@ async def start_clone_task(client: Client, user_id: int):
|
|
| 431 |
summary_card = (
|
| 432 |
"🏁 **Transfer Finished**\n"
|
| 433 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
|
|
|
| 434 |
f"✅ Success: {success}\n"
|
| 435 |
-
f"🗑️
|
| 436 |
-
f"🔁 Retrying:
|
| 437 |
f"📦 Total Size: {humanbytes(total_bytes)}\n"
|
| 438 |
f"⚡ Avg Speed: {avg_speed}\n"
|
| 439 |
f"⏱️ Time: {time_formatter(elapsed_time)}\n"
|
|
@@ -461,11 +537,10 @@ def get_file_name_from_msg(msg: Message) -> str:
|
|
| 461 |
else:
|
| 462 |
name = f"file_{msg.id}.bin"
|
| 463 |
|
| 464 |
-
# नाम से आगे लगी ID हटाना
|
| 465 |
clean_name = re.sub(r"^\d+_", "", name)
|
| 466 |
return clean_name if clean_name else name
|
| 467 |
|
| 468 |
-
async def process_media(client: Client, acc: Client, user_id: int, source_chat, msgid: int, target_chat, target_topic_id, task: dict, status_msg: Message):
|
| 469 |
if batch_temp.IS_BATCH.get(user_id):
|
| 470 |
return False, 0
|
| 471 |
|
|
@@ -478,10 +553,10 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 478 |
except Exception:
|
| 479 |
return False, 0
|
| 480 |
|
| 481 |
-
if not msg or msg.empty:
|
| 482 |
return False, 0
|
| 483 |
|
| 484 |
-
final_caption = msg.caption.markdown if msg.caption else ""
|
| 485 |
|
| 486 |
if task.get("custom_caption"):
|
| 487 |
final_caption = task["custom_caption"]
|
|
@@ -502,6 +577,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 502 |
|
| 503 |
topic_kwargs = {"message_thread_id": target_topic_id} if target_topic_id and not is_direct_bot else {}
|
| 504 |
|
|
|
|
| 505 |
if msg.text:
|
| 506 |
text_to_send = msg.text.markdown
|
| 507 |
if task.get("custom_caption"):
|
|
@@ -518,12 +594,17 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 518 |
file_name = get_file_name_from_msg(msg)
|
| 519 |
user_down_dir = os.path.join("downloads", str(user_id))
|
| 520 |
os.makedirs(user_down_dir, exist_ok=True)
|
| 521 |
-
# फ़ाइल नाम से ID प्रीफ़िक्स हटा दिया गया
|
| 522 |
down_path = os.path.join(user_down_dir, file_name)
|
| 523 |
|
|
|
|
| 524 |
down_start = time.time()
|
| 525 |
-
await status_msg.edit_text(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
|
|
|
|
| 527 |
if msg.photo:
|
| 528 |
file_path = await acc.download_media(msg, file_name=down_path)
|
| 529 |
else:
|
|
@@ -533,14 +614,14 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 533 |
msg,
|
| 534 |
out_path=down_path,
|
| 535 |
progress_func=progress_bar,
|
| 536 |
-
progress_args=("📥 Downloading ID: " + str(msgid), status_msg, down_start, file_name)
|
| 537 |
)
|
| 538 |
except Exception:
|
| 539 |
file_path = await acc.download_media(
|
| 540 |
msg,
|
| 541 |
file_name=down_path,
|
| 542 |
progress=progress_bar,
|
| 543 |
-
progress_args=("📥 Downloading ID: " + str(msgid), status_msg, down_start, file_name)
|
| 544 |
)
|
| 545 |
|
| 546 |
if batch_temp.IS_BATCH.get(user_id):
|
|
@@ -553,7 +634,11 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 553 |
|
| 554 |
size = os.path.getsize(file_path)
|
| 555 |
up_start = time.time()
|
| 556 |
-
await status_msg.edit_text(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
thumb_to_use = task.get("thumb_path")
|
| 559 |
created_temp_thumb = None
|
|
@@ -563,7 +648,6 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 563 |
created_temp_thumb = generate_auto_thumb(file_path, auto_thumb_path)
|
| 564 |
thumb_to_use = created_temp_thumb
|
| 565 |
|
| 566 |
-
# केवल एक बार डायरेक्ट अपलोड (डबल अपलोडिंग का लूप पूरी तरह हटा दिया गया)
|
| 567 |
try:
|
| 568 |
if msg.photo:
|
| 569 |
await sender_client.send_photo(
|
|
@@ -580,7 +664,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 580 |
width=getattr(msg.video, "width", 0) or 0,
|
| 581 |
height=getattr(msg.video, "height", 0) or 0,
|
| 582 |
progress=progress_bar,
|
| 583 |
-
progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name),
|
| 584 |
**topic_kwargs
|
| 585 |
)
|
| 586 |
elif msg.audio:
|
|
@@ -592,7 +676,7 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 592 |
parse_mode=enums.ParseMode.MARKDOWN,
|
| 593 |
duration=getattr(msg.audio, "duration", 0) or 0,
|
| 594 |
progress=progress_bar,
|
| 595 |
-
progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name),
|
| 596 |
**topic_kwargs
|
| 597 |
)
|
| 598 |
else:
|
|
@@ -603,11 +687,11 @@ async def process_media(client: Client, acc: Client, user_id: int, source_chat,
|
|
| 603 |
caption=final_caption,
|
| 604 |
parse_mode=enums.ParseMode.MARKDOWN,
|
| 605 |
progress=progress_bar,
|
| 606 |
-
progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name),
|
| 607 |
**topic_kwargs
|
| 608 |
)
|
| 609 |
except Exception as e:
|
| 610 |
-
print(f"Direct Upload error: {e}")
|
| 611 |
return False, 0
|
| 612 |
finally:
|
| 613 |
if os.path.exists(file_path):
|
|
|
|
| 44 |
((str(seconds) + "s") if seconds else "")
|
| 45 |
return tmp if tmp else "0s"
|
| 46 |
|
| 47 |
+
async def progress_bar(current, total, ud_type, message, start, fname="", current_idx=1, total_count=1):
|
| 48 |
now = time.time()
|
| 49 |
diff = max(1e-3, now - start)
|
| 50 |
if round(diff % 2.0) == 0 or current == total:
|
|
|
|
| 57 |
filled_length = int(bar_length * current // total) if total > 0 else 0
|
| 58 |
bar = '▰' * filled_length + '▱' * (bar_length - filled_length)
|
| 59 |
|
| 60 |
+
fname_text = f"📁 **फ़ाइल:** `{fname[:30]}...`\n" if fname else ""
|
| 61 |
+
remaining = max(0, total_count - current_idx)
|
| 62 |
|
| 63 |
status_text = (
|
| 64 |
f"**{ud_type}**\n"
|
| 65 |
+
f"📊 **प्रगति:** `[{current_idx}/{total_count}]` | ⏳ **शेष:** `{remaining}`\n"
|
| 66 |
f"{fname_text}"
|
| 67 |
f"[{bar}] {percentage:.1f}%\n"
|
| 68 |
+
f"⚡ **स्पीड:** {humanbytes(speed)}/s\n"
|
| 69 |
+
f"📦 **डन:** {humanbytes(current)} / {humanbytes(total)}\n"
|
| 70 |
+
f"⏱️ **ETA:** {time_formatter(eta)} | **समय:** {time_formatter(elapsed_time)}"
|
| 71 |
)
|
| 72 |
try:
|
| 73 |
await message.edit_text(status_text)
|
|
|
|
| 114 |
def parse_telegram_link(link: str):
|
| 115 |
link = link.strip().replace("?single", "")
|
| 116 |
|
| 117 |
+
# टॉपिक फोरम लिंक: t.me/c/1234567/5/100
|
| 118 |
c_topic = re.search(r"t\.me/c/(\d+)/(\d+)/(\d+)", link)
|
| 119 |
if c_topic:
|
| 120 |
return int("-100" + c_topic.group(1)), int(c_topic.group(3)), int(c_topic.group(2))
|
| 121 |
|
| 122 |
+
# प्राइवेट चैनल: t.me/c/1234567/100
|
| 123 |
c_match = re.search(r"t\.me/c/(\d+)/(\d+)", link)
|
| 124 |
if c_match:
|
| 125 |
return int("-100" + c_match.group(1)), int(c_match.group(2)), None
|
| 126 |
|
| 127 |
+
# बॉट लिंक: t.me/b/username/100
|
| 128 |
b_match = re.search(r"t\.me/b/([^/]+)/(\d+)", link)
|
| 129 |
if b_match:
|
| 130 |
return b_match.group(1), int(b_match.group(2)), None
|
| 131 |
|
| 132 |
+
# पब्लिक चैनल: t.me/username/100
|
| 133 |
p_match = re.search(r"t\.me/([^/]+)/(\d+)", link)
|
| 134 |
if p_match:
|
| 135 |
return p_match.group(1), int(p_match.group(2)), None
|
|
|
|
| 172 |
"📖 **कंटेंट क्लोनिंग निर्देश:**\n"
|
| 173 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 174 |
"👉 **स्टेप 1:** जहाँ से कॉपी करना है, उसकी **पहली लिंक (Start Link)** भेजें:\n"
|
| 175 |
+
"(पब्लिक, प्राइवेट, बॉट लिंक या टॉपिक लिंक मान्य हैं)\n"
|
| 176 |
"(रद्द करने के लिए /cancel लिखें)"
|
| 177 |
)
|
| 178 |
first_msg = await client.ask(user_id, guide_text, filters=filters.text, timeout=300)
|
|
|
|
| 204 |
dest_msg = await client.ask(
|
| 205 |
user_id,
|
| 206 |
"👉 **स्टेप 3:** जहाँ अपलोड करवाना है, उस **चैनल/ग्रुप का लिंक या ID** भेजें:\n"
|
|
|
|
| 207 |
"(सीधे इसी बॉट में पाने के लिए `/skip` लिखें)",
|
| 208 |
filters=filters.text,
|
| 209 |
timeout=300
|
|
|
|
| 213 |
|
| 214 |
dest_val = dest_msg.text.strip()
|
| 215 |
is_direct_bot = False
|
| 216 |
+
target_chat = None
|
| 217 |
|
| 218 |
if dest_val.lower() == "/skip":
|
| 219 |
target_chat = user_id
|
| 220 |
is_direct_bot = True
|
| 221 |
+
batch_temp.CLONE_DATA[user_id] = {
|
| 222 |
+
"source_chat": s_chat,
|
| 223 |
+
"start_id": min(s_id, e_id),
|
| 224 |
+
"end_id": max(s_id, e_id),
|
| 225 |
+
"target_chat": target_chat,
|
| 226 |
+
"target_topic_id": None,
|
| 227 |
+
"is_direct_bot": is_direct_bot,
|
| 228 |
+
"custom_caption": None,
|
| 229 |
+
"extra_caption": None,
|
| 230 |
+
"replace_find": None,
|
| 231 |
+
"replace_with": None,
|
| 232 |
+
"thumb_path": None
|
| 233 |
+
}
|
| 234 |
+
return await show_customization_menu(client, user_id)
|
| 235 |
+
|
| 236 |
+
if ":" in dest_val:
|
| 237 |
+
parts = dest_val.split(":")
|
| 238 |
+
dest_val = parts[0]
|
| 239 |
try:
|
| 240 |
+
target_topic_id = int(parts[1])
|
| 241 |
except ValueError:
|
| 242 |
+
target_topic_id = None
|
| 243 |
+
else:
|
| 244 |
+
target_topic_id = None
|
| 245 |
+
|
| 246 |
+
try:
|
| 247 |
+
target_chat = int(dest_val)
|
| 248 |
+
except ValueError:
|
| 249 |
+
target_chat = dest_val.replace("https://t.me/", "@")
|
| 250 |
|
| 251 |
batch_temp.CLONE_DATA[user_id] = {
|
| 252 |
"source_chat": s_chat,
|
|
|
|
| 261 |
"replace_with": None,
|
| 262 |
"thumb_path": None
|
| 263 |
}
|
| 264 |
+
|
| 265 |
+
# टॉपिक ग्रुप Yes/No इनलाइन बटन
|
| 266 |
+
topic_markup = InlineKeyboardMarkup([
|
| 267 |
+
[
|
| 268 |
+
InlineKeyboardButton("✅ हाँ (Yes)", callback_data="ask_topic_yes"),
|
| 269 |
+
InlineKeyboardButton("❌ नहीं (No)", callback_data="ask_topic_no")
|
| 270 |
+
]
|
| 271 |
+
])
|
| 272 |
+
await client.send_message(
|
| 273 |
+
user_id,
|
| 274 |
+
"🧵 **क्या आप इसे किसी विशेष टॉपिक (Forum Topic) में अपलोड करवाना चाहते हैं?**",
|
| 275 |
+
reply_markup=topic_markup
|
| 276 |
+
)
|
| 277 |
|
| 278 |
async def show_customization_menu(client: Client, user_id: int):
|
| 279 |
data = batch_temp.CLONE_DATA.get(user_id, {})
|
|
|
|
| 285 |
if data.get("target_topic_id"):
|
| 286 |
dest_display += f" (टॉपिक ID: `{data.get('target_topic_id')}`)"
|
| 287 |
|
| 288 |
+
total_msgs = (data.get('end_id', 0) - data.get('start_id', 0)) + 1
|
| 289 |
+
|
| 290 |
panel_text = (
|
| 291 |
"⚙️ **कंटेंट कस्टमाइज़ेशन सेटिंग्स:**\n"
|
| 292 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
|
|
|
| 295 |
f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
|
| 296 |
f"🖼️ थंबनेल: `{thm_status}`\n"
|
| 297 |
f"🎯 टारगेट: {dest_display}\n"
|
| 298 |
+
f"📊 रेंज: `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_msgs} मैसेज)\n"
|
| 299 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 300 |
"एडिट करें या तुरंत ट्रांसफर के लिए **🚀 Confirm & Start** दबाएँ:"
|
| 301 |
)
|
|
|
|
| 319 |
return await query.answer("⚠️ सेशन एक्सपायर हो गया, दोबारा /clone करें।", show_alert=True)
|
| 320 |
|
| 321 |
data = query.data
|
| 322 |
+
|
| 323 |
+
if data == "ask_topic_yes":
|
| 324 |
+
await query.message.delete()
|
| 325 |
+
t_msg = await client.ask(
|
| 326 |
+
user_id,
|
| 327 |
+
"👉 कृपया उस **Topic ID (थ्रेड ID)** को दर्ज करें:\n(उदाहरण: `45`)",
|
| 328 |
+
filters=filters.text,
|
| 329 |
+
timeout=180
|
| 330 |
+
)
|
| 331 |
+
if t_msg.text != "/cancel":
|
| 332 |
+
try:
|
| 333 |
+
batch_temp.CLONE_DATA[user_id]["target_topic_id"] = int(t_msg.text.strip())
|
| 334 |
+
except ValueError:
|
| 335 |
+
await t_msg.reply_text("⚠️ अमान्य संख्या! टॉपिक आईडी छोड़ दी गई।")
|
| 336 |
+
await show_customization_menu(client, user_id)
|
| 337 |
+
|
| 338 |
+
elif data == "ask_topic_no":
|
| 339 |
+
await query.message.delete()
|
| 340 |
+
await show_customization_menu(client, user_id)
|
| 341 |
+
|
| 342 |
+
elif data == "set_caption":
|
| 343 |
await query.message.delete()
|
| 344 |
msg = await client.ask(user_id, "✍️ **नया कस्टम कैप्शन भेजें** (हाइपरलिंक मान्य हैं):", filters=filters.text, timeout=180)
|
| 345 |
batch_temp.CLONE_DATA[user_id]["custom_caption"] = msg.text.markdown
|
| 346 |
await show_customization_menu(client, user_id)
|
| 347 |
+
|
| 348 |
elif data == "set_replace":
|
| 349 |
await query.message.delete()
|
| 350 |
find_msg = await client.ask(user_id, "🔍 क्या खोजना/हटाना चाहते हैं? वह शब्द भेजें:", filters=filters.text, timeout=180)
|
| 351 |
if find_msg.text == "/cancel":
|
| 352 |
return await show_customization_menu(client, user_id)
|
| 353 |
+
with_msg = await client.ask(user_id, f"✏️ `{find_msg.text}` की जगह क्या लगाना चाहते हैं? (हटाने/खाली रखने के लिए `/empty`):", filters=filters.text, timeout=180)
|
| 354 |
if with_msg.text == "/cancel":
|
| 355 |
return await show_customization_menu(client, user_id)
|
| 356 |
batch_temp.CLONE_DATA[user_id]["replace_find"] = find_msg.text
|
| 357 |
batch_temp.CLONE_DATA[user_id]["replace_with"] = "" if with_msg.text.strip() == "/empty" else with_msg.text.markdown
|
| 358 |
await show_customization_menu(client, user_id)
|
| 359 |
+
|
| 360 |
elif data == "set_extra":
|
| 361 |
await query.message.delete()
|
| 362 |
msg = await client.ask(user_id, "✍️ **अतिरिक्त कैप्शन भेजें** (हाइपरलिंक्स मान्य हैं):", filters=filters.text, timeout=180)
|
| 363 |
batch_temp.CLONE_DATA[user_id]["extra_caption"] = msg.text.markdown
|
| 364 |
await show_customization_menu(client, user_id)
|
| 365 |
+
|
| 366 |
elif data == "set_thumb":
|
| 367 |
await query.message.delete()
|
| 368 |
msg = await client.ask(user_id, "🖼️ **थंबनेल के लिए फ़ोटो भेजें:**", filters=filters.photo, timeout=180)
|
|
|
|
| 373 |
batch_temp.CLONE_DATA[user_id]["thumb_path"] = thumb_file
|
| 374 |
await msg.reply_text("✅ आपका थंबनेल सुरक्षित सेव कर लिया गया!")
|
| 375 |
await show_customization_menu(client, user_id)
|
| 376 |
+
|
| 377 |
elif data == "clear_settings":
|
| 378 |
batch_temp.CLONE_DATA[user_id]["custom_caption"] = None
|
| 379 |
batch_temp.CLONE_DATA[user_id]["extra_caption"] = None
|
|
|
|
| 386 |
await query.answer("सेटिंग्स रीसेट हो गईं।")
|
| 387 |
await query.message.delete()
|
| 388 |
await show_customization_menu(client, user_id)
|
| 389 |
+
|
| 390 |
elif data == "confirm_start":
|
| 391 |
await query.message.delete()
|
| 392 |
await start_clone_task(client, user_id)
|
|
|
|
| 406 |
user_api_id = int(db.get_api_id(user_id) or API_ID)
|
| 407 |
user_api_hash = db.get_api_hash(user_id) or API_HASH
|
| 408 |
|
| 409 |
+
total_count = (end_id - start_id) + 1
|
| 410 |
+
status_msg = await client.send_message(
|
| 411 |
+
user_id,
|
| 412 |
+
f"🚀 **कंटेंट ट्रांसफर शुरू हो रहा है...**\n📊 **कुल फाइल्स/मैसेज:** `{total_count}`"
|
| 413 |
+
)
|
| 414 |
|
| 415 |
acc = Client(
|
| 416 |
f"user_session_{user_id}",
|
|
|
|
| 418 |
api_hash=user_api_hash,
|
| 419 |
api_id=user_api_id,
|
| 420 |
in_memory=True,
|
| 421 |
+
workers=16,
|
| 422 |
+
max_concurrent_transmissions=4
|
| 423 |
)
|
| 424 |
try:
|
| 425 |
await acc.start()
|
| 426 |
except Exception as e:
|
| 427 |
return await status_msg.edit_text(f"❌ सेशन कनेक्ट एरर: `{e}`")
|
| 428 |
|
|
|
|
| 429 |
try:
|
| 430 |
+
async for dialog in acc.get_dialogs(limit=20):
|
| 431 |
pass
|
| 432 |
except Exception:
|
| 433 |
pass
|
|
|
|
| 439 |
total_bytes = 0
|
| 440 |
start_time = time.time()
|
| 441 |
|
| 442 |
+
current_idx = 0
|
| 443 |
for msgid in range(start_id, end_id + 1):
|
| 444 |
+
current_idx += 1
|
| 445 |
if batch_temp.IS_BATCH.get(user_id):
|
| 446 |
+
await status_msg.edit_text("🛑 **टास्क रोक दिया गया है।**")
|
| 447 |
break
|
| 448 |
|
| 449 |
if not db.is_user_vip(user_id, ADMINS):
|
|
|
|
| 455 |
while attempts < 3:
|
| 456 |
if batch_temp.IS_BATCH.get(user_id):
|
| 457 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
try:
|
| 459 |
+
# 300 सेकंड टाइमआउट ताकि कोई बड़ी फ़ाइल टास्क को फ्रीज न करे
|
| 460 |
+
ok, sz = await asyncio.wait_for(
|
| 461 |
+
process_media(
|
| 462 |
+
client, acc, user_id, source_chat, msgid,
|
| 463 |
+
target_chat, target_topic_id, task, status_msg,
|
| 464 |
+
current_idx, total_count
|
| 465 |
+
),
|
| 466 |
+
timeout=300.0
|
| 467 |
+
)
|
| 468 |
if ok:
|
| 469 |
success += 1
|
| 470 |
total_bytes += sz
|
|
|
|
| 476 |
await status_msg.edit_text(f"⏳ **Rate-limit:** {fw.value} सेकंड इंतज़ार कर रहे हैं...")
|
| 477 |
await asyncio.sleep(fw.value + 1)
|
| 478 |
attempts += 1
|
| 479 |
+
except asyncio.TimeoutError:
|
| 480 |
+
print(f"Timeout on msg {msgid}, retrying...")
|
| 481 |
+
attempts += 1
|
| 482 |
+
await asyncio.sleep(2)
|
| 483 |
except Exception as e:
|
| 484 |
print(f"General error on {msgid}: {e}")
|
| 485 |
retrying += 1
|
|
|
|
| 506 |
summary_card = (
|
| 507 |
"🏁 **Transfer Finished**\n"
|
| 508 |
"━━━━━━━━━━━━━━━━━━━━\n"
|
| 509 |
+
f"📊 Total Messages: {total_count}\n"
|
| 510 |
f"✅ Success: {success}\n"
|
| 511 |
+
f"🗑️ Empty/Skipped: {not_found}\n"
|
| 512 |
+
f"🔁 Retrying: {retrying}\n"
|
| 513 |
f"📦 Total Size: {humanbytes(total_bytes)}\n"
|
| 514 |
f"⚡ Avg Speed: {avg_speed}\n"
|
| 515 |
f"⏱️ Time: {time_formatter(elapsed_time)}\n"
|
|
|
|
| 537 |
else:
|
| 538 |
name = f"file_{msg.id}.bin"
|
| 539 |
|
|
|
|
| 540 |
clean_name = re.sub(r"^\d+_", "", name)
|
| 541 |
return clean_name if clean_name else name
|
| 542 |
|
| 543 |
+
async def process_media(client: Client, acc: Client, user_id: int, source_chat, msgid: int, target_chat, target_topic_id, task: dict, status_msg: Message, current_idx: int, total_count: int):
|
| 544 |
if batch_temp.IS_BATCH.get(user_id):
|
| 545 |
return False, 0
|
| 546 |
|
|
|
|
| 553 |
except Exception:
|
| 554 |
return False, 0
|
| 555 |
|
| 556 |
+
if not msg or msg.empty or msg.service:
|
| 557 |
return False, 0
|
| 558 |
|
| 559 |
+
final_caption = (msg.caption.markdown if msg.caption else "")
|
| 560 |
|
| 561 |
if task.get("custom_caption"):
|
| 562 |
final_caption = task["custom_caption"]
|
|
|
|
| 577 |
|
| 578 |
topic_kwargs = {"message_thread_id": target_topic_id} if target_topic_id and not is_direct_bot else {}
|
| 579 |
|
| 580 |
+
# सादा टेक्स्ट मैसेज
|
| 581 |
if msg.text:
|
| 582 |
text_to_send = msg.text.markdown
|
| 583 |
if task.get("custom_caption"):
|
|
|
|
| 594 |
file_name = get_file_name_from_msg(msg)
|
| 595 |
user_down_dir = os.path.join("downloads", str(user_id))
|
| 596 |
os.makedirs(user_down_dir, exist_ok=True)
|
|
|
|
| 597 |
down_path = os.path.join(user_down_dir, file_name)
|
| 598 |
|
| 599 |
+
remaining = max(0, total_count - current_idx)
|
| 600 |
down_start = time.time()
|
| 601 |
+
await status_msg.edit_text(
|
| 602 |
+
f"📥 **Downloading ID:** `{msgid}`\n"
|
| 603 |
+
f"📊 **प्रगति:** `[{current_idx}/{total_count}]` | ⏳ **शेष:** `{remaining}`\n"
|
| 604 |
+
f"📁 **फ़ाइल:** `{file_name}`..."
|
| 605 |
+
)
|
| 606 |
|
| 607 |
+
file_path = None
|
| 608 |
if msg.photo:
|
| 609 |
file_path = await acc.download_media(msg, file_name=down_path)
|
| 610 |
else:
|
|
|
|
| 614 |
msg,
|
| 615 |
out_path=down_path,
|
| 616 |
progress_func=progress_bar,
|
| 617 |
+
progress_args=("📥 Downloading ID: " + str(msgid), status_msg, down_start, file_name, current_idx, total_count)
|
| 618 |
)
|
| 619 |
except Exception:
|
| 620 |
file_path = await acc.download_media(
|
| 621 |
msg,
|
| 622 |
file_name=down_path,
|
| 623 |
progress=progress_bar,
|
| 624 |
+
progress_args=("📥 Downloading ID: " + str(msgid), status_msg, down_start, file_name, current_idx, total_count)
|
| 625 |
)
|
| 626 |
|
| 627 |
if batch_temp.IS_BATCH.get(user_id):
|
|
|
|
| 634 |
|
| 635 |
size = os.path.getsize(file_path)
|
| 636 |
up_start = time.time()
|
| 637 |
+
await status_msg.edit_text(
|
| 638 |
+
f"📤 **Uploading ID:** `{msgid}`\n"
|
| 639 |
+
f"📊 **प्रगति:** `[{current_idx}/{total_count}]` | ⏳ **शेष:** `{remaining}`\n"
|
| 640 |
+
f"📁 **फ़ाइल:** `{file_name}`..."
|
| 641 |
+
)
|
| 642 |
|
| 643 |
thumb_to_use = task.get("thumb_path")
|
| 644 |
created_temp_thumb = None
|
|
|
|
| 648 |
created_temp_thumb = generate_auto_thumb(file_path, auto_thumb_path)
|
| 649 |
thumb_to_use = created_temp_thumb
|
| 650 |
|
|
|
|
| 651 |
try:
|
| 652 |
if msg.photo:
|
| 653 |
await sender_client.send_photo(
|
|
|
|
| 664 |
width=getattr(msg.video, "width", 0) or 0,
|
| 665 |
height=getattr(msg.video, "height", 0) or 0,
|
| 666 |
progress=progress_bar,
|
| 667 |
+
progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count),
|
| 668 |
**topic_kwargs
|
| 669 |
)
|
| 670 |
elif msg.audio:
|
|
|
|
| 676 |
parse_mode=enums.ParseMode.MARKDOWN,
|
| 677 |
duration=getattr(msg.audio, "duration", 0) or 0,
|
| 678 |
progress=progress_bar,
|
| 679 |
+
progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count),
|
| 680 |
**topic_kwargs
|
| 681 |
)
|
| 682 |
else:
|
|
|
|
| 687 |
caption=final_caption,
|
| 688 |
parse_mode=enums.ParseMode.MARKDOWN,
|
| 689 |
progress=progress_bar,
|
| 690 |
+
progress_args=(f"📤 Uploading ID: {msgid}", status_msg, up_start, file_name, current_idx, total_count),
|
| 691 |
**topic_kwargs
|
| 692 |
)
|
| 693 |
except Exception as e:
|
| 694 |
+
print(f"Direct Upload error on {msgid}: {e}")
|
| 695 |
return False, 0
|
| 696 |
finally:
|
| 697 |
if os.path.exists(file_path):
|