Agnivesh10M commited on
Commit
bbac8e8
·
verified ·
1 Parent(s): a01370e

Update TechVJ/start.py

Browse files
Files changed (1) hide show
  1. TechVJ/start.py +112 -73
TechVJ/start.py CHANGED
@@ -77,6 +77,113 @@ def humanbytes(size):
77
  t_n += 1
78
  return f"{round(size, 2)} {power_labels[t_n]}B"
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  def time_formatter(seconds: int) -> str:
81
  minutes, seconds = divmod(seconds, 60)
82
  hours, minutes = divmod(minutes, 60)
@@ -121,52 +228,6 @@ async def progress_bar(current, total, ud_type, message, start, fname="", curren
121
  except Exception:
122
  pass
123
 
124
- def get_system_font():
125
- fonts = [
126
- "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
127
- "/usr/share/fonts/truetype/freefont/FreeSansBold.ttf",
128
- "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf"
129
- ]
130
- for f in fonts:
131
- if os.path.exists(f):
132
- return f
133
- return None
134
-
135
- def apply_video_watermark(input_path: str, output_path: str, text: str):
136
- clean_text = text.upper().strip().replace("'", "").replace(":", "")
137
- font_file = get_system_font()
138
- font_arg = f":fontfile='{font_file}'" if font_file else ""
139
-
140
- # 5-रंगों का चक्र (Red, Purple, Pink, White, Gold)
141
- color_expr = (
142
- "if(lt(mod(t\,25)\,5)\,0xff3333\,"
143
- "if(lt(mod(t\,25)\,10)\,0xbf00ff\,"
144
- "if(lt(mod(t\,25)\,15)\,0xff66cc\,"
145
- "if(lt(mod(t\,25)\,20)\,0xffffff\,0xffd700))))"
146
- )
147
-
148
- draw_filter = (
149
- f"drawtext=text='{clean_text}'{font_arg}:"
150
- f"x=w-mod(t*90\\,w+tw):y=h-th-25:"
151
- f"fontsize=30:fontcolor_expr={color_expr}:"
152
- f"box=1:boxcolor=black@0.4:boxborderw=6:shadowcolor=black@0.8:shadowx=2:shadowy=2"
153
- )
154
-
155
- cmd = [
156
- "ffmpeg", "-i", input_path,
157
- "-vf", draw_filter,
158
- "-c:v", "libx264", "-preset", "ultrafast", "-crf", "23",
159
- "-c:a", "copy",
160
- output_path, "-y"
161
- ]
162
- try:
163
- subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
164
- if os.path.exists(output_path) and os.path.getsize(output_path) > 1024:
165
- return output_path
166
- except Exception as e:
167
- print(f"Watermark Error: {e}")
168
- return input_path
169
-
170
  def generate_auto_thumb(video_path: str, thumb_path: str):
171
  try:
172
  cmd = [
@@ -388,7 +449,7 @@ async def init_clone_workflow(client: Client, message: Message, is_topic_mode: b
388
  try:
389
  target_chat = int(dest_val)
390
  except ValueError:
391
- target_chat = dest_val.replace("https://t.me/", "@")
392
 
393
  start_num = min(s_id, e_id)
394
  end_num = max(s_id, e_id)
@@ -404,8 +465,7 @@ async def init_clone_workflow(client: Client, message: Message, is_topic_mode: b
404
  "extra_caption": None,
405
  "replace_find": None,
406
  "replace_with": None,
407
- "thumb_path": None,
408
- "watermark_text": None
409
  }
410
  await show_customization_menu(client, user_id)
411
 
@@ -415,7 +475,6 @@ async def show_customization_menu(client: Client, user_id: int):
415
  ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
416
  thm_status = "सेट है ✅" if data.get("thumb_path") else "मूल (Default)"
417
  rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
418
- wm_status = f"`{data.get('watermark_text')}` (5-कलर स्क्रोलिंग) ✅" if data.get("watermark_text") else "कोई नहीं"
419
  dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
420
  mode_display = "🔥 ऑटो-टॉपिक मोड" if data.get("is_topic_mode") else "🚀 डायरेक्ट मोड"
421
  total_count = data.get('end_id', 0) - data.get('start_id', 0) + 1
@@ -428,7 +487,6 @@ async def show_customization_menu(client: Client, user_id: int):
428
  f"🔄 रिप्लेस टेक्स्ट: {rep_status}\n"
429
  f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
430
  f"🖼️ कस्टम थंबनेल: `{thm_status}`\n"
431
- f"🏷️ रनिंग वीडियो वॉटरमार्क: {wm_status}\n"
432
  f"📍 टारगेट डेस्टिनेशन: {dest_display}\n"
433
  f"📊 कुल संदेश रेंज: `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_count} फाइल्स)\n"
434
  "━━━━━━━━━━━━━━━━━━━━\n"
@@ -439,16 +497,15 @@ async def show_customization_menu(client: Client, user_id: int):
439
  InlineKeyboardButton("🔄 Replace Text", callback_data="set_replace")],
440
  [InlineKeyboardButton("➕ Add Extra", callback_data="set_extra"),
441
  InlineKeyboardButton("🖼️ Set Thumbnail", callback_data="set_thumb")],
442
- [InlineKeyboardButton("🏷️ Set Video Watermark", callback_data="set_wm"),
443
- InlineKeyboardButton("🗑️ Clear Settings", callback_data="clear_settings")],
444
- [InlineKeyboardButton("🚀 Confirm & Start", callback_data="confirm_start")]
445
  ])
