import os import time import threading import requests import asyncio import re from flask import Flask, jsonify, make_response, request from supabase import create_client from pyrogram import Client, filters, enums from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo # ================= CONFIGURATION ================= BOT_TOKEN = "8628213901:AAFvfHBpZ6tok40ZQuhIDLAVIMrHeiheMNY" API_ID = 2040 API_HASH = "b18441a1ff607e10a989891a5462e627" SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co" SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN" WEB_APP_URL = "https://rony90790.github.io/Forward-bot/index.html" BYSE_API_KEY = "133323knboif885fhgwxvf" ADMIN_IDS = [7307789267] app = Flask(__name__) supabase = create_client(SUPABASE_URL, SUPABASE_KEY) admin_states = {} # Pyrogram Client Setup bot = Client( "file_unlocker_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN ) # Helper function to prevent blocking the event loop async def db_query(func): return await asyncio.to_thread(func) # ================= FLASK API ROUTES ================= @app.route('/') def index(): return "Bot and API are Running smoothly! 🚀" @app.route('/api/videos') def api_videos(): try: res = supabase.table('videos').select('*').order('id', desc=True).execute() response = make_response(jsonify(res.data)) except Exception as e: print(f"API Error: {e}") response = make_response(jsonify([])) response.headers['Access-Control-Allow-Origin'] = '*' return response # āϝ⧁āĻ•ā§āϤ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇ - Frontend-āĻāϰ āϜāĻ¨ā§āϝ Missing API Endpoint (CORS Handle āϏāĻš) @app.route('/api/send_code', methods=['POST', 'OPTIONS']) def api_send_code(): if request.method == 'OPTIONS': res = make_response() res.headers['Access-Control-Allow-Origin'] = '*' res.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization' return res # Mock Response: Frontend error āĻā§œāĻžāύ⧋ āĻ“ āĻĄā§‡āĻŽā§‹ āϰāĻžāύ āĻ•āϰāĻžāϰ āϜāĻ¨ā§āϝ res = make_response(jsonify({"status": "ok", "hash": "dummy_hash_1234"})) res.headers['Access-Control-Allow-Origin'] = '*' return res @app.route('/api/verify_code', methods=['POST', 'OPTIONS']) def api_verify_code(): if request.method == 'OPTIONS': res = make_response() res.headers['Access-Control-Allow-Origin'] = '*' res.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization' return res res = make_response(jsonify({"status": "ok"})) res.headers['Access-Control-Allow-Origin'] = '*' return res # ================= TELEGRAM BOT COMMANDS ================= @bot.on_message(filters.command("start")) async def start(client, message): if message.chat.type != enums.ChatType.PRIVATE: try: bot_me = client.me if client.me else await client.get_me() bot_link = f"https://t.me/{bot_me.username}" markup = InlineKeyboardMarkup([[InlineKeyboardButton("đŸŽŦ Watch Videos Now", url=bot_link)]]) await message.reply("đŸ”Ĩ **Watch Premium Viral Videos for FREE!**\n\n👉 Click the button below to watch:", reply_markup=markup) except Exception as e: print(e) return try: user_id = message.from_user.id first_name = message.from_user.first_name args = message.command referrer_id = None if len(args) > 1: try: referrer_id = int(args[1]) except ValueError: pass user_check = await db_query(lambda: supabase.table('referrals').select('*').eq('user_id', user_id).execute()) if not user_check.data: await db_query(lambda: supabase.table('referrals').insert({ 'user_id': user_id, 'referral_count': 0, 'referrer_id': referrer_id if referrer_id != user_id else None }).execute()) if referrer_id and referrer_id != user_id: ref_data = await db_query(lambda: supabase.table('referrals').select('referral_count').eq('user_id', referrer_id).execute()) if ref_data.data: new_count = ref_data.data[0]['referral_count'] + 1 await db_query(lambda: supabase.table('referrals').update({'referral_count': new_count}).eq('user_id', referrer_id).execute()) try: safe_name = first_name.replace('<', '').replace('>', '') if first_name else "User" success_msg = f"🎉 Congratulations!\n\n👤 {safe_name} has joined using your link!\n📈 Total Invites: {new_count}\n\nGo to the Web App to check unlocked videos!" markup = InlineKeyboardMarkup([[InlineKeyboardButton("đŸŽŦ Check Unlocked Videos", web_app=WebAppInfo(url=WEB_APP_URL))]]) await client.send_message(referrer_id, success_msg, parse_mode=enums.ParseMode.HTML, reply_markup=markup) except Exception: pass bot_me = client.me if client.me else await client.get_me() markup = InlineKeyboardMarkup([ [InlineKeyboardButton("đŸ”Ĩ Play Viral Videos 🔞", web_app=WebAppInfo(url=WEB_APP_URL))], [InlineKeyboardButton("đŸ“ĸ Add to Group", url=f"https://t.me/{bot_me.username}?startgroup=true")] ]) welcome_text = ( f"Hello {first_name}! 👋\n\n" f"🎁 Welcome to Video Unlocker Pro!\n" f"Here you can watch premium leaked and viral videos completely for FREE.\n\n" f"👇 Click the button below to Open App:" ) await message.reply(welcome_text, parse_mode=enums.ParseMode.HTML, reply_markup=markup) except Exception as e: print(f"Start error: {e}") @bot.on_message(filters.new_chat_members) async def bot_added_to_group(client, message): me = client.me if getattr(me, "id", None) is None: try: me = await client.get_me() except: return for member in message.new_chat_members: if member.id == me.id: try: await db_query(lambda: supabase.table('groups').upsert({'group_id': message.chat.id}).execute()) group_name = message.chat.title admin_msg = f"✅ āĻŦāϟ āύāϤ⧁āύ āĻāĻ•āϟāĻŋ āĻ—ā§āϰ⧁āĻĒ⧇ āĻ…ā§āϝāĻžāĻĄ āĻšā§Ÿā§‡āϛ⧇!\n\n📌 āĻ—ā§āϰ⧁āĻĒ⧇āϰ āύāĻžāĻŽ: {group_name}\n🆔 ID: {message.chat.id}" for admin_id in ADMIN_IDS: try: await client.send_message(chat_id=admin_id, text=admin_msg, parse_mode=enums.ParseMode.HTML) except: pass except: pass @bot.on_message(filters.command("blur") & filters.private & filters.user(ADMIN_IDS)) async def set_blur_state(client, message): try: args = message.text.split() if len(args) > 1 and args[1].lower() in ['0', '0%', 'off', 'cancel']: if message.chat.id in admin_states: admin_states[message.chat.id].pop("blur_percent", None) admin_states[message.chat.id].pop("clear_percent", None) await message.reply("✅ āĻŦā§āϞāĻžāϰ āĻŽā§‹āĻĄ āĻŦāĻ¨ā§āϧ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇!\nāĻāĻ–āύ āĻĨ⧇āϕ⧇ āφāĻĒāϞ⧋āĻĄ āĻ•āϰāĻž āĻ­āĻŋāĻĄāĻŋāĻ“ āφāϰ āĻŦā§āϞāĻžāϰ āĻšāĻŦ⧇ āύāĻž, āφāϗ⧇āϰ āĻŽāϤ⧋ āĻļ⧁āϧ⧁āĻŽāĻžāĻ¤ā§āϰ āĻ“ā§ŸāĻžāϟāĻžāϰāĻŽāĻžāĻ°ā§āĻ• āĻšāĻŦ⧇āĨ¤", parse_mode=enums.ParseMode.HTML) return match = re.search(r'/blur\s+(\d+)%?(?:\s+(\d+)%?)?', message.text, re.IGNORECASE) if match: percent = int(match.group(1)) clear_percent = int(match.group(2)) if match.group(2) else 0 if percent == 0: if message.chat.id in admin_states: admin_states[message.chat.id].pop("blur_percent", None) admin_states[message.chat.id].pop("clear_percent", None) await message.reply("✅ āĻŦā§āϞāĻžāϰ āĻŽā§‹āĻĄ āĻŦāĻ¨ā§āϧ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇!", parse_mode=enums.ParseMode.HTML) return if message.chat.id not in admin_states: admin_states[message.chat.id] = {} admin_states[message.chat.id]["blur_percent"] = percent admin_states[message.chat.id]["clear_percent"] = clear_percent clear_msg = f"āĻāĻŦāĻ‚ āωāĻĒāϰ⧇āϰ {clear_percent}% āĻ…āĻ‚āĻļ āĻ•ā§āϞāĻŋ⧟āĻžāϰ āĻĨāĻžāĻ•āĻŦ⧇āĨ¤" if clear_percent > 0 else "āĻĒ⧁āϰ⧋ āĻ›āĻŦāĻŋ/āĻ­āĻŋāĻĄāĻŋāĻ“ āĻŦā§āϞāĻžāϰ āĻšāĻŦ⧇āĨ¤" reply_text = ( f"✅ āĻŦā§āϞāĻžāϰ āϏ⧇āϟ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇: {percent}%\n" f"📌 {clear_msg}\n\n" f"āĻāĻ–āύ āĻĨ⧇āϕ⧇ āφāĻĒāϞ⧋āĻĄ āĻ•āϰāĻž āϏāĻŦ āĻ­āĻŋāĻĄāĻŋāĻ“/āĻ›āĻŦāĻŋāϤ⧇ āĻ¸ā§āĻŦ⧟āĻ‚āĻ•ā§āϰāĻŋ⧟āĻ­āĻžāĻŦ⧇ āĻāϟāĻŋ āĻ…ā§āϝāĻžāĻĒā§āϞāĻžāχ āĻšāĻŦ⧇āĨ¤\n\n" f"(āĻŦāĻŋ.āĻĻā§āϰ: āĻŦāĻ¨ā§āϧ āĻ•āϰāϤ⧇ /blur 0 āϞāĻŋāϖ⧇ āϏ⧇āĻ¨ā§āĻĄ āĻ•āϰ⧁āύāĨ¤)" ) await message.reply(reply_text, parse_mode=enums.ParseMode.HTML) else: await message.reply("❌ āϭ⧁āϞ āĻ•āĻŽāĻžāĻ¨ā§āĻĄ!\nāϏāĻ āĻŋāĻ• āύāĻŋ⧟āĻŽ: `/blur 60` āĻ…āĻĨāĻŦāĻž `/blur 60 20`") except Exception as e: print(e) def upload_file_sync(upload_url, file_path, api_key): with open(file_path, 'rb') as f: payload = {'key': api_key} files = {'file': f} return requests.post(upload_url, data=payload, files=files, timeout=900).json() @bot.on_message((filters.video | filters.animation | filters.photo) & filters.private & filters.user(ADMIN_IDS)) async def handle_media_upload(client, message): state = admin_states.get(message.chat.id, {}) if state.get("step") == "broadcast": await process_broadcast(client, message) return media_type = "video" if message.video else "animation" if message.animation else "photo" has_blur_caption = message.caption and "/blur" in message.caption.lower() is_persistent_blur = bool(state.get("blur_percent")) if media_type == "photo" and not (has_blur_caption or is_persistent_blur): status = await message.reply("âŗ āĻĨāĻžāĻŽā§āĻŦāύ⧇āχāϞ āϏ⧇āĻ­ āĻšāĻšā§āϛ⧇...") try: local_path = await message.download() if not local_path: await status.edit_text("❌ āĻĨāĻžāĻŽā§āĻŦāύ⧇āχāϞ āĻĄāĻžāωāύāϞ⧋āĻĄ āĻ•āϰāĻž āϏāĻŽā§āĻ­āĻŦ āĻšā§ŸāύāĻŋ!") return def upload_to_supabase(): with open(local_path, 'rb') as f: file_bytes = f.read() file_name = f"thumb_{int(time.time())}.jpg" supabase.storage.from_('thumbnails').upload(file_name, file_bytes, {"content-type": "image/jpeg"}) return supabase.storage.from_('thumbnails').get_public_url(file_name) direct_link = await asyncio.to_thread(upload_to_supabase) if os.path.exists(local_path): os.remove(local_path) await status.edit_text(f"✅ āĻĨāĻžāĻŽā§āĻŦāύ⧇āχāϞ āϏāĻĢāϞāĻ­āĻžāĻŦ⧇ āϏ⧇āĻ­ āĻšā§Ÿā§‡āϛ⧇!\n\n{direct_link}", parse_mode=enums.ParseMode.HTML) except Exception as e: await status.edit_text(f"âš ī¸ āφāĻĒāϞ⧋āĻĄ āĻāϰāϰ: {e}") return raw_caption = message.caption or "" blur_match = re.search(r'/blur\s+(\d+)%?(?:\s+(\d+)%?)?', raw_caption, re.IGNORECASE) is_blur = False blur_percent = 0 clear_percent = 0 clean_caption = raw_caption if blur_match: is_blur = True blur_percent = int(blur_match.group(1)) clear_percent = int(blur_match.group(2)) if blur_match.group(2) else 0 clean_caption = re.sub(r'/blur\s*\d+%?(?:\s*\d+%?)?', '', raw_caption, flags=re.IGNORECASE).strip() elif state.get("blur_percent"): is_blur = True blur_percent = state["blur_percent"] clear_percent = state.get("clear_percent", 0) is_large_video = False if media_type == "video": duration = message.video.duration if message.video and message.video.duration else 0 file_size = message.video.file_size if message.video and message.video.file_size else 0 MAX_DURATION = 600 MAX_SIZE = 150 * 1024 * 1024 if duration > MAX_DURATION or file_size > MAX_SIZE: is_large_video = True is_blur = False if is_large_video: status_msg = await message.reply("âŗ āĻ­āĻŋāĻĄāĻŋāĻ“āϟāĻŋ āĻŦ⧜! āϏāĻžāĻ°ā§āĻ­āĻžāϰ āĻ•ā§āĻ°ā§āϝāĻžāĻļ āĻā§œāĻžāϤ⧇ āĻŦā§āϞāĻžāϰ āĻ¸ā§āĻ•āĻŋāĻĒ āĻ•āϰ⧇ āϏāϰāĻžāϏāϰāĻŋ byse.sx āĻ āφāĻĒāϞ⧋āĻĄ āĻ•āϰāĻž āĻšāĻšā§āϛ⧇...") else: status_msg = await message.reply("âŗ āĻŽāĻŋāĻĄāĻŋ⧟āĻž āĻĄāĻžāωāύāϞ⧋āĻĄ āĻšāĻšā§āϛ⧇...") bot_me = client.me if client.me else await client.get_me() bot_link = f"https://t.me/{bot_me.username}" original_file = None watermarked_file = None blurred_file = None final_file = None embed_link = None try: original_file = await message.download() # āϝ⧁āĻ•ā§āϤ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇ - āĻĢāĻžāχāϞ āĻĢ⧇āχāϞ āĻšāϞ⧇ āĻ•ā§āĻ°ā§āϝāĻžāĻļ āĻšā§āϝāĻžāĻ¨ā§āĻĄāϞ if not original_file: await status_msg.edit_text("❌ āĻŽāĻŋāĻĄāĻŋ⧟āĻž āĻĢāĻžāχāϞāϟāĻŋ āĻĄāĻžāωāύāϞ⧋āĻĄ āĻ•āϰāĻž āϏāĻŽā§āĻ­āĻŦ āĻšā§ŸāύāĻŋ! (āϖ⧁āĻŦ āĻŦ⧜ āĻŦāĻž āϏāĻžāĻ°ā§āĻ­āĻžāϰ āϏāĻŽāĻ¸ā§āϝāĻž)") return final_file = original_file if media_type == "video" and not is_large_video: await status_msg.edit_text("âŗ āĻ­āĻŋāĻĄāĻŋāĻ“ āĻ“ā§ŸāĻžāϟāĻžāϰāĻŽāĻžāĻ°ā§āĻ• āĻ•āϰāĻž āĻšāĻšā§āϛ⧇... (āĻ•āĻŽ āĻ°â€ā§āϝāĻžāĻŽ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇)") watermarked_file = f"{original_file}_wm.mp4" cmd = [ "ffmpeg", "-y", "-i", original_file, "-vf", "drawtext=text='@mxvdo':x=W-tw-20:y=H-th-20:fontsize=22:fontcolor=white@0.7:shadowcolor=black@0.8:shadowx=2:shadowy=2:enable='gte(t,5)'", "-c:v", "libx264", "-preset", "ultrafast", "-threads", "1", "-crf", "28", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart", watermarked_file ] process = await asyncio.create_subprocess_exec(*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) await process.communicate() if process.returncode == 0 and os.path.exists(watermarked_file): final_file = watermarked_file if is_blur and not is_large_video: msg_txt = f"âŗ āĻŸā§‡āϞāĻŋāĻ—ā§āϰāĻžāĻŽā§‡āϰ āϜāĻ¨ā§āϝ {blur_percent}% āĻŦā§āϞāĻžāϰ āϤ⧈āϰāĻŋ āĻ•āϰāĻž āĻšāĻšā§āϛ⧇..." if clear_percent > 0: msg_txt = f"âŗ {blur_percent}% āĻŦā§āϞāĻžāϰ (āωāĻĒāϰ⧇āϰ {clear_percent}% āĻ•ā§āϞāĻŋ⧟āĻžāϰ) āϤ⧈āϰāĻŋ āĻ•āϰāĻž āĻšāĻšā§āϛ⧇..." await status_msg.edit_text(msg_txt) radius = max(2, min(20, int((blur_percent / 100.0) * 30))) ext = "jpg" if media_type == "photo" else "mp4" blurred_file = f"{original_file}_blurred.{ext}" if clear_percent > 0: clear_ratio = clear_percent / 100.0 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"] else: ff_filter = ["-vf", f"boxblur={radius}:1"] if media_type == "photo": cmd_blur = ["ffmpeg", "-y", "-i", final_file] + ff_filter + [blurred_file] elif media_type == "animation": cmd_blur = ["ffmpeg", "-y", "-i", final_file] + ff_filter + ["-c:v", "libx264", "-preset", "ultrafast", "-threads", "1", "-pix_fmt", "yuv420p", blurred_file] else: cmd_blur = ["ffmpeg", "-y", "-i", final_file] + ff_filter + ["-c:v", "libx264", "-preset", "ultrafast", "-threads", "1", "-crf", "28", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart", blurred_file] process_blur = await asyncio.create_subprocess_exec(*cmd_blur, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) await process_blur.communicate() if process_blur.returncode == 0 and os.path.exists(blurred_file): final_file = blurred_file if media_type == "video": await status_msg.edit_text("âŗ byse.sx āϏāĻžāĻ°ā§āĻ­āĻžāϰ⧇ āĻ­āĻŋāĻĄāĻŋāĻ“ āφāĻĒāϞ⧋āĻĄ āĻ•āϰāĻž āĻšāĻšā§āϛ⧇...") api_endpoint = "https://api.byse.sx/upload/server" params = {'key': BYSE_API_KEY} loop = asyncio.get_event_loop() response = await loop.run_in_executor(None, lambda: requests.get(api_endpoint, params=params, timeout=30)) result = response.json() if result.get('status') == 200: upload_url = result.get('result') upload_res = await loop.run_in_executor(None, upload_file_sync, upload_url, final_file, BYSE_API_KEY) if upload_res.get('status') == 200 and 'files' in upload_res and len(upload_res['files']) > 0: file_code = upload_res['files'][0].get('filecode') file_status = upload_res['files'][0].get('status', '') if "not allowed" in str(file_status).lower(): await status_msg.edit_text(f"❌ byse.sx āĻĢāĻžāχāϞ āϰāĻŋāĻœā§‡āĻ•ā§āϟ āĻ•āϰ⧇āϛ⧇: {file_status}", parse_mode=enums.ParseMode.HTML) return if file_code: embed_link = f"https://bysesayeveum.com/e/{file_code}" if not embed_link: await status_msg.edit_text("❌ byse.sx āφāĻĒāϞ⧋āĻĄ āĻšā§Ÿā§‡āϛ⧇ āĻ•āĻŋāĻ¨ā§āϤ⧁ Embed Link āĻĒāĻžāĻ“ā§ŸāĻž āϝāĻžā§ŸāύāĻŋāĨ¤") return if is_large_video: admin_cap = ( f"✅ āϏāĻĢāϞ! (āĻŦ⧜ āĻ­āĻŋāĻĄāĻŋāĻ“)\n\n" f"🔗 Embed Link:\n{embed_link or 'N/A'}\n\n" f"📌 āĻ­āĻŋāĻĄāĻŋāĻ“āϟāĻŋ āĻ…āύ⧇āĻ• āĻŦ⧜ āĻšāĻ“ā§ŸāĻžā§Ÿ āĻ—ā§āϰ⧁āĻĒ⧇ āĻŦā§āϰāĻĄāĻ•āĻžāĻ¸ā§āϟ āĻ¸ā§āĻ•āĻŋāĻĒ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇āĨ¤ āφāĻĒāύāĻŋ āϚāĻžāχāϞ⧇ āϞāĻŋāĻ‚āĻ•āϟāĻŋ āĻĻāĻŋā§Ÿā§‡ āύāĻŋāĻœā§‡āχ Web App āĻ āĻ­āĻŋāĻĄāĻŋāĻ“ āĻ…ā§āϝāĻžāĻĄ āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύāĨ¤" ) await client.send_video(message.chat.id, message.video.file_id, caption=admin_cap, parse_mode=enums.ParseMode.HTML) await status_msg.delete() return await status_msg.edit_text("âŗ āĻ—ā§āϰ⧁āĻĒ⧇ āĻĒāĻžāĻ āĻžāύ⧋āϰ āĻĒā§āϰāĻ¸ā§āϤ⧁āϤāĻŋ āϚāϞāϛ⧇...") if media_type == "video": if is_blur: caption_text = ( f"đŸ”Ĩ New Premium Viral Video Leaked! 🔞\n\n" f"đŸŽŦ Watch HD Video Here:\n" f"👉 â–ļī¸ Click Here to Watch HD\n\n" f"🤖 Open Bot for More Videos!\n" f"👇 Click the button below to open Bot!" ) else: caption_text = ( f"đŸ”Ĩ New Premium Viral Video Leaked! 🔞\n\n" f"đŸŽŦ Watch Full Video Here:\n" f"👉 â–ļī¸ Click Here to Watch\n\n" f"👇 Click the button below to open Bot!" ) else: if clean_caption: caption_text = f"{clean_caption}\n\n👇 Click the button below to open Bot!" else: caption_text = ( f"đŸ”Ĩ New Premium Viral Content! 🔞\n\n" f"đŸŽŦ Watch HD Video Here:\n" f"👉 â–ļī¸ Click Here to Watch\n\n" f"👇 Click the button below to open Bot!" ) group_markup = InlineKeyboardMarkup([ [InlineKeyboardButton("đŸŽŦ Watch Full Video Here 🔞", url=bot_link)] ]) admin_cap = f"✅ āϏāĻĢāϞ! āĻŽāĻŋāĻĄāĻŋ⧟āĻžāϟāĻŋ āĻāĻ–āύ āĻ—ā§āϰ⧁āĻĒāϗ⧁āϞ⧋āϤ⧇ āĻĒāĻžāĻ āĻžāύ⧋ āĻšāĻšā§āϛ⧇...\n\n🔗 Embed Link (āφāĻĒāύāĻžāϰ āϜāĻ¨ā§āϝ):\n{embed_link or 'N/A'}" thumb_path = None if media_type == "video": v_duration = message.video.duration if message.video else 0 v_width = message.video.width if message.video else 0 v_height = message.video.height if message.video else 0 thumb_path = f"{original_file}_thumb.jpg" cmd_thumb = ["ffmpeg", "-y", "-i", final_file, "-vframes", "1", thumb_path] proc = await asyncio.create_subprocess_exec(*cmd_thumb, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) await proc.communicate() if not os.path.exists(thumb_path): thumb_path = None if media_type == "photo": sent_to_admin = await client.send_photo(message.chat.id, final_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML) tg_file_id = sent_to_admin.photo.file_id elif media_type == "animation": sent_to_admin = await client.send_animation(message.chat.id, final_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML) tg_file_id = sent_to_admin.animation.file_id else: sent_to_admin = await client.send_video( message.chat.id, final_file, caption=admin_cap, parse_mode=enums.ParseMode.HTML, duration=v_duration, width=v_width, height=v_height, thumb=thumb_path ) tg_file_id = sent_to_admin.video.file_id await status_msg.delete() groups_res = await db_query(lambda: supabase.table('groups').select('group_id').execute()) group_ids = [g['group_id'] for g in groups_res.data] success_count, fail_count = 0, 0 for gid in set(group_ids): try: if media_type == "photo": await client.send_photo(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup) elif media_type == "animation": await client.send_animation(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup) else: await client.send_video(gid, tg_file_id, caption=caption_text, parse_mode=enums.ParseMode.HTML, reply_markup=group_markup) success_count += 1 await asyncio.sleep(1.5) except Exception: fail_count += 1 await message.reply(f"đŸ“ĸ āĻŦā§āϰāĻĄāĻ•āĻžāĻ¸ā§āϟ āϏāĻŽā§āĻĒāĻ¨ā§āύ!\n\n✅ āϏāĻĢāϞ: {success_count} āϟāĻŋ āĻ—ā§āϰ⧁āĻĒ⧇\n❌ āĻŦā§āϝāĻ°ā§āĻĨ (āϰāĻŋāĻŽā§āĻ­āĻĄ): {fail_count} āϟāĻŋ āĻ—ā§āϰ⧁āĻĒ⧇", parse_mode=enums.ParseMode.HTML) except Exception as e: await message.reply(f"âš ī¸ āĻāϰāϰ āĻšā§Ÿā§‡āϛ⧇: {str(e)}") finally: thumb_file = f"{original_file}_thumb.jpg" if original_file else None for f in [original_file, watermarked_file, blurred_file, thumb_file]: if f and os.path.exists(f): try: os.remove(f) except: pass @bot.on_message(filters.command(["stats", "users"]) & filters.private & filters.user(ADMIN_IDS)) async def bot_stats(client, message): try: users = await db_query(lambda: supabase.table('referrals').select('user_id', count='exact').execute()) videos = await db_query(lambda: supabase.table('videos').select('*', count='exact').execute()) groups = await db_query(lambda: supabase.table('groups').select('group_id', count='exact').execute()) stat_msg = f"📊 āĻŦāĻŸā§‡āϰ āĻŦāĻ°ā§āϤāĻŽāĻžāύ āĻ¸ā§āĻŸā§āϝāĻžāϟāĻžāϏ:\n\nđŸ‘Ĩ āĻŽā§‹āϟ āχāωāϜāĻžāϰ: {users.count or 0} āϜāύ\nđŸŽŦ āĻŽā§‹āϟ āĻ­āĻŋāĻĄāĻŋāĻ“: {videos.count or 0} āϟāĻŋ\nđŸ“ĸ āĻŽā§‹āϟ āĻ—ā§āϰ⧁āĻĒ: {groups.count or 0} āϟāĻŋ" await message.reply(stat_msg, parse_mode=enums.ParseMode.HTML) except Exception as e: print(e) @bot.on_message(filters.command("broadcast") & filters.private & filters.user(ADMIN_IDS)) async def broadcast_command(client, message): admin_states[message.chat.id] = {"step": "broadcast"} await message.reply("đŸ“ĸ āϏāĻŦāĻžāϰ āĻ•āĻžāϛ⧇ āϝāĻž āĻĒāĻžāĻ āĻžāϤ⧇ āϚāĻžāύ āĻĻāĻŋāύāĨ¤ (āĻŦāĻžāϤāĻŋāϞ āĻ•āϰāϤ⧇ /cancel)") async def process_broadcast(client, message): text = message.text or message.caption if text == '/cancel': admin_states.pop(message.chat.id, None) await message.reply("❌ āĻŦāĻžāϤāĻŋāϞ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇āĨ¤") return await message.reply("âŗ āĻŦā§āϰāĻĄāĻ•āĻžāĻ¸ā§āϟ āĻļ⧁āϰ⧁ āĻšā§Ÿā§‡āϛ⧇...") admin_states.pop(message.chat.id, None) try: all_users = [] start = 0 step = 1000 while True: res = await db_query(lambda: supabase.table('referrals').select('user_id').range(start, start + step - 1).execute()) if not res.data: break all_users.extend(res.data) start += step success, failed = 0, 0 for u in all_users: try: await message.copy(chat_id=u['user_id']) success += 1 await asyncio.sleep(0.15) except Exception: failed += 1 await message.reply(f"✅ āĻŦā§āϰāĻĄāĻ•āĻžāĻ¸ā§āϟ āϏāĻŽā§āĻĒāĻ¨ā§āύ!\nāϏāĻĢāϞ: {success}\nāĻŦā§āϝāĻ°ā§āĻĨ: {failed}") except Exception as e: print(e) @bot.on_message(filters.command(["png", "addvideo"]) & filters.private & filters.user(ADMIN_IDS)) async def add_png(client, message): try: parts = message.command needed_ref = 3 duration = "random" if len(parts) == 4 and parts[1].isdigit(): needed_ref = int(parts[1]); duration = parts[2]; thumbnail_url = parts[3] elif len(parts) == 3 and parts[1].isdigit(): needed_ref = int(parts[1]); thumbnail_url = parts[2] elif len(parts) == 2: thumbnail_url = parts[1] else: await message.reply("❌ āύāĻŋ⧟āĻŽ āϭ⧁āϞāĨ¤") return packed_thumb = f"{thumbnail_url}||{duration}" admin_states[message.chat.id] = {"step": 1, "thumbnail_url": packed_thumb, "needed_ref": needed_ref} await message.reply("✅ āĻāĻ–āύ Video/Embed Link āĻĻāĻŋāύāĨ¤") except Exception as e: print(e) @bot.on_message(filters.private & filters.user(ADMIN_IDS) & ~filters.command(["start", "stats", "users", "broadcast", "png", "addvideo", "blur"])) async def catch_admin_steps(client, message): state = admin_states.get(message.chat.id, {}) if state.get("step") == 1: if not message.text: return video_url = message.text.strip() if video_url == "/cancel": admin_states.pop(message.chat.id, None) await message.reply("❌ āĻŦāĻžāϤāĻŋāϞ āĻ•āϰāĻž āĻšā§Ÿā§‡āϛ⧇āĨ¤") return thumb_url = state["thumbnail_url"] needed_ref = state["needed_ref"] try: await db_query(lambda: supabase.table('videos').insert({"video_url": video_url, "thumbnail_url": thumb_url, "needed_ref": needed_ref}).execute()) await message.reply("🎉 āĻ­āĻŋāĻĄāĻŋāĻ“ āϏāĻĢāϞāĻ­āĻžāĻŦ⧇ āĻ…ā§āϝāĻžāĻĄ āĻšā§Ÿā§‡āϛ⧇!") except Exception as e: print(e) finally: admin_states.pop(message.chat.id, None) elif state.get("step") == "broadcast": await process_broadcast(client, message) # ================= RUNNER ================= def run_flask(): app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8080))) if __name__ == "__main__": threading.Thread(target=run_flask, daemon=True).start() print("🤖 Pyrogram Bot is starting...") bot.run()