Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -369,7 +369,8 @@ async def handle_media_upload(client, message):
|
|
| 369 |
bot_me = client.me if client.me else await client.get_me()
|
| 370 |
bot_link = f"https://t.me/{bot_me.username}"
|
| 371 |
|
| 372 |
-
original_file, watermarked_file, blurred_file
|
|
|
|
| 373 |
|
| 374 |
# === Progress Bar Function ===
|
| 375 |
last_update_time = time.time()
|
|
@@ -387,9 +388,9 @@ async def handle_media_upload(client, message):
|
|
| 387 |
|
| 388 |
try:
|
| 389 |
original_file = await message.download(progress=download_progress)
|
| 390 |
-
|
| 391 |
|
| 392 |
-
#
|
| 393 |
if media_type == "video" and not is_large_video:
|
| 394 |
await status_msg.edit_text("⏳ Watermarking video... (High Quality Processing)")
|
| 395 |
watermarked_file = f"{original_file}_wm.mp4"
|
|
@@ -401,42 +402,19 @@ async def handle_media_upload(client, message):
|
|
| 401 |
]
|
| 402 |
process = await asyncio.create_subprocess_exec(*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
| 403 |
await process.communicate()
|
| 404 |
-
if process.returncode == 0 and os.path.exists(watermarked_file):
|
| 405 |
-
|
| 406 |
-
if is_blur and not is_large_video:
|
| 407 |
-
await status_msg.edit_text(f"⏳ Applying {blur_percent}% blur... (High Quality Processing)")
|
| 408 |
-
radius = max(2, min(20, int((blur_percent / 100.0) * 30)))
|
| 409 |
-
ext = "jpg" if media_type == "photo" else "mp4"
|
| 410 |
-
blurred_file = f"{original_file}_blurred.{ext}"
|
| 411 |
-
|
| 412 |
-
if clear_percent > 0:
|
| 413 |
-
clear_ratio = clear_percent / 100.0
|
| 414 |
-
ff_filter = ["-filter_complex", f"[0:v]split[v1][v2];[v2]boxblur={radius}:1[blurred];[v1]crop=iw:ih*{clear_ratio}:0:0[top];[blurred][top]overlay=0:0[vout]", "-map", "[vout]"]
|
| 415 |
-
if media_type == "video":
|
| 416 |
-
ff_filter.extend(["-map", "0:a?"])
|
| 417 |
-
else:
|
| 418 |
-
ff_filter = ["-vf", f"boxblur={radius}:1"]
|
| 419 |
-
|
| 420 |
-
if media_type == "photo":
|
| 421 |
-
cmd_blur = ["ffmpeg", "-y", "-i", final_file] + ff_filter + [blurred_file]
|
| 422 |
-
elif media_type == "animation":
|
| 423 |
-
cmd_blur = ["ffmpeg", "-y", "-i", final_file] + ff_filter + ["-c:v", "libx264", "-preset", "fast", "-threads", "2", "-pix_fmt", "yuv420p", blurred_file]
|
| 424 |
-
else:
|
| 425 |
-
cmd_blur = ["ffmpeg", "-y", "-i", final_file] + ff_filter + ["-c:v", "libx264", "-preset", "fast", "-threads", "2", "-crf", "22", "-pix_fmt", "yuv420p", "-c:a", "copy", "-movflags", "+faststart", blurred_file]
|
| 426 |
-
|
| 427 |
-
process_blur = await asyncio.create_subprocess_exec(*cmd_blur, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
| 428 |
-
await process_blur.communicate()
|
| 429 |
-
if process_blur.returncode == 0 and os.path.exists(blurred_file): final_file = blurred_file
|
| 430 |
|
|
|
|
| 431 |
if media_type == "video":
|
| 432 |
-
await status_msg.edit_text("⏳ Uploading video to byse.sx server...")
|
| 433 |
api_endpoint = "https://api.byse.sx/upload/server"
|
| 434 |
loop = asyncio.get_event_loop()
|
| 435 |
response = await loop.run_in_executor(None, lambda: requests.get(api_endpoint, params={'key': BYSE_API_KEY}, timeout=30))
|
| 436 |
result = response.json()
|
| 437 |
|
| 438 |
if result.get('status') == 200:
|
| 439 |
-
upload_res = await loop.run_in_executor(None, upload_file_sync, result.get('result'),
|
| 440 |
if upload_res.get('status') == 200 and 'files' in upload_res and len(upload_res['files']) > 0:
|
| 441 |
file_status = upload_res['files'][0].get('status', '')
|
| 442 |
if "not allowed" in str(file_status).lower():
|
|
@@ -455,6 +433,34 @@ async def handle_media_upload(client, message):
|
|
| 455 |
await status_msg.delete()
|
| 456 |
return
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
await status_msg.edit_text("⏳ Preparing to broadcast to groups...")
|
| 459 |
if media_type == "video":
|
| 460 |
caption_text = f"🔥 <b>New Premium Viral Video Leaked!</b> 🔞\n\n🎬 <b>Watch HD Video Here:</b>\n👉 <b><a href='{embed_link if is_blur else bot_link}'>▶️ Click Here to Watch</a></b>\n\n👇 <i>Click the button below to open Bot!</i>"
|
|
@@ -462,20 +468,20 @@ async def handle_media_upload(client, message):
|
|
| 462 |
caption_text = f"{clean_caption}\n\n👇 <i>Click the button below to open Bot!</i>" if clean_caption else f"🔥 <b>New Premium Viral Content!</b> 🔞\n\n🎬 <b>Watch HD Video Here:</b>\n👉 <b><a href='{bot_link}'>▶️ Click Here to Watch</a></b>\n\n👇 <i>Click the button below to open Bot!</i>"
|
| 463 |
|
| 464 |
group_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🎬 Watch Full Video Here 🔞", url=bot_link)]])
|
| 465 |
-
admin_cap = f"✅ <b>Success!</b> Media is broadcasting...\n\n🔗 <b>Embed Link:</b>\n<code>{embed_link or 'N/A'}</code>"
|
| 466 |
|
| 467 |
thumb_path = None
|
| 468 |
if media_type == "video":
|
| 469 |
thumb_path = f"{original_file}_thumb.jpg"
|
| 470 |
-
proc = await asyncio.create_subprocess_exec("ffmpeg", "-y", "-i",
|
| 471 |
await proc.communicate()
|
| 472 |
if not os.path.exists(thumb_path): thumb_path = None
|
| 473 |
|
| 474 |
if media_type == "photo":
|
| 475 |
-
sent_to_admin = await client.send_photo(message.chat.id,
|
| 476 |
tg_file_id = sent_to_admin.photo.file_id
|
| 477 |
elif media_type == "animation":
|
| 478 |
-
sent_to_admin = await client.send_animation(message.chat.id,
|
| 479 |
tg_file_id = sent_to_admin.animation.file_id
|
| 480 |
else:
|
| 481 |
vid_duration = message.video.duration if message.video and message.video.duration else 0
|
|
@@ -484,7 +490,7 @@ async def handle_media_upload(client, message):
|
|
| 484 |
|
| 485 |
sent_to_admin = await client.send_video(
|
| 486 |
message.chat.id,
|
| 487 |
-
|
| 488 |
caption=admin_cap,
|
| 489 |
parse_mode=enums.ParseMode.HTML,
|
| 490 |
duration=vid_duration,
|
|
|
|
| 369 |
bot_me = client.me if client.me else await client.get_me()
|
| 370 |
bot_link = f"https://t.me/{bot_me.username}"
|
| 371 |
|
| 372 |
+
original_file, watermarked_file, blurred_file = None, None, None
|
| 373 |
+
clean_upload_file, telegram_file, embed_link = None, None, None
|
| 374 |
|
| 375 |
# === Progress Bar Function ===
|
| 376 |
last_update_time = time.time()
|
|
|
|
| 388 |
|
| 389 |
try:
|
| 390 |
original_file = await message.download(progress=download_progress)
|
| 391 |
+
clean_upload_file = original_file # ডিফল্টভাবে অরিজিনাল ফাইলই ক্লিন ফাইল
|
| 392 |
|
| 393 |
+
# ১. ওয়াটারমার্ক (Watermark) করা - HD Quality
|
| 394 |
if media_type == "video" and not is_large_video:
|
| 395 |
await status_msg.edit_text("⏳ Watermarking video... (High Quality Processing)")
|
| 396 |
watermarked_file = f"{original_file}_wm.mp4"
|
|
|
|
| 402 |
]
|
| 403 |
process = await asyncio.create_subprocess_exec(*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
| 404 |
await process.communicate()
|
| 405 |
+
if process.returncode == 0 and os.path.exists(watermarked_file):
|
| 406 |
+
clean_upload_file = watermarked_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
+
# ২. byse.sx সার্ভারে HD / Clean ভিডিও আপলোড করা
|
| 409 |
if media_type == "video":
|
| 410 |
+
await status_msg.edit_text("⏳ Uploading Clean HD video to byse.sx server...")
|
| 411 |
api_endpoint = "https://api.byse.sx/upload/server"
|
| 412 |
loop = asyncio.get_event_loop()
|
| 413 |
response = await loop.run_in_executor(None, lambda: requests.get(api_endpoint, params={'key': BYSE_API_KEY}, timeout=30))
|
| 414 |
result = response.json()
|
| 415 |
|
| 416 |
if result.get('status') == 200:
|
| 417 |
+
upload_res = await loop.run_in_executor(None, upload_file_sync, result.get('result'), clean_upload_file, BYSE_API_KEY)
|
| 418 |
if upload_res.get('status') == 200 and 'files' in upload_res and len(upload_res['files']) > 0:
|
| 419 |
file_status = upload_res['files'][0].get('status', '')
|
| 420 |
if "not allowed" in str(file_status).lower():
|
|
|
|
| 433 |
await status_msg.delete()
|
| 434 |
return
|
| 435 |
|
| 436 |
+
# ৩. টেলিগ্রামে পাঠানোর জন্য ভিডিও ব্লার করা (যদি ব্লার অন থাকে)
|
| 437 |
+
telegram_file = clean_upload_file
|
| 438 |
+
if is_blur and not is_large_video:
|
| 439 |
+
await status_msg.edit_text(f"⏳ Applying {blur_percent}% blur for Telegram broadcast...")
|
| 440 |
+
radius = max(2, min(20, int((blur_percent / 100.0) * 30)))
|
| 441 |
+
ext = "jpg" if media_type == "photo" else "mp4"
|
| 442 |
+
blurred_file = f"{original_file}_blurred.{ext}"
|
| 443 |
+
|
| 444 |
+
if clear_percent > 0:
|
| 445 |
+
clear_ratio = clear_percent / 100.0
|
| 446 |
+
ff_filter = ["-filter_complex", f"[0:v]split[v1][v2];[v2]boxblur={radius}:1[blurred];[v1]crop=iw:ih*{clear_ratio}:0:0[top];[blurred][top]overlay=0:0[vout]", "-map", "[vout]"]
|
| 447 |
+
if media_type == "video":
|
| 448 |
+
ff_filter.extend(["-map", "0:a?"])
|
| 449 |
+
else:
|
| 450 |
+
ff_filter = ["-vf", f"boxblur={radius}:1"]
|
| 451 |
+
|
| 452 |
+
if media_type == "photo":
|
| 453 |
+
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + [blurred_file]
|
| 454 |
+
elif media_type == "animation":
|
| 455 |
+
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + ["-c:v", "libx264", "-preset", "fast", "-threads", "2", "-pix_fmt", "yuv420p", blurred_file]
|
| 456 |
+
else:
|
| 457 |
+
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + ["-c:v", "libx264", "-preset", "fast", "-threads", "2", "-crf", "22", "-pix_fmt", "yuv420p", "-c:a", "copy", "-movflags", "+faststart", blurred_file]
|
| 458 |
+
|
| 459 |
+
process_blur = await asyncio.create_subprocess_exec(*cmd_blur, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
| 460 |
+
await process_blur.communicate()
|
| 461 |
+
if process_blur.returncode == 0 and os.path.exists(blurred_file):
|
| 462 |
+
telegram_file = blurred_file
|
| 463 |
+
|
| 464 |
await status_msg.edit_text("⏳ Preparing to broadcast to groups...")
|
| 465 |
if media_type == "video":
|
| 466 |
caption_text = f"🔥 <b>New Premium Viral Video Leaked!</b> 🔞\n\n🎬 <b>Watch HD Video Here:</b>\n👉 <b><a href='{embed_link if is_blur else bot_link}'>▶️ Click Here to Watch</a></b>\n\n👇 <i>Click the button below to open Bot!</i>"
|
|
|
|
| 468 |
caption_text = f"{clean_caption}\n\n👇 <i>Click the button below to open Bot!</i>" if clean_caption else f"🔥 <b>New Premium Viral Content!</b> 🔞\n\n🎬 <b>Watch HD Video Here:</b>\n👉 <b><a href='{bot_link}'>▶️ Click Here to Watch</a></b>\n\n👇 <i>Click the button below to open Bot!</i>"
|
| 469 |
|
| 470 |
group_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🎬 Watch Full Video Here 🔞", url=bot_link)]])
|
| 471 |
+
admin_cap = f"✅ <b>Success!</b> Media is broadcasting...\n\n🔗 <b>Embed Link (Clean HD):</b>\n<code>{embed_link or 'N/A'}</code>"
|
| 472 |
|
| 473 |
thumb_path = None
|
| 474 |
if media_type == "video":
|
| 475 |
thumb_path = f"{original_file}_thumb.jpg"
|
| 476 |
+
proc = await asyncio.create_subprocess_exec("ffmpeg", "-y", "-i", telegram_file, "-vframes", "1", thumb_path, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
| 477 |
await proc.communicate()
|
| 478 |
if not os.path.exists(thumb_path): thumb_path = None
|
| 479 |
|
| 480 |
if media_type == "photo":
|
| 481 |
+
sent_to_admin = await client.send_photo(message.chat.id, telegram_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML)
|
| 482 |
tg_file_id = sent_to_admin.photo.file_id
|
| 483 |
elif media_type == "animation":
|
| 484 |
+
sent_to_admin = await client.send_animation(message.chat.id, telegram_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML)
|
| 485 |
tg_file_id = sent_to_admin.animation.file_id
|
| 486 |
else:
|
| 487 |
vid_duration = message.video.duration if message.video and message.video.duration else 0
|
|
|
|
| 490 |
|
| 491 |
sent_to_admin = await client.send_video(
|
| 492 |
message.chat.id,
|
| 493 |
+
telegram_file,
|
| 494 |
caption=admin_cap,
|
| 495 |
parse_mode=enums.ParseMode.HTML,
|
| 496 |
duration=vid_duration,
|