446
  await client.send_message(user_id, panel_text, reply_markup=buttons)
447
 
448
  @Client.on_callback_query()
449
  async def callback_handler(client: Client, query: CallbackQuery):
450
  user_id = query.from_user.id
451
- if query.data.startswith("nav_") or query.data.startswith("bc_") or query.data.startswith("setlang_"):
452
  return
453
 
454
  if user_id not in batch_temp.CLONE_DATA:
@@ -486,23 +543,11 @@ async def callback_handler(client: Client, query: CallbackQuery):
486
  batch_temp.CLONE_DATA[user_id]["thumb_path"] = thumb_file
487
  await msg.reply_text("✅ थंबनेल सेव कर लिया गया!")
488
  await show_customization_menu(client, user_id)
489
- elif data == "set_wm":
490
- await query.message.delete()
491
- msg = await client.ask(
492
- user_id,
493
- "🏷️ **वीडियो रनिंग वॉटरमार्क के लिए नाम भेजें:**\n(उदा: `SACHIN SHARMA`)",
494
- filters=filters.text,
495
- timeout=180
496
- )
497
- if msg.text != "/cancel":
498
- batch_temp.CLONE_DATA[user_id]["watermark_text"] = msg.text.strip().upper()
499
- await show_customization_menu(client, user_id)
500
  elif data == "clear_settings":
501
  batch_temp.CLONE_DATA[user_id]["custom_caption"] = None
502
  batch_temp.CLONE_DATA[user_id]["extra_caption"] = None
503
  batch_temp.CLONE_DATA[user_id]["replace_find"] = None
504
  batch_temp.CLONE_DATA[user_id]["replace_with"] = None
505
- batch_temp.CLONE_DATA[user_id]["watermark_text"] = None
506
  tpath = batch_temp.CLONE_DATA[user_id].get("thumb_path")
507
  if tpath and os.path.exists(tpath):
508
  os.remove(tpath)
