Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1097,6 +1097,7 @@ async def process_single_video(task, redis_client):
|
|
| 1097 |
print(f"▶️ [WM] Task Started for User: {owner_id}, Msg: {message_id}")
|
| 1098 |
|
| 1099 |
clone_client = Client(f"clone_wm_{task_id}", bot_token=clone_token, api_id=API_ID, api_hash=API_HASH, in_memory=True)
|
|
|
|
| 1100 |
|
| 1101 |
try:
|
| 1102 |
await clone_client.start()
|
|
@@ -1106,13 +1107,13 @@ async def process_single_video(task, redis_client):
|
|
| 1106 |
if not msg or not (msg.video or msg.document):
|
| 1107 |
raise Exception("Video not found or deleted by user.")
|
| 1108 |
|
| 1109 |
-
status_msg = await clone_client.send_message(owner_id, "⏳ <b>
|
| 1110 |
print(f"▶️ [WM] Status Message Sent to User")
|
| 1111 |
|
| 1112 |
raw_video_path = await clone_client.download_media(msg)
|
| 1113 |
print(f"▶️ [WM] Original Video Downloaded: {raw_video_path}")
|
| 1114 |
|
| 1115 |
-
await clone_client.edit_message_text(owner_id, status_msg.id, "⏳ <b>
|
| 1116 |
|
| 1117 |
raw_sent = await bot.send_video(
|
| 1118 |
chat_id=STORAGE_CHANNEL_ID,
|
|
@@ -1122,9 +1123,9 @@ async def process_single_video(task, redis_client):
|
|
| 1122 |
raw_storage_id = raw_sent.id
|
| 1123 |
stream_link = f"{BACKEND_URL}/stream/{raw_storage_id}"
|
| 1124 |
download_link = f"{BACKEND_URL}/download/{raw_storage_id}"
|
| 1125 |
-
print(f"▶️ [WM] Original
|
| 1126 |
|
| 1127 |
-
await clone_client.edit_message_text(owner_id, status_msg.id, "⏳ <b>
|
| 1128 |
|
| 1129 |
watermarked_path = f"wm_{task_id}.mp4"
|
| 1130 |
|
|
@@ -1144,12 +1145,24 @@ async def process_single_video(task, redis_client):
|
|
| 1144 |
raise Exception("FFmpeg processing failed! The video format might be unsupported.")
|
| 1145 |
|
| 1146 |
print(f"▶️ [WM] FFmpeg Processing Complete!")
|
| 1147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1148 |
|
| 1149 |
await bot.send_video(
|
| 1150 |
chat_id=STORAGE_CHANNEL_ID,
|
| 1151 |
video=watermarked_path,
|
| 1152 |
-
caption=f"Watermarked Backup for Clone Owner {owner_id}"
|
|
|
|
| 1153 |
)
|
| 1154 |
print(f"▶️ [WM] Watermarked Backup Uploaded to Storage")
|
| 1155 |
|
|
@@ -1163,15 +1176,13 @@ async def process_single_video(task, redis_client):
|
|
| 1163 |
chat_id=owner_id,
|
| 1164 |
video=watermarked_path,
|
| 1165 |
caption=final_caption,
|
| 1166 |
-
parse_mode=enums.ParseMode.HTML
|
|
|
|
| 1167 |
)
|
| 1168 |
print(f"▶️ [WM] Final Video Sent to User Successfully!")
|
| 1169 |
|
| 1170 |
await clone_client.delete_messages(owner_id, status_msg.id)
|
| 1171 |
|
| 1172 |
-
if os.path.exists(raw_video_path): os.remove(raw_video_path)
|
| 1173 |
-
if os.path.exists(watermarked_path): os.remove(watermarked_path)
|
| 1174 |
-
|
| 1175 |
except Exception as e:
|
| 1176 |
print(f"❌ [WM] Process Error: {e}")
|
| 1177 |
try:
|
|
@@ -1180,6 +1191,11 @@ async def process_single_video(task, redis_client):
|
|
| 1180 |
print(f"❌ [WM] Failed to send error msg to user: {ex}")
|
| 1181 |
|
| 1182 |
finally:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1183 |
await clone_client.stop()
|
| 1184 |
await redis_client.delete(f"wm_processing:{owner_id}")
|
| 1185 |
processing_owners.discard(owner_id)
|
|
|
|
| 1097 |
print(f"▶️ [WM] Task Started for User: {owner_id}, Msg: {message_id}")
|
| 1098 |
|
| 1099 |
clone_client = Client(f"clone_wm_{task_id}", bot_token=clone_token, api_id=API_ID, api_hash=API_HASH, in_memory=True)
|
| 1100 |
+
thumb_path = f"thumb_{task_id}.jpg" # থাম্বনেইল এর ভেরিয়েবল
|
| 1101 |
|
| 1102 |
try:
|
| 1103 |
await clone_client.start()
|
|
|
|
| 1107 |
if not msg or not (msg.video or msg.document):
|
| 1108 |
raise Exception("Video not found or deleted by user.")
|
| 1109 |
|
| 1110 |
+
status_msg = await clone_client.send_message(owner_id, "⏳ <b>ভিডিও প্রসেসিং শুরু হয়েছে...</b>", parse_mode=enums.ParseMode.HTML)
|
| 1111 |
print(f"▶️ [WM] Status Message Sent to User")
|
| 1112 |
|
| 1113 |
raw_video_path = await clone_client.download_media(msg)
|
| 1114 |
print(f"▶️ [WM] Original Video Downloaded: {raw_video_path}")
|
| 1115 |
|
| 1116 |
+
await clone_client.edit_message_text(owner_id, status_msg.id, "⏳ <b>অরিজিনাল ভিডিও স্টোরেজে আপলোড হচ্ছে...</b>", parse_mode=enums.ParseMode.HTML)
|
| 1117 |
|
| 1118 |
raw_sent = await bot.send_video(
|
| 1119 |
chat_id=STORAGE_CHANNEL_ID,
|
|
|
|
| 1123 |
raw_storage_id = raw_sent.id
|
| 1124 |
stream_link = f"{BACKEND_URL}/stream/{raw_storage_id}"
|
| 1125 |
download_link = f"{BACKEND_URL}/download/{raw_storage_id}"
|
| 1126 |
+
print(f"▶️ [WM] Original video Uploaded to Storage")
|
| 1127 |
|
| 1128 |
+
await clone_client.edit_message_text(owner_id, status_msg.id, "⏳ <b>ওয়াটারমার্ক যুক্ত করা হচ্ছে... (কিছুক্ষণ সময় লাগতে পারে)</b>", parse_mode=enums.ParseMode.HTML)
|
| 1129 |
|
| 1130 |
watermarked_path = f"wm_{task_id}.mp4"
|
| 1131 |
|
|
|
|
| 1145 |
raise Exception("FFmpeg processing failed! The video format might be unsupported.")
|
| 1146 |
|
| 1147 |
print(f"▶️ [WM] FFmpeg Processing Complete!")
|
| 1148 |
+
|
| 1149 |
+
# ==========================================
|
| 1150 |
+
# থাম্বনেইল জেনারেট করা হচ্ছে
|
| 1151 |
+
# ==========================================
|
| 1152 |
+
thumb_cmd = ["ffmpeg", "-y", "-i", watermarked_path, "-vframes", "1", thumb_path]
|
| 1153 |
+
t_proc = await asyncio.create_subprocess_exec(*thumb_cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
| 1154 |
+
await t_proc.communicate()
|
| 1155 |
+
if not os.path.exists(thumb_path) or os.path.getsize(thumb_path) == 0:
|
| 1156 |
+
thumb_path = None
|
| 1157 |
+
# ==========================================
|
| 1158 |
+
|
| 1159 |
+
await clone_client.edit_message_text(owner_id, status_msg.id, "⏳ <b>ফাইনাল ভিডিও আপলোড হচ্ছে...</b>", parse_mode=enums.ParseMode.HTML)
|
| 1160 |
|
| 1161 |
await bot.send_video(
|
| 1162 |
chat_id=STORAGE_CHANNEL_ID,
|
| 1163 |
video=watermarked_path,
|
| 1164 |
+
caption=f"Watermarked Backup for Clone Owner {owner_id}",
|
| 1165 |
+
thumb=thumb_path # থাম্বনেইল যুক্ত করা হলো
|
| 1166 |
)
|
| 1167 |
print(f"▶️ [WM] Watermarked Backup Uploaded to Storage")
|
| 1168 |
|
|
|
|
| 1176 |
chat_id=owner_id,
|
| 1177 |
video=watermarked_path,
|
| 1178 |
caption=final_caption,
|
| 1179 |
+
parse_mode=enums.ParseMode.HTML,
|
| 1180 |
+
thumb=thumb_path # থাম্বনেইল যুক্ত করা হলো
|
| 1181 |
)
|
| 1182 |
print(f"▶️ [WM] Final Video Sent to User Successfully!")
|
| 1183 |
|
| 1184 |
await clone_client.delete_messages(owner_id, status_msg.id)
|
| 1185 |
|
|
|
|
|
|
|
|
|
|
| 1186 |
except Exception as e:
|
| 1187 |
print(f"❌ [WM] Process Error: {e}")
|
| 1188 |
try:
|
|
|
|
| 1191 |
print(f"❌ [WM] Failed to send error msg to user: {ex}")
|
| 1192 |
|
| 1193 |
finally:
|
| 1194 |
+
# ফাইলগুলো সার্ভার থেকে ডিলিট করে ক্লিন করা হচ্ছে
|
| 1195 |
+
if os.path.exists(raw_video_path): os.remove(raw_video_path)
|
| 1196 |
+
if os.path.exists(watermarked_path): os.remove(watermarked_path)
|
| 1197 |
+
if thumb_path and os.path.exists(thumb_path): os.remove(thumb_path)
|
| 1198 |
+
|
| 1199 |
await clone_client.stop()
|
| 1200 |
await redis_client.delete(f"wm_processing:{owner_id}")
|
| 1201 |
processing_owners.discard(owner_id)
|