Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -602,7 +602,8 @@ async def handle_media_upload(client, message):
|
|
| 602 |
await process_broadcast(client, message)
|
| 603 |
return
|
| 604 |
|
| 605 |
-
|
|
|
|
| 606 |
has_blur_caption = message.caption and "/blur" in message.caption.lower()
|
| 607 |
is_persistent_blur = bool(state.get("blur_percent"))
|
| 608 |
|
|
@@ -642,8 +643,10 @@ async def handle_media_upload(client, message):
|
|
| 642 |
|
| 643 |
is_large_video = False
|
| 644 |
if media_type == "video":
|
| 645 |
-
|
| 646 |
-
|
|
|
|
|
|
|
| 647 |
MAX_DURATION = 7200
|
| 648 |
MAX_SIZE = 1900 * 1024 * 1024
|
| 649 |
|
|
@@ -691,15 +694,13 @@ async def handle_media_upload(client, message):
|
|
| 691 |
if process.returncode == 0 and os.path.exists(watermarked_file):
|
| 692 |
clean_upload_file = watermarked_file
|
| 693 |
|
| 694 |
-
# ২. আপনার নিজের
|
| 695 |
storage_msg_id = None
|
| 696 |
-
if media_type in ["video", "
|
| 697 |
await status_msg.edit_text(f"⏳ Uploading {media_type} to your storage channel...")
|
| 698 |
|
| 699 |
if media_type == "photo":
|
| 700 |
sent_to_channel = await client.send_photo(chat_id=STORAGE_CHANNEL_ID, photo=clean_upload_file, caption="Backup of photo uploaded by Admin.")
|
| 701 |
-
elif media_type == "animation":
|
| 702 |
-
sent_to_channel = await client.send_animation(chat_id=STORAGE_CHANNEL_ID, animation=clean_upload_file, caption="Backup of GIF uploaded by Admin.")
|
| 703 |
else:
|
| 704 |
sent_to_channel = await client.send_video(chat_id=STORAGE_CHANNEL_ID, video=clean_upload_file, caption=f"Backup of video uploaded by Admin. File: {os.path.basename(clean_upload_file)}")
|
| 705 |
|
|
@@ -734,8 +735,6 @@ async def handle_media_upload(client, message):
|
|
| 734 |
|
| 735 |
if media_type == "photo":
|
| 736 |
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + [blurred_file]
|
| 737 |
-
elif media_type == "animation":
|
| 738 |
-
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + ["-c:v", "libx264", "-preset", "superfast", "-pix_fmt", "yuv420p", blurred_file]
|
| 739 |
else:
|
| 740 |
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + ["-c:v", "libx264", "-preset", "superfast", "-crf", "23", "-pix_fmt", "yuv420p", "-c:a", "copy", "-movflags", "+faststart", blurred_file]
|
| 741 |
|
|
@@ -768,12 +767,12 @@ async def handle_media_upload(client, message):
|
|
| 768 |
|
| 769 |
if media_type == "photo":
|
| 770 |
sent_to_admin = await client.send_photo(message.chat.id, telegram_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML)
|
| 771 |
-
elif media_type == "animation":
|
| 772 |
-
sent_to_admin = await client.send_animation(message.chat.id, telegram_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML)
|
| 773 |
else:
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
|
|
|
|
|
|
| 777 |
|
| 778 |
sent_to_admin = await client.send_video(
|
| 779 |
message.chat.id,
|
|
@@ -801,7 +800,6 @@ async def handle_media_upload(client, message):
|
|
| 801 |
for gid in set(group_ids):
|
| 802 |
try:
|
| 803 |
if media_type == "photo": await client.send_photo(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 804 |
-
elif media_type == "animation": await client.send_animation(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 805 |
else: await client.send_video(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 806 |
success_count += 1
|
| 807 |
await asyncio.sleep(1.5)
|
|
@@ -809,7 +807,6 @@ async def handle_media_upload(client, message):
|
|
| 809 |
await asyncio.sleep(e.value + 1)
|
| 810 |
try:
|
| 811 |
if media_type == "photo": await client.send_photo(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 812 |
-
elif media_type == "animation": await client.send_animation(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 813 |
else: await client.send_video(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 814 |
success_count += 1
|
| 815 |
except Exception:
|
|
|
|
| 602 |
await process_broadcast(client, message)
|
| 603 |
return
|
| 604 |
|
| 605 |
+
# FORCE ANIMATIONS (GIFS) TO BE TREATED AS VIDEOS FOR BROADCAST STABILITY
|
| 606 |
+
media_type = "video" if (message.video or message.animation) else "photo"
|
| 607 |
has_blur_caption = message.caption and "/blur" in message.caption.lower()
|
| 608 |
is_persistent_blur = bool(state.get("blur_percent"))
|
| 609 |
|
|
|
|
| 643 |
|
| 644 |
is_large_video = False
|
| 645 |
if media_type == "video":
|
| 646 |
+
# Safe size checks for both Videos and Animations (GIFs)
|
| 647 |
+
media = get_media_obj(message)
|
| 648 |
+
duration = media.duration if media and hasattr(media, 'duration') and media.duration else 0
|
| 649 |
+
file_size = media.file_size if media and hasattr(media, 'file_size') and media.file_size else 0
|
| 650 |
MAX_DURATION = 7200
|
| 651 |
MAX_SIZE = 1900 * 1024 * 1024
|
| 652 |
|
|
|
|
| 694 |
if process.returncode == 0 and os.path.exists(watermarked_file):
|
| 695 |
clean_upload_file = watermarked_file
|
| 696 |
|
| 697 |
+
# ২. আপনার নিজের চ্যানেলে ফাইল আপলোড (ভিডিও বা অ্যানিমেশন)
|
| 698 |
storage_msg_id = None
|
| 699 |
+
if media_type in ["video", "photo"]:
|
| 700 |
await status_msg.edit_text(f"⏳ Uploading {media_type} to your storage channel...")
|
| 701 |
|
| 702 |
if media_type == "photo":
|
| 703 |
sent_to_channel = await client.send_photo(chat_id=STORAGE_CHANNEL_ID, photo=clean_upload_file, caption="Backup of photo uploaded by Admin.")
|
|
|
|
|
|
|
| 704 |
else:
|
| 705 |
sent_to_channel = await client.send_video(chat_id=STORAGE_CHANNEL_ID, video=clean_upload_file, caption=f"Backup of video uploaded by Admin. File: {os.path.basename(clean_upload_file)}")
|
| 706 |
|
|
|
|
| 735 |
|
| 736 |
if media_type == "photo":
|
| 737 |
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + [blurred_file]
|
|
|
|
|
|
|
| 738 |
else:
|
| 739 |
cmd_blur = ["ffmpeg", "-y", "-i", clean_upload_file] + ff_filter + ["-c:v", "libx264", "-preset", "superfast", "-crf", "23", "-pix_fmt", "yuv420p", "-c:a", "copy", "-movflags", "+faststart", blurred_file]
|
| 740 |
|
|
|
|
| 767 |
|
| 768 |
if media_type == "photo":
|
| 769 |
sent_to_admin = await client.send_photo(message.chat.id, telegram_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML)
|
|
|
|
|
|
|
| 770 |
else:
|
| 771 |
+
# Safe dimensions extraction for Videos and Animations
|
| 772 |
+
media = get_media_obj(message)
|
| 773 |
+
vid_duration = media.duration if media and hasattr(media, 'duration') and media.duration else 0
|
| 774 |
+
vid_width = media.width if media and hasattr(media, 'width') and media.width else 0
|
| 775 |
+
vid_height = media.height if media and hasattr(media, 'height') and media.height else 0
|
| 776 |
|
| 777 |
sent_to_admin = await client.send_video(
|
| 778 |
message.chat.id,
|
|
|
|
| 800 |
for gid in set(group_ids):
|
| 801 |
try:
|
| 802 |
if media_type == "photo": await client.send_photo(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
|
|
|
| 803 |
else: await client.send_video(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 804 |
success_count += 1
|
| 805 |
await asyncio.sleep(1.5)
|
|
|
|
| 807 |
await asyncio.sleep(e.value + 1)
|
| 808 |
try:
|
| 809 |
if media_type == "photo": await client.send_photo(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
|
|
|
| 810 |
else: await client.send_video(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup)
|
| 811 |
success_count += 1
|
| 812 |
except Exception:
|