@@ -789,12 +834,6 @@ async def process_media(
789
  if not file_path or not os.path.exists(file_path):
790
  return False, 0, None
791
 
792
- wm_text = task.get("watermark_text")
793
- if wm_text and msg.video:
794
- await status_msg.edit_text(f"🏷️ **Applying Watermark:** `{wm_text}`...")
795
- wm_output_path = os.path.join(user_down_dir, f"wm_{file_name}")
796
- file_path = apply_video_watermark(file_path, wm_output_path, wm_text)
797
-
798
  size = os.path.getsize(file_path)
799
  up_start = time.time()
800
  await status_msg.edit_text(f"📤 **Uploading:** `{file_name}`\n⏳ (फाइल {current_idx} / {total_msgs})...")
 
77
  t_n += 1
78
  return f"{round(size, 2)} {power_labels[t_n]}B"
79
 
80
+ def time_formatter(seconds: int) -> str:
81
+ minutes, seconds = divmod(seconds, 60)
82
+ hours, minutes = divmod(minutes, 60)
83
+ days, hours = divmod(hours, 24)
84
+ tmp = ((str(days) + "d, ") if days else "") + \
85
+ ((str(hours) + "h, ") if hours else "") + \
86
+ स्क्रीनशॉट में साफ़ दिख रहा है कि फ़ाइल 18 मिनट से लटकी हुई है और स्पीड **317 KB/s** पर गिर गई है[span_2](start_span)[span_2](end_span)।
87
+
88
+ ### यह समस्या क्यों आई थी?
89
+ 1. **वॉटरमार्क री-एन्कोडिंग (FFmpeg Bottleneck):** 775 MB की वीडियो फ़ाइल पर जब FFmpeg प्रोसेस चला, तो CPU 100% पर जाकर चोक हो गया। इससे सिस्टम की सारी मेमोरी और थ्रेड्स जाम हो गए और अपलोड पाइपलाइन की स्पीड 317 KB/s पर आ गई[span_3](start_span)[span_3](end_span)।
90
+ 2. **वॉटरमार्क इनपुट स्टेप:** यूज़र से बार-बार वॉटरमार्क का नाम पूछने के कारण वर्कफ़्लो अनावश्यक रूप से लंबा और धीमा हो रहा था[span_4](start_span)[span_4](end_span)।
91
+
92
+ ---
93
+
94
+ ### किए गए बदलाव:
95
+ 1. **वॉटरमार्क पूरी तरह हटा दिया गया:** स्टेप 3 के बाद सीधे ट्रांसफर शुरू होगा (कोई वॉटरमार्क प्रॉम्प्ट नहीं आएगा)। FFmpeg का लोड 0% हो जाएगा।
96
+ 2. **सीधा तेज़ ट्रांसमिशन:** डाउनलोड हुई फ़ाइल बिना किसी री-एन्कोडिंग के सीधे टेलीग्राम सर्वर पर हाई-स्पीड मल्टी-पार्ट में अपलोड होगी।
97
+ 3. **बाकी सभी फ़ीचर्स सुरक्षित:** `/clone`, `/topicclone`, ओरिजिनल कैप्शन, फ़ोर्स सब्सक्राइब, बिना ID वाला फ़ाइल नाम और सारी 17 कमांड्स पहले की तरह काम करेंगी।
98
+
99
+ आपको केवल **`TechVJ/start.py`** फ़ाइल अपडेट करनी है।
100
+
101
+ ---
102
+
103
+ ### फ़ाइल: `TechVJ/start.py`
104
+
105
+ Hugging Face में `TechVJ/start.py` खोलें और यह संपूर्ण कोड पेस्ट करके **Commit changes** कर दें:
106
+
107
+ ```python
108
+ import os
109
+ import asyncio
110
+ import time
111
+ import math
112
+ import re
113
+ import subprocess
114
+ from pyrogram import Client, filters, enums
115
+ from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
116
+ from pyrogram.errors import (
117
+ FloodWait,
118
+ RPCError,
119
+ ChatAdminRequired,
120
+ RightForbidden,
121
+ UserNotParticipant
122
+ )
123
+ from pyrogram.raw.functions.channels import GetForumTopicsByID, CreateForumTopic
124
+ from config import API_ID, API_HASH, ADMINS, CHANNEL_ID, WAITING_TIME, FORCE_SUB_CHANNEL
125
+ from db import db
126
+
127
+ try:
128
+ from TechVJ.TechVJ.fast_download import fast_download_file, fast_upload_file
129
+ except ImportError:
130
+ try:
131
+ from TechVJ.fast_download import fast_download_file, fast_upload_file
132
+ except ImportError:
133
+ from fast_download import fast_download_file, fast_upload_file
134
+
135
+ class batch_temp(object):
136
+ IS_BATCH = {}
137
+ CLONE_DATA = {}
138
+ LAST_SAVED_ID = {}
139
+ CREATED_TOPICS = {}
140
+
141
+ async def is_user_subscribed(client: Client, user_id: int) -> bool:
142
+ if not FORCE_SUB_CHANNEL:
143
+ return True
144
+ try:
145
+ member = await client.get_chat_member(FORCE_SUB_CHANNEL, user_id)
146
+ if member.status in [enums.ChatMemberStatus.MEMBER, enums.ChatMemberStatus.ADMINISTRATOR, enums.ChatMemberStatus.OWNER]:
147
+ return True
148
+ return False
149
+ except UserNotParticipant:
150
+ return False
151
+ except Exception as e:
152
+ print(f"Force Sub Error: {e}")
153
+ return True
154
+
155
+ async def send_force_sub_message(client: Client, message: Message):
156
+ invite_link = None
157
+ try:
158
+ chat = await client.get_chat(FORCE_SUB_CHANNEL)
159
+ invite_link = chat.invite_link or (f"[https://t.me/](https://t.me/){chat.username}" if chat.username else None)
160
+ except Exception:
161
+ pass
162
+
163
+ if not invite_link:
164
+ invite_link = "[https://t.me/](https://t.me/)"
165
+
166
+ buttons = InlineKeyboardMarkup([
167
+ [InlineKeyboardButton("📢 चैनल जॉइन करें", url=invite_link)],
168
+ [InlineKeyboardButton("🔄 मैंने जॉइन कर लिया (Retry)", callback_data="check_fsub")]
169
+ ])
170
+ await message.reply_text(
171
+ "⚠️ **बॉट का इस्तेमाल करने के लिए आपको हमारे चैनल को जॉइन करना होगा!**\n\n"
172
+ "कृपया नीचे दिए गए बटन से चैनल जॉइन करें और फिर दोबारा प्रयास करें।",
173
+ reply_markup=buttons
174
+ )
175
+
176
+ def humanbytes(size):
177
+ if not size:
178
+ return "0 B"
179
+ power = 1024
180
+ t_n = 0
181
+ power_labels = {0: ' ', 1: 'K', 2: 'M', 3: 'G', 4: 'T'}
182
+ while size > power:
183
+ size /= power
184
+ t_n += 1
185
+ return f"{round(size, 2)} {power_labels[t_n]}B"
186
+
187
  def time_formatter(seconds: int) -> str:
188
  minutes, seconds = divmod(seconds, 60)
189
  hours, minutes = divmod(minutes, 60)
 
228
  except Exception:
229
  pass
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  def generate_auto_thumb(video_path: str, thumb_path: str):
232
  try:
233
  cmd = [
 
449
  try:
450
  target_chat = int(dest_val)
451
  except ValueError:
452
+ target_chat = dest_val.replace("[https://t.me/](https://t.me/)", "@")
453
 
454
  start_num = min(s_id, e_id)
455
  end_num = max(s_id, e_id)
 
465
  "extra_caption": None,
466
  "replace_find": None,
467
  "replace_with": None,
468
+ "thumb_path": None
 
469
  }
470
  await show_customization_menu(client, user_id)
471
 
 
475
  ext_status = "सेट है ✅" if data.get("extra_caption") else "कोई नहीं"
476
  thm_status = "सेट है ✅" if data.get("thumb_path") else "मूल (Default)"
477
  rep_status = f"`{data.get('replace_find')}` ➔ `{data.get('replace_with')}`" if data.get("replace_find") else "कोई नहीं"
 
478
  dest_display = "सीधे बॉट चैट (Direct Bot)" if data.get("is_direct_bot") else f"`{data.get('target_chat')}`"
479
  mode_display = "🔥 ऑटो-टॉपिक मोड" if data.get("is_topic_mode") else "🚀 डायरेक्ट मोड"
480
  total_count = data.get('end_id', 0) - data.get('start_id', 0) + 1
 
487
  f"🔄 रिप्लेस टेक्स्ट: {rep_status}\n"
488
  f"➕ अतिरिक्त कैप्शन: `{ext_status}`\n"
489
  f"🖼️ कस्टम थंबनेल: `{thm_status}`\n"
 
490
  f"📍 टारगेट डेस्टिनेशन: {dest_display}\n"
491
  f"📊 कुल संदेश रेंज: `{data.get('start_id')}` से `{data.get('end_id')}` (कुल {total_count} फाइल्स)\n"
492
  "━━━━━━━━━━━━━━━━━━━━\n"
 
497
  InlineKeyboardButton("🔄 Replace Text", callback_data="set_replace")],
498
  [InlineKeyboardButton("➕ Add Extra", callback_data="set_extra"),
499
  InlineKeyboardButton("🖼️ Set Thumbnail", callback_data="set_thumb")],
500
+ [InlineKeyboardButton("🗑️ Clear Settings", callback_data="clear_settings"),
501
+ InlineKeyboardButton("🚀 Confirm & Start", callback_data="confirm_start")]
 
502
  ])
503
  await client.send_message(user_id, panel_text, reply_markup=buttons)
504
 
505
  @Client.on_callback_query()
506
  async def callback_handler(client: Client, query: CallbackQuery):
507
  user_id = query.from_user.id
508
+ if query.data.startswith("nav_") or query.data.startswith("bc_") or query.data.startswith("setlang_") or query.data == "check_fsub":
509
  return
510
 
511
  if user_id not in batch_temp.CLONE_DATA:
 
543
  batch_temp.CLONE_DATA[user_id]["thumb_path"] = thumb_file
544
  await msg.reply_text("✅ थंबनेल सेव कर लिया गया!")
545
  await show_customization_menu(client, user_id)
 
 
 
 
 
 
 
 
 
 
 
546
  elif data == "clear_settings":
547
  batch_temp.CLONE_DATA[user_id]["custom_caption"] = None
548
  batch_temp.CLONE_DATA[user_id]["extra_caption"] = None
549
  batch_temp.CLONE_DATA[user_id]["replace_find"] = None
550
  batch_temp.CLONE_DATA[user_id]["replace_with"] = None
 
551
  tpath = batch_temp.CLONE_DATA[user_id].get("thumb_path")
552
  if tpath and os.path.exists(tpath):
553
  os.remove(tpath)
 
834
  if not file_path or not os.path.exists(file_path):
835
  return False, 0, None
836
 
 
 
 
 
 
 
837
  size = os.path.getsize(file_path)
838
  up_start = time.time()
839
  await status_msg.edit_text(f"📤 **Uploading:** `{file_name}`\n⏳ (फाइल {current_idx} / {total_msgs})...")