Spaces:
Paused
Paused
Upload 14 files
Browse files- Dockerfile +55 -0
- auth.py +73 -0
- authorized_users.json +1 -0
- entrypoint.sh +9 -0
- favicon.ico +0 -0
- favicon.png +0 -0
- noor.py +653 -0
- requirements.txt +10 -0
- runtime.txt +1 -0
- static/angel.txt +1 -0
- static/favicon.ico +0 -0
- static/favicon.png +0 -0
- templates/index.html +262 -0
- utils/duration.py +39 -0
Dockerfile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a lightweight Python image
|
| 2 |
+
FROM python:3.11-slim-bookworm
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
# Kolkata timezone (IST - UTC+5:30)
|
| 6 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
+
PYTHONUNBUFFERED=1 \
|
| 8 |
+
PIP_NO_CACHE_DIR=on \
|
| 9 |
+
TZ=Asia/Kolkata
|
| 10 |
+
|
| 11 |
+
# Set timezone and install system dependencies
|
| 12 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 13 |
+
aria2 \
|
| 14 |
+
ffmpeg \
|
| 15 |
+
procps \
|
| 16 |
+
wget \
|
| 17 |
+
gnupg \
|
| 18 |
+
ca-certificates \
|
| 19 |
+
tzdata \
|
| 20 |
+
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
|
| 21 |
+
&& echo $TZ > /etc/timezone \
|
| 22 |
+
&& apt-get clean \
|
| 23 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 24 |
+
|
| 25 |
+
# Set working directory
|
| 26 |
+
WORKDIR /app
|
| 27 |
+
|
| 28 |
+
# Copy requirements first to leverage Docker cache
|
| 29 |
+
COPY requirements.txt .
|
| 30 |
+
|
| 31 |
+
# Install Python dependencies
|
| 32 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 33 |
+
|
| 34 |
+
# Copy application files
|
| 35 |
+
COPY . .
|
| 36 |
+
|
| 37 |
+
# Create download directory and fix permissions
|
| 38 |
+
RUN mkdir -p downloads \
|
| 39 |
+
&& chmod 777 downloads
|
| 40 |
+
|
| 41 |
+
# Fix permissions for authorized_users.json
|
| 42 |
+
RUN if [ -f "authorized_users.json" ]; then chmod 664 authorized_users.json; fi
|
| 43 |
+
|
| 44 |
+
# Copy and prepare entrypoint script
|
| 45 |
+
COPY entrypoint.sh /app/entrypoint.sh
|
| 46 |
+
RUN chmod +x /app/entrypoint.sh
|
| 47 |
+
|
| 48 |
+
# Expose Flask port
|
| 49 |
+
EXPOSE 8080
|
| 50 |
+
|
| 51 |
+
# Set entrypoint
|
| 52 |
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
| 53 |
+
|
| 54 |
+
# Start the bot
|
| 55 |
+
CMD ["python", "noor.py"]
|
auth.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import logging
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
BOT_OWNER_ID = int(os.getenv("BOT_OWNER_ID", "6743860398"))
|
| 8 |
+
|
| 9 |
+
# Setup logging for auth module
|
| 10 |
+
file_handler = logging.FileHandler('auth.log')
|
| 11 |
+
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger("terabox_bot")
|
| 14 |
+
logger.setLevel(logging.INFO)
|
| 15 |
+
logger.addHandler(file_handler)
|
| 16 |
+
|
| 17 |
+
# ফাইল পাথ
|
| 18 |
+
AUTHORIZED_USERS_FILE = os.path.abspath("authorized_users.json")
|
| 19 |
+
logger.info(f"Authorized users file path: {AUTHORIZED_USERS_FILE}")
|
| 20 |
+
|
| 21 |
+
# ইউজার লোড
|
| 22 |
+
if os.path.exists(AUTHORIZED_USERS_FILE):
|
| 23 |
+
try:
|
| 24 |
+
with open(AUTHORIZED_USERS_FILE, "r") as f:
|
| 25 |
+
AUTHORIZED_USERS = json.load(f)
|
| 26 |
+
logger.info(f"Loaded authorized users: {AUTHORIZED_USERS}")
|
| 27 |
+
except Exception as e:
|
| 28 |
+
AUTHORIZED_USERS = []
|
| 29 |
+
logger.warning(f"Failed to load users: {str(e)}. Initializing empty list.")
|
| 30 |
+
else:
|
| 31 |
+
AUTHORIZED_USERS = []
|
| 32 |
+
logger.info("No user file found, initializing empty list")
|
| 33 |
+
|
| 34 |
+
"""
|
| 35 |
+
def add_authorized_user(user_id: int) -> bool:
|
| 36 |
+
if user_id in AUTHORIZED_USERS:
|
| 37 |
+
logger.info(f"User {user_id} already authorized")
|
| 38 |
+
return False
|
| 39 |
+
AUTHORIZED_USERS.append(user_id)
|
| 40 |
+
return save_users()
|
| 41 |
+
"""
|
| 42 |
+
def add_authorized_user(user_id: int) -> bool:
|
| 43 |
+
user_id = int(user_id) # Ensure it's stored as integer
|
| 44 |
+
if user_id in AUTHORIZED_USERS:
|
| 45 |
+
logger.info(f"User {user_id} already authorized")
|
| 46 |
+
return False
|
| 47 |
+
AUTHORIZED_USERS.append(user_id)
|
| 48 |
+
return save_users()
|
| 49 |
+
|
| 50 |
+
def remove_authorized_user(user_id: int) -> bool:
|
| 51 |
+
if user_id not in AUTHORIZED_USERS:
|
| 52 |
+
logger.info(f"User {user_id} not found in list")
|
| 53 |
+
return False
|
| 54 |
+
AUTHORIZED_USERS.remove(user_id)
|
| 55 |
+
return save_users()
|
| 56 |
+
|
| 57 |
+
def save_users() -> bool:
|
| 58 |
+
try:
|
| 59 |
+
with open(AUTHORIZED_USERS_FILE, "w") as f:
|
| 60 |
+
json.dump(AUTHORIZED_USERS, f)
|
| 61 |
+
logger.info("✅ User list saved successfully")
|
| 62 |
+
logger.info(f"✅ Saved to path: {AUTHORIZED_USERS_FILE}") # ⬅️ এই লাইনটি যোগ করো
|
| 63 |
+
return True
|
| 64 |
+
except Exception as e:
|
| 65 |
+
logger.error(f"❌ Error saving user list: {str(e)}")
|
| 66 |
+
return False
|
| 67 |
+
|
| 68 |
+
def is_authorized(user_id: int) -> bool:
|
| 69 |
+
return user_id == BOT_OWNER_ID or user_id in AUTHORIZED_USERS
|
| 70 |
+
|
| 71 |
+
def get_authorized_users() -> list:
|
| 72 |
+
logger.info(f"Returning authorized users: {AUTHORIZED_USERS}")
|
| 73 |
+
return AUTHORIZED_USERS
|
authorized_users.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[7014665654]
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
# Set permissions on authorized_users.json
|
| 4 |
+
if [ -f "authorized_users.json" ]; then
|
| 5 |
+
chmod 664 authorized_users.json
|
| 6 |
+
fi
|
| 7 |
+
|
| 8 |
+
# Execute the main command
|
| 9 |
+
exec "$@"
|
favicon.ico
ADDED
|
|
favicon.png
ADDED
|
|
noor.py
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import shutil
|
| 4 |
+
import traceback
|
| 5 |
+
import logging
|
| 6 |
+
import json
|
| 7 |
+
import re
|
| 8 |
+
import requests
|
| 9 |
+
import asyncio
|
| 10 |
+
from threading import Thread
|
| 11 |
+
from urllib.parse import quote
|
| 12 |
+
from pyrogram.enums import ParseMode
|
| 13 |
+
from pyrogram import Client, filters
|
| 14 |
+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
| 15 |
+
from pyrogram.errors import FloodWait
|
| 16 |
+
from dotenv import load_dotenv
|
| 17 |
+
from flask import Flask, render_template
|
| 18 |
+
from auth import add_authorized_user, remove_authorized_user, is_authorized, AUTHORIZED_USERS, AUTHORIZED_USERS_FILE
|
| 19 |
+
from auth import BOT_OWNER_ID, get_authorized_users
|
| 20 |
+
from utils.duration import get_video_duration, sanitize_filename
|
| 21 |
+
|
| 22 |
+
# Load environment variables
|
| 23 |
+
load_dotenv()
|
| 24 |
+
API_ID = int(os.getenv("API_ID", "20687211"))
|
| 25 |
+
API_HASH = os.getenv("API_HASH", "4523f58b045175baaeaf1ba29733f31c")
|
| 26 |
+
BOT_TOKEN = os.getenv("BOT_TOKEN", "8016048090:AAG9GrfX5pKKFEYLWtMh18EAph8a-LAEt7Y")
|
| 27 |
+
BOT_OWNER_ID = int(os.getenv("BOT_OWNER_ID", "7014665654"))
|
| 28 |
+
# 🖇️ Terabox api
|
| 29 |
+
TERABOX_API = os.getenv("TERABOX_API", "https://angel-noor-terabox-api.woodmirror.workers.dev/api?url=")
|
| 30 |
+
# 🔗 Channel button photo links
|
| 31 |
+
CHANNEL_NAME = os.getenv("CHANNEL_NAME", "⚡❍⊱❁ 𝐒𝐀𝐍𝐂𝐇𝐈𝐓 ™")
|
| 32 |
+
CHANNEL_URL = os.getenv("CHANNEL_URL", "https://t.me/S4NCHITT")
|
| 33 |
+
WELCOME_URL = os.getenv("WELCOME_URL", "https://i.ibb.co/j9n6nZxD/Op-log.png")
|
| 34 |
+
USER_URL = os.getenv("PHOTO_URL", "https://i.ibb.co/7dc9sd45/Noor-logo.png")
|
| 35 |
+
# ⭐ Read max size in MB default = 1900 MB
|
| 36 |
+
MAX_SIZE_MB = int(os.getenv("MAX_SIZE", 1900))
|
| 37 |
+
# 💥 Convert MB to bytes
|
| 38 |
+
MAX_SIZE = MAX_SIZE_MB * 1024 * 1024
|
| 39 |
+
# ▶️ Video Streaming Support
|
| 40 |
+
SUPPORTS_STREAMING = os.getenv("SUPPORTS_STREAMING", "True").lower() == "true"
|
| 41 |
+
HAS_SPOILER = os.getenv("HAS_SPOILER", "False").lower() == "true"
|
| 42 |
+
|
| 43 |
+
# Initialize Pyrogram client
|
| 44 |
+
bot = Client("terabox_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 45 |
+
|
| 46 |
+
# Constants
|
| 47 |
+
DOWNLOAD_DIR = "downloads"
|
| 48 |
+
PROGRESS_UPDATE_INTERVAL = 1 # 1 second interval for smoother progress
|
| 49 |
+
|
| 50 |
+
# Regex pattern for Terabox links
|
| 51 |
+
TERABOX_REGEX = r"https?://(?:www\.)?(teraboxlink\.com|terasharelink\.com|teraboxapp\.com|1024terabox\.com|terabox\.com|terasharelink\.com|terafileshare\.com|4funbox\.co|teraboxapp\.to|terabox\.app)/s/([a-zA-Z0-9_-]+)"
|
| 52 |
+
|
| 53 |
+
# Setup basic logging
|
| 54 |
+
logging.basicConfig(
|
| 55 |
+
level=logging.INFO,
|
| 56 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 57 |
+
)
|
| 58 |
+
logger = logging.getLogger("terabox_bot")
|
| 59 |
+
|
| 60 |
+
# Add file logging handler
|
| 61 |
+
file_handler = logging.FileHandler('bot.log')
|
| 62 |
+
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
| 63 |
+
logger.addHandler(file_handler)
|
| 64 |
+
logger.setLevel(logging.INFO)
|
| 65 |
+
|
| 66 |
+
# Initialize Flask app
|
| 67 |
+
flask_app = Flask(__name__)
|
| 68 |
+
|
| 69 |
+
@flask_app.route('/')
|
| 70 |
+
def home():
|
| 71 |
+
return render_template("index.html")
|
| 72 |
+
|
| 73 |
+
Thread(target=lambda: flask_app.run(host="0.0.0.0", port=8080), daemon=True).start()
|
| 74 |
+
|
| 75 |
+
# Utility functions
|
| 76 |
+
def human_readable_size(size):
|
| 77 |
+
for unit in ["B", "KB", "MB", "GB"]:
|
| 78 |
+
if size < 1024.0:
|
| 79 |
+
return f"{size:.2f} {unit}"
|
| 80 |
+
size /= 1024.0
|
| 81 |
+
|
| 82 |
+
def progress_bar(percentage, bar_length=20):
|
| 83 |
+
"""Fixed progress bar function"""
|
| 84 |
+
filled = int(bar_length * percentage / 100)
|
| 85 |
+
empty = bar_length - filled
|
| 86 |
+
return "█" * filled + "░" * empty
|
| 87 |
+
|
| 88 |
+
async def edit_message(message, text):
|
| 89 |
+
try:
|
| 90 |
+
await message.edit_text(text, parse_mode=ParseMode.HTML)
|
| 91 |
+
except FloodWait as e:
|
| 92 |
+
await asyncio.sleep(e.value)
|
| 93 |
+
await edit_message(message, text)
|
| 94 |
+
except Exception as e:
|
| 95 |
+
logger.error(f"Error editing message: {str(e)}")
|
| 96 |
+
|
| 97 |
+
async def delete_message(message):
|
| 98 |
+
try:
|
| 99 |
+
await message.delete()
|
| 100 |
+
except Exception as e:
|
| 101 |
+
logger.error(f"Error deleting message: {str(e)}")
|
| 102 |
+
|
| 103 |
+
def clean_directory(directory):
|
| 104 |
+
try:
|
| 105 |
+
if os.path.exists(directory):
|
| 106 |
+
shutil.rmtree(directory)
|
| 107 |
+
logger.info(f"🪥 Successfully cleaned your file: {directory}")
|
| 108 |
+
return True
|
| 109 |
+
else:
|
| 110 |
+
logger.warning(f"⚠️ Directory does not exist: {directory}")
|
| 111 |
+
return False
|
| 112 |
+
except Exception as e:
|
| 113 |
+
logger.error(f"❌ Error cleaning directory {directory}: {repr(e)}")
|
| 114 |
+
logger.debug(traceback.format_exc())
|
| 115 |
+
return False
|
| 116 |
+
|
| 117 |
+
def parse_aria2c_output(line):
|
| 118 |
+
"""Parse aria2c output to get download progress"""
|
| 119 |
+
try:
|
| 120 |
+
# Example: [#1c9b1b 20MiB/100MiB(20%) CN:1 DL:3.0MiB]
|
| 121 |
+
match = re.search(r'\((\d+)%\)', line)
|
| 122 |
+
if match:
|
| 123 |
+
return int(match.group(1))
|
| 124 |
+
return None
|
| 125 |
+
except Exception:
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
+
# Terabox processing
|
| 129 |
+
async def process_terabox(user_id, terabox_url, msg):
|
| 130 |
+
USER_DIR = os.path.join(DOWNLOAD_DIR, f"user_{user_id}_{int(time.time())}")
|
| 131 |
+
os.makedirs(USER_DIR, exist_ok=True)
|
| 132 |
+
|
| 133 |
+
try:
|
| 134 |
+
# Show processing message
|
| 135 |
+
await edit_message(
|
| 136 |
+
msg,
|
| 137 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 138 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 139 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 140 |
+
f"🔍 <b>Processing your link...</b>\n"
|
| 141 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨"
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
# Fetch API data
|
| 145 |
+
api_url = TERABOX_API + quote(terabox_url)
|
| 146 |
+
response = requests.get(api_url)
|
| 147 |
+
|
| 148 |
+
if response.status_code != 200:
|
| 149 |
+
await edit_message(
|
| 150 |
+
msg,
|
| 151 |
+
f"❌ <b>API Error:</b> Failed to fetch link information\n"
|
| 152 |
+
f"Status Code: {response.status_code}"
|
| 153 |
+
)
|
| 154 |
+
await asyncio.sleep(5)
|
| 155 |
+
await delete_message(msg)
|
| 156 |
+
return False
|
| 157 |
+
|
| 158 |
+
data = response.json()
|
| 159 |
+
file_name = data["file_name"]
|
| 160 |
+
download_url = data["proxy_url"]
|
| 161 |
+
file_size = data["size_bytes"]
|
| 162 |
+
readable_size = human_readable_size(file_size)
|
| 163 |
+
|
| 164 |
+
# Check file size
|
| 165 |
+
if file_size > MAX_SIZE:
|
| 166 |
+
await edit_message(
|
| 167 |
+
msg,
|
| 168 |
+
f"❌ <b>File Too Large:</b> {readable_size}\n"
|
| 169 |
+
f"Max allowed: {human_readable_size(MAX_SIZE)}"
|
| 170 |
+
)
|
| 171 |
+
await asyncio.sleep(5)
|
| 172 |
+
await delete_message(msg)
|
| 173 |
+
return False
|
| 174 |
+
|
| 175 |
+
file_path = os.path.join(USER_DIR, file_name)
|
| 176 |
+
|
| 177 |
+
# Start download
|
| 178 |
+
await edit_message(
|
| 179 |
+
msg,
|
| 180 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 181 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 182 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 183 |
+
f"📥 <b>Downloading:</b> <code>{file_name}</code>\n"
|
| 184 |
+
f"📦 <b>Size:</b> {readable_size}\n"
|
| 185 |
+
f"🔸 {progress_bar(0)} 🔸\n"
|
| 186 |
+
f"🚀 <b>Progress:</b> 0%\n"
|
| 187 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨"
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
# Download file with improved progress tracking
|
| 191 |
+
command = [
|
| 192 |
+
"aria2c",
|
| 193 |
+
"-x16",
|
| 194 |
+
"--summary-interval=1",
|
| 195 |
+
"--auto-file-renaming=false",
|
| 196 |
+
"--allow-overwrite=true",
|
| 197 |
+
"--dir=" + USER_DIR,
|
| 198 |
+
"--out=" + file_name,
|
| 199 |
+
download_url
|
| 200 |
+
]
|
| 201 |
+
|
| 202 |
+
process = await asyncio.create_subprocess_exec(
|
| 203 |
+
*command,
|
| 204 |
+
stdout=asyncio.subprocess.PIPE,
|
| 205 |
+
stderr=asyncio.subprocess.STDOUT
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
# Track download progress with aria2c output
|
| 209 |
+
last_reported_percent = 0
|
| 210 |
+
start_time = time.time()
|
| 211 |
+
timeout = 7200 # 2 hours timeout for large files
|
| 212 |
+
|
| 213 |
+
# Pattern to match aria2c progress output
|
| 214 |
+
progress_pattern = re.compile(r'\((\d+)%\)')
|
| 215 |
+
|
| 216 |
+
while True:
|
| 217 |
+
# Check if process is still running
|
| 218 |
+
if process.returncode is not None:
|
| 219 |
+
break
|
| 220 |
+
|
| 221 |
+
# Check timeout
|
| 222 |
+
if time.time() - start_time > timeout:
|
| 223 |
+
process.kill()
|
| 224 |
+
await edit_message(msg, "❌ Download timed out (2 hours)")
|
| 225 |
+
await asyncio.sleep(5)
|
| 226 |
+
await delete_message(msg)
|
| 227 |
+
return False
|
| 228 |
+
|
| 229 |
+
# Read stdout line by line
|
| 230 |
+
line = await process.stdout.readline()
|
| 231 |
+
if not line:
|
| 232 |
+
await asyncio.sleep(0.1)
|
| 233 |
+
continue
|
| 234 |
+
|
| 235 |
+
line = line.decode().strip()
|
| 236 |
+
percent_match = progress_pattern.search(line)
|
| 237 |
+
|
| 238 |
+
if percent_match:
|
| 239 |
+
percent = int(percent_match.group(1))
|
| 240 |
+
# Update progress only when it changes
|
| 241 |
+
if percent > last_reported_percent:
|
| 242 |
+
bar = progress_bar(percent)
|
| 243 |
+
|
| 244 |
+
try:
|
| 245 |
+
await edit_message(
|
| 246 |
+
msg,
|
| 247 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 248 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 249 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 250 |
+
f"📥 <b>Downloading:</b> <code>{file_name}</code>\n"
|
| 251 |
+
f"📦 <b>Size:</b> {readable_size}\n"
|
| 252 |
+
f"🔸 {bar} 🔸\n"
|
| 253 |
+
f"🚀 <b>Progress:</b> {percent}%\n"
|
| 254 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨"
|
| 255 |
+
)
|
| 256 |
+
last_reported_percent = percent
|
| 257 |
+
except Exception as e:
|
| 258 |
+
logger.error(f"Error updating progress: {str(e)}")
|
| 259 |
+
|
| 260 |
+
await asyncio.sleep(0.1)
|
| 261 |
+
|
| 262 |
+
# Wait for process to finish
|
| 263 |
+
await process.wait()
|
| 264 |
+
|
| 265 |
+
# Verify download
|
| 266 |
+
if not os.path.exists(file_path) or os.path.getsize(file_path) < file_size * 0.95: # 95% tolerance
|
| 267 |
+
await edit_message(
|
| 268 |
+
msg,
|
| 269 |
+
f"❌ <b>Download Failed:</b>\n"
|
| 270 |
+
f"File incomplete or corrupted\n"
|
| 271 |
+
f"Expected: {readable_size}\n"
|
| 272 |
+
f"Actual: {human_readable_size(os.path.getsize(file_path)) if os.path.exists(file_path) else '0 B'}"
|
| 273 |
+
)
|
| 274 |
+
await asyncio.sleep(5)
|
| 275 |
+
await delete_message(msg)
|
| 276 |
+
return False
|
| 277 |
+
|
| 278 |
+
# Prepare for upload
|
| 279 |
+
await edit_message(
|
| 280 |
+
msg,
|
| 281 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 282 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 283 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 284 |
+
f"📤 <b>Uploading:</b> <code>{file_name}</code>\n"
|
| 285 |
+
f"📦 <b>Size:</b> {readable_size}\n"
|
| 286 |
+
f"🔸 {progress_bar(0)} 🔸\n"
|
| 287 |
+
f"🚀 <b>Progress:</b> 0%\n"
|
| 288 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨"
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
# Create caption and download button
|
| 292 |
+
caption = (
|
| 293 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 294 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 295 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 296 |
+
f"<pre>✅ Your File is Ready!</pre>\n\n"
|
| 297 |
+
f"📂 <b>File:</b> <code>{file_name}</code>\n"
|
| 298 |
+
f"📦 <b>Size:</b> {readable_size}\n"
|
| 299 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨"
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
# Create inline keyboard with direct download button
|
| 303 |
+
keyboard = InlineKeyboardMarkup([[
|
| 304 |
+
InlineKeyboardButton(f"🔗 Direct Download {readable_size}", url=download_url)
|
| 305 |
+
]])
|
| 306 |
+
|
| 307 |
+
# Send file with upload progress
|
| 308 |
+
is_video = file_name.lower().endswith(('.mp4', '.mkv', '.mov', '.avi', '.flv', '.webm'))
|
| 309 |
+
thumb_path = os.path.join(USER_DIR, "thumb.jpg")
|
| 310 |
+
|
| 311 |
+
if "thumbnail" in data:
|
| 312 |
+
try:
|
| 313 |
+
thumb_data = requests.get(data["thumbnail"]).content
|
| 314 |
+
with open(thumb_path, "wb") as f:
|
| 315 |
+
f.write(thumb_data)
|
| 316 |
+
except Exception as e:
|
| 317 |
+
logger.warning(f"Thumbnail download failed: {str(e)}")
|
| 318 |
+
thumb_path = None
|
| 319 |
+
|
| 320 |
+
# Upload progress callback
|
| 321 |
+
last_upload_percent = 0
|
| 322 |
+
|
| 323 |
+
async def progress_callback(current, total):
|
| 324 |
+
nonlocal last_upload_percent
|
| 325 |
+
percent = int(current * 100 / total)
|
| 326 |
+
|
| 327 |
+
# Update every 5% or when it changes significantly
|
| 328 |
+
if percent > last_upload_percent + 5 or percent == 100:
|
| 329 |
+
bar = progress_bar(percent)
|
| 330 |
+
try:
|
| 331 |
+
await edit_message(
|
| 332 |
+
msg,
|
| 333 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 334 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 335 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 336 |
+
f"📤 <b>Uploading:</b> <code>{file_name}</code>\n"
|
| 337 |
+
f"📦 <b>Size:</b> {readable_size}\n"
|
| 338 |
+
f"🔸 {bar} 🔸\n"
|
| 339 |
+
f"🚀 <b>Progress:</b> {percent}%\n"
|
| 340 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨"
|
| 341 |
+
)
|
| 342 |
+
last_upload_percent = percent
|
| 343 |
+
except Exception as e:
|
| 344 |
+
logger.error(f"Error updating upload progress: {str(e)}")
|
| 345 |
+
|
| 346 |
+
try:
|
| 347 |
+
# Calculate upload timeout based on file size
|
| 348 |
+
upload_timeout = max(600, int(file_size / (50 * 1024 * 1024)) * 60 + 600) # More generous timeout
|
| 349 |
+
|
| 350 |
+
if is_video:
|
| 351 |
+
duration = get_video_duration(file_path)
|
| 352 |
+
if duration == 0:
|
| 353 |
+
logger.warning("⚠️ ffprobe failed to detect duration, setting to None")
|
| 354 |
+
duration = None
|
| 355 |
+
|
| 356 |
+
# Use asyncio.wait_for for timeout handling
|
| 357 |
+
await asyncio.wait_for(
|
| 358 |
+
msg.reply_video(
|
| 359 |
+
video=file_path,
|
| 360 |
+
caption=caption,
|
| 361 |
+
thumb=thumb_path if thumb_path and os.path.exists(thumb_path) else None,
|
| 362 |
+
parse_mode=ParseMode.HTML,
|
| 363 |
+
reply_markup=keyboard,
|
| 364 |
+
progress=progress_callback,
|
| 365 |
+
duration=duration,
|
| 366 |
+
supports_streaming=SUPPORTS_STREAMING,
|
| 367 |
+
has_spoiler=HAS_SPOILER
|
| 368 |
+
),
|
| 369 |
+
timeout=upload_timeout
|
| 370 |
+
)
|
| 371 |
+
else:
|
| 372 |
+
# Use asyncio.wait_for for timeout handling
|
| 373 |
+
await asyncio.wait_for(
|
| 374 |
+
msg.reply_document(
|
| 375 |
+
document=file_path,
|
| 376 |
+
caption=caption,
|
| 377 |
+
thumb=thumb_path if thumb_path and os.path.exists(thumb_path) else None,
|
| 378 |
+
parse_mode=ParseMode.HTML,
|
| 379 |
+
reply_markup=keyboard,
|
| 380 |
+
progress=progress_callback
|
| 381 |
+
),
|
| 382 |
+
timeout=upload_timeout
|
| 383 |
+
)
|
| 384 |
+
except asyncio.TimeoutError:
|
| 385 |
+
logger.error(f"Upload timed out after {upload_timeout} seconds")
|
| 386 |
+
await edit_message(
|
| 387 |
+
msg,
|
| 388 |
+
f"❌ <b>Upload Timeout:</b>\n"
|
| 389 |
+
f"Upload took too long ({upload_timeout}s limit)\n"
|
| 390 |
+
f"Please try again with a smaller file."
|
| 391 |
+
)
|
| 392 |
+
await asyncio.sleep(5)
|
| 393 |
+
await delete_message(msg)
|
| 394 |
+
return False
|
| 395 |
+
except Exception as e:
|
| 396 |
+
logger.error(f"Upload failed: {str(e)}")
|
| 397 |
+
await edit_message(
|
| 398 |
+
msg,
|
| 399 |
+
f"❌ <b>Upload Failed:</b>\n"
|
| 400 |
+
f"{str(e)}"
|
| 401 |
+
)
|
| 402 |
+
await asyncio.sleep(5)
|
| 403 |
+
await delete_message(msg)
|
| 404 |
+
return False
|
| 405 |
+
|
| 406 |
+
# Delete progress message after successful upload
|
| 407 |
+
await delete_message(msg)
|
| 408 |
+
return True
|
| 409 |
+
|
| 410 |
+
except Exception as e:
|
| 411 |
+
logger.error(f"Processing error: {str(e)}")
|
| 412 |
+
await edit_message(
|
| 413 |
+
msg,
|
| 414 |
+
f"❌ <b>Critical Error:</b>\n"
|
| 415 |
+
f"{str(e)}"
|
| 416 |
+
)
|
| 417 |
+
await asyncio.sleep(5)
|
| 418 |
+
await delete_message(msg)
|
| 419 |
+
return False
|
| 420 |
+
finally:
|
| 421 |
+
if clean_directory(USER_DIR):
|
| 422 |
+
logger.info(f"🧹 Cleaned: {USER_DIR}")
|
| 423 |
+
else:
|
| 424 |
+
logger.warning(f"⚠️ Cleanup failed: {USER_DIR}")
|
| 425 |
+
|
| 426 |
+
# Start command handler
|
| 427 |
+
@bot.on_message(filters.command("start") & filters.private)
|
| 428 |
+
async def start_handler(client: Client, message: Message):
|
| 429 |
+
caption = (
|
| 430 |
+
"<pre>🔷🔹🔸♦️◈ 𝗧𝗘𝗥𝗔𝗕𝗢𝗫 𝗕𝗢𝗧 ◈♦️🔸🔹🔷</pre>\n\n"
|
| 431 |
+
"📘 <b>How It Works:</b>\n"
|
| 432 |
+
"➤ Paste your Terabox URL below 👇\n"
|
| 433 |
+
"➤ The bot will fetch & send the file ⚡\n\n"
|
| 434 |
+
"🌐 <b>Supported:</b> <i>(Tap the button below)</i>\n\n"
|
| 435 |
+
"📦 <b>Limit:</b> <code>1.9GB</code>\n"
|
| 436 |
+
"<pre>👨💻 Created by 𝐖𝐎𝐎𝐃𝐜𝐫𝐚𝐟𝐭</pre>"
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
keyboard = InlineKeyboardMarkup([
|
| 440 |
+
[InlineKeyboardButton("🌐 Supported Domains", callback_data="show_supported_domains")],
|
| 441 |
+
[InlineKeyboardButton(CHANNEL_NAME, url=CHANNEL_URL)]
|
| 442 |
+
])
|
| 443 |
+
|
| 444 |
+
try:
|
| 445 |
+
await message.reply_photo(
|
| 446 |
+
photo=WELCOME_URL,
|
| 447 |
+
caption=caption,
|
| 448 |
+
reply_markup=keyboard,
|
| 449 |
+
parse_mode=ParseMode.HTML
|
| 450 |
+
)
|
| 451 |
+
except FloodWait as e:
|
| 452 |
+
await asyncio.sleep(e.value)
|
| 453 |
+
await start_handler(client, message)
|
| 454 |
+
|
| 455 |
+
@bot.on_callback_query()
|
| 456 |
+
async def callback_query_handler(client, callback_query):
|
| 457 |
+
try:
|
| 458 |
+
if callback_query.data == "show_supported_domains":
|
| 459 |
+
await callback_query.answer(
|
| 460 |
+
"🌍 Supported Domains:\n"
|
| 461 |
+
"💧 terabox.com\n"
|
| 462 |
+
"💧 4funbox.co\n"
|
| 463 |
+
"💧 terabox.app\n"
|
| 464 |
+
"💧 teraboxapp.com\n"
|
| 465 |
+
"💧 teraboxlink.com\n"
|
| 466 |
+
"💧 terafileshare.com\n"
|
| 467 |
+
"💧 terasharelink.com\n"
|
| 468 |
+
"💧 1024terabox.com\n"
|
| 469 |
+
"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨\n\n"
|
| 470 |
+
"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™",
|
| 471 |
+
show_alert=True
|
| 472 |
+
)
|
| 473 |
+
except FloodWait as e:
|
| 474 |
+
await asyncio.sleep(e.value)
|
| 475 |
+
await callback_query_handler(client, callback_query)
|
| 476 |
+
|
| 477 |
+
# ✅ Add user command
|
| 478 |
+
@bot.on_message(filters.command("adduser"))
|
| 479 |
+
async def add_user_cmd(client, message):
|
| 480 |
+
if message.from_user.id != BOT_OWNER_ID:
|
| 481 |
+
return await message.reply("🚫 You cannot run this command.")
|
| 482 |
+
|
| 483 |
+
try:
|
| 484 |
+
logger.info("Adduser command triggered")
|
| 485 |
+
args = message.text.split()
|
| 486 |
+
|
| 487 |
+
if len(args) < 2:
|
| 488 |
+
return await message.reply("❌ Use: /adduser <user_id>")
|
| 489 |
+
|
| 490 |
+
try:
|
| 491 |
+
new_id = int(args[1])
|
| 492 |
+
except ValueError:
|
| 493 |
+
return await message.reply("❌ Invalid user ID! Enter a number.")
|
| 494 |
+
|
| 495 |
+
result = add_authorized_user(new_id)
|
| 496 |
+
|
| 497 |
+
if result:
|
| 498 |
+
await message.reply(f"✅ User `{new_id}` Added!")
|
| 499 |
+
|
| 500 |
+
# ✅ Notify user
|
| 501 |
+
try:
|
| 502 |
+
await client.send_message(new_id, "✅ You've been added to the authorized user list.")
|
| 503 |
+
logger.info(f"Notified user {new_id}")
|
| 504 |
+
except Exception as e:
|
| 505 |
+
logger.warning(f"Couldn't message user {new_id}: {e}")
|
| 506 |
+
|
| 507 |
+
else:
|
| 508 |
+
await message.reply(f"ℹ️ User `{new_id}` was already added.")
|
| 509 |
+
except Exception as e:
|
| 510 |
+
logger.exception("Error in adduser")
|
| 511 |
+
await message.reply(f"❌ Error: {str(e)}")
|
| 512 |
+
|
| 513 |
+
# ✅ Remove user command
|
| 514 |
+
@bot.on_message(filters.command("removeuser"))
|
| 515 |
+
async def remove_user_cmd(client, message):
|
| 516 |
+
if message.from_user.id != BOT_OWNER_ID:
|
| 517 |
+
return await message.reply("🚫 You cannot run this command.")
|
| 518 |
+
|
| 519 |
+
try:
|
| 520 |
+
logger.info("Removeuser command triggered")
|
| 521 |
+
args = message.text.split()
|
| 522 |
+
|
| 523 |
+
if len(args) < 2:
|
| 524 |
+
return await message.reply("❌ Use: /removeuser <user_id>")
|
| 525 |
+
|
| 526 |
+
try:
|
| 527 |
+
uid = int(args[1])
|
| 528 |
+
except ValueError:
|
| 529 |
+
return await message.reply("❌ Invalid user ID! Enter a number.")
|
| 530 |
+
|
| 531 |
+
result = remove_authorized_user(uid)
|
| 532 |
+
|
| 533 |
+
if result:
|
| 534 |
+
await message.reply(f"❎ User `{uid}` removed!")
|
| 535 |
+
else:
|
| 536 |
+
await message.reply(f"⚠️ User `{uid}` was not authorized.")
|
| 537 |
+
except Exception as e:
|
| 538 |
+
logger.exception("Error in removeuser")
|
| 539 |
+
await message.reply(f"❌ Error: {str(e)}")
|
| 540 |
+
|
| 541 |
+
# ✅ Userlist command
|
| 542 |
+
@bot.on_message(filters.command("userlist"))
|
| 543 |
+
async def list_users(client, message):
|
| 544 |
+
if message.from_user.id != BOT_OWNER_ID:
|
| 545 |
+
logger.warning(f"Unauthorized /userlist access attempt by: {message.from_user.id}")
|
| 546 |
+
return await message.reply("🚫 You cannot run this command.")
|
| 547 |
+
|
| 548 |
+
logger.info(f"/userlist command triggered by: {message.from_user.id}")
|
| 549 |
+
|
| 550 |
+
try:
|
| 551 |
+
users = get_authorized_users()
|
| 552 |
+
logger.info(f"AUTHORIZED_USERS inside /userlist: {users}")
|
| 553 |
+
|
| 554 |
+
if not users:
|
| 555 |
+
logger.warning("User list is empty!")
|
| 556 |
+
return await message.reply("⚠️ There are no authorized users.")
|
| 557 |
+
|
| 558 |
+
# ✅ Plain text formatting
|
| 559 |
+
text = "👤 **Authorized User List:**\n"
|
| 560 |
+
text += "═══════════════════════\n"
|
| 561 |
+
|
| 562 |
+
for i, uid in enumerate(users, start=1):
|
| 563 |
+
try:
|
| 564 |
+
user = await client.get_users(uid)
|
| 565 |
+
name = user.first_name or "No name"
|
| 566 |
+
logger.info(f"User #{i}: {name} ({uid})")
|
| 567 |
+
text += f"🔹 {i}. {name}\n🆔 {uid}\n\n"
|
| 568 |
+
except Exception as e:
|
| 569 |
+
name = "Name not found (❗Hasn't started the bot)"
|
| 570 |
+
logger.warning(f"User ID {uid} fetch failed: {str(e)}")
|
| 571 |
+
text += f"🔹 {i}. {name}\n🆔 {uid}\n\n"
|
| 572 |
+
|
| 573 |
+
text += "═══════════════════════"
|
| 574 |
+
|
| 575 |
+
# ✅ Inline button
|
| 576 |
+
developer = InlineKeyboardMarkup([
|
| 577 |
+
[InlineKeyboardButton("💧𝐖𝐎𝐎𝐃𝐜𝐫𝐚𝐟𝐭 💦", url="https://t.me/Farooq_is_king")]
|
| 578 |
+
])
|
| 579 |
+
|
| 580 |
+
# ✅ Try sending with image
|
| 581 |
+
try:
|
| 582 |
+
await message.reply_photo(
|
| 583 |
+
photo=USER_URL,
|
| 584 |
+
caption=text,
|
| 585 |
+
reply_markup=developer
|
| 586 |
+
)
|
| 587 |
+
except Exception as e:
|
| 588 |
+
logger.warning(f"Couldn't send photo: {e}")
|
| 589 |
+
await message.reply(
|
| 590 |
+
text=text,
|
| 591 |
+
reply_markup=developer,
|
| 592 |
+
disable_web_page_preview=True
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
logger.info("/userlist executed successfully.")
|
| 596 |
+
|
| 597 |
+
except Exception as e:
|
| 598 |
+
logger.exception(f"❌ Error in /userlist command: {str(e)}")
|
| 599 |
+
await message.reply(f"❌ Error: {str(e)}")
|
| 600 |
+
|
| 601 |
+
# Message handler
|
| 602 |
+
@bot.on_message(filters.private & filters.text)
|
| 603 |
+
async def message_handler(client: Client, message: Message):
|
| 604 |
+
user_id = message.from_user.id
|
| 605 |
+
text = message.text.strip()
|
| 606 |
+
|
| 607 |
+
if not is_authorized(user_id):
|
| 608 |
+
await message.reply("🚫 You are not authorized to use this bot.")
|
| 609 |
+
return
|
| 610 |
+
|
| 611 |
+
if not re.match(TERABOX_REGEX, text):
|
| 612 |
+
try:
|
| 613 |
+
error_msg = await message.reply("❌ Please send a valid Terabox link")
|
| 614 |
+
await asyncio.sleep(10)
|
| 615 |
+
await error_msg.delete()
|
| 616 |
+
except Exception:
|
| 617 |
+
pass
|
| 618 |
+
return
|
| 619 |
+
|
| 620 |
+
try:
|
| 621 |
+
msg = await message.reply(
|
| 622 |
+
f"╭━◝━━━━━━━━━━━━◜━╮\n"
|
| 623 |
+
f"⚡❍⊱❁ 𝐖𝐃 𝐙𝐎𝐍𝐄 ™\n"
|
| 624 |
+
f"╰━◞━━━━━━━━━━━━◟━╯\n\n"
|
| 625 |
+
f"🔍 <b>Processing your link...</b>\n"
|
| 626 |
+
f"✨❍⭕️━━━━━━━━━━━━━━━⭕️❍✨",
|
| 627 |
+
parse_mode=ParseMode.HTML
|
| 628 |
+
)
|
| 629 |
+
except FloodWait as e:
|
| 630 |
+
logger.warning(f"FloodWait: Sleeping for {e.value} seconds")
|
| 631 |
+
await asyncio.sleep(e.value)
|
| 632 |
+
|
| 633 |
+
if e.value > 600:
|
| 634 |
+
await message.reply("🚫 FloodWait too long. Please try again later.")
|
| 635 |
+
return
|
| 636 |
+
|
| 637 |
+
# Retry after waiting
|
| 638 |
+
await message_handler(client, message)
|
| 639 |
+
return
|
| 640 |
+
|
| 641 |
+
# Proceed only if no FloodWait
|
| 642 |
+
await process_terabox(user_id, text, msg)
|
| 643 |
+
|
| 644 |
+
# Run the bot
|
| 645 |
+
if __name__ == "__main__":
|
| 646 |
+
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
| 647 |
+
logger.info("🚀 Starting Terabox Downloader Bot...")
|
| 648 |
+
# Log the authorized users file path
|
| 649 |
+
logger.info(f"Authorized users file: {AUTHORIZED_USERS_FILE}")
|
| 650 |
+
logger.info(f"Initial authorized users: {AUTHORIZED_USERS}")
|
| 651 |
+
|
| 652 |
+
# Start the bot 💥
|
| 653 |
+
bot.run()
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pyrogram>=2.0.106
|
| 2 |
+
tgcrypto>=1.2.5
|
| 3 |
+
python-dotenv
|
| 4 |
+
flask
|
| 5 |
+
requests
|
| 6 |
+
tqdm
|
| 7 |
+
aria2p
|
| 8 |
+
regex
|
| 9 |
+
psutil
|
| 10 |
+
aiohttp
|
runtime.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
python-3.10.8
|
static/angel.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
কেমন আছেন আপনি এঞ্জেল
|
static/favicon.ico
ADDED
|
|
static/favicon.png
ADDED
|
|
templates/index.html
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 6 |
+
<title>Bot Status</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css2?family=Asap:wght@500;700&display=swap" rel="stylesheet">
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
|
| 9 |
+
<link rel="icon" href="https://i.ibb.co/j9n6nZxD/Op-log.png" type="image/png">
|
| 10 |
+
<style>
|
| 11 |
+
body {
|
| 12 |
+
margin: 0;
|
| 13 |
+
padding: 0;
|
| 14 |
+
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
|
| 15 |
+
height: 100vh;
|
| 16 |
+
display: flex;
|
| 17 |
+
justify-content: center;
|
| 18 |
+
align-items: center;
|
| 19 |
+
font-family: 'Asap', sans-serif;
|
| 20 |
+
flex-direction: column;
|
| 21 |
+
position: relative;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.typing {
|
| 25 |
+
color: #00ffc3;
|
| 26 |
+
font-size: 1.1rem;
|
| 27 |
+
font-family: 'Asap', sans-serif;
|
| 28 |
+
margin-bottom: 10px;
|
| 29 |
+
height: 24px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.text::after {
|
| 33 |
+
content: "|";
|
| 34 |
+
animation: blink 1s infinite;
|
| 35 |
+
color: #00ffc3;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
@keyframes blink {
|
| 39 |
+
0%, 100% { opacity: 1; }
|
| 40 |
+
50% { opacity: 0; }
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.image-glow {
|
| 44 |
+
width: 130px;
|
| 45 |
+
height: 130px;
|
| 46 |
+
border-radius: 50%;
|
| 47 |
+
padding: 5px;
|
| 48 |
+
background: linear-gradient(45deg, #ff00cc, #3333ff, #00ccff, #00ff99);
|
| 49 |
+
background-size: 400% 400%;
|
| 50 |
+
animation: glowRotate 6s linear infinite;
|
| 51 |
+
display: flex;
|
| 52 |
+
justify-content: center;
|
| 53 |
+
align-items: center;
|
| 54 |
+
margin-bottom: 20px;
|
| 55 |
+
box-shadow: 0 0 20px rgba(0,255,255,0.3);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.image-glow img {
|
| 59 |
+
width: 100%;
|
| 60 |
+
height: 100%;
|
| 61 |
+
border-radius: 50%;
|
| 62 |
+
object-fit: cover;
|
| 63 |
+
border: 3px solid #111;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
@keyframes glowRotate {
|
| 67 |
+
0% { background-position: 0% 50%; }
|
| 68 |
+
50% { background-position: 100% 50%; }
|
| 69 |
+
100% { background-position: 0% 50%; }
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.container {
|
| 73 |
+
background: #ffffff10;
|
| 74 |
+
padding: 40px 60px;
|
| 75 |
+
border-radius: 20px;
|
| 76 |
+
box-shadow: 0 20px 30px rgba(0, 0, 0, 0.5);
|
| 77 |
+
backdrop-filter: blur(10px);
|
| 78 |
+
text-align: center;
|
| 79 |
+
margin-bottom: 20px;
|
| 80 |
+
position: relative;
|
| 81 |
+
z-index: 1;
|
| 82 |
+
overflow: hidden;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.container::before {
|
| 86 |
+
content: "";
|
| 87 |
+
position: absolute;
|
| 88 |
+
top: -3px;
|
| 89 |
+
left: -3px;
|
| 90 |
+
right: -3px;
|
| 91 |
+
bottom: -3px;
|
| 92 |
+
background: linear-gradient(45deg, #00ffc3, #00ccff, #cc66ff, #ff3399, #00ffc3);
|
| 93 |
+
background-size: 400% 400%;
|
| 94 |
+
border-radius: 25px;
|
| 95 |
+
animation: borderAnim 10s linear infinite;
|
| 96 |
+
z-index: -1;
|
| 97 |
+
filter: blur(8px);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
@keyframes borderAnim {
|
| 101 |
+
0% { background-position: 0% 50%; }
|
| 102 |
+
50% { background-position: 100% 50%; }
|
| 103 |
+
100% { background-position: 0% 50%; }
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.status {
|
| 107 |
+
font-size: 2.5rem;
|
| 108 |
+
color: #fff;
|
| 109 |
+
text-shadow: 2px 2px 10px #00ffcc, -2px -2px 10px #006666;
|
| 110 |
+
margin-bottom: 20px;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.channel, .developer {
|
| 114 |
+
font-size: 1rem;
|
| 115 |
+
color: #ccc;
|
| 116 |
+
margin-top: 10px;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.channel a {
|
| 120 |
+
color: #00ffc3;
|
| 121 |
+
text-decoration: none;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.channel a:hover {
|
| 125 |
+
text-decoration: underline;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.button-container {
|
| 129 |
+
margin-top: 10px;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.channel-btn {
|
| 133 |
+
background: linear-gradient(145deg, #1abc9c, #16a085);
|
| 134 |
+
color: #fff;
|
| 135 |
+
font-size: 1rem;
|
| 136 |
+
padding: 12px 25px;
|
| 137 |
+
border: none;
|
| 138 |
+
border-radius: 12px;
|
| 139 |
+
box-shadow: 0 8px 20px rgba(0, 255, 204, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.2);
|
| 140 |
+
transition: 0.3s ease;
|
| 141 |
+
cursor: pointer;
|
| 142 |
+
font-family: 'Asap', sans-serif;
|
| 143 |
+
text-decoration: none;
|
| 144 |
+
display: inline-block;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.channel-btn:hover {
|
| 148 |
+
transform: translateY(-3px);
|
| 149 |
+
box-shadow: 0 12px 24px rgba(0, 255, 204, 0.4);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.channel-btn i {
|
| 153 |
+
margin-right: 8px;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
.footer-badge {
|
| 157 |
+
position: fixed;
|
| 158 |
+
bottom: 10px;
|
| 159 |
+
background: linear-gradient(145deg, #00b894, #0984e3);
|
| 160 |
+
padding: 10px 20px;
|
| 161 |
+
color: white;
|
| 162 |
+
font-weight: bold;
|
| 163 |
+
font-size: 0.9rem;
|
| 164 |
+
border-radius: 10px;
|
| 165 |
+
font-family: 'Asap', sans-serif;
|
| 166 |
+
box-shadow: 0 5px 15px rgba(0, 255, 255, 0.3);
|
| 167 |
+
text-align: center;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.spinner {
|
| 171 |
+
width: 40px;
|
| 172 |
+
height: 40px;
|
| 173 |
+
margin-top: 20px;
|
| 174 |
+
border: 4px solid #00ffc3;
|
| 175 |
+
border-top: 4px solid transparent;
|
| 176 |
+
border-radius: 50%;
|
| 177 |
+
animation: spin 1s linear infinite;
|
| 178 |
+
margin: 20px auto;
|
| 179 |
+
box-shadow: 0 0 12px #00ffc3;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
@keyframes spin {
|
| 183 |
+
0% { transform: rotate(0deg); }
|
| 184 |
+
100% { transform: rotate(360deg); }
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
@media (max-width: 600px) {
|
| 188 |
+
.container {
|
| 189 |
+
padding: 20px 25px;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.status {
|
| 193 |
+
font-size: 1.8rem;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.channel-btn {
|
| 197 |
+
font-size: 0.95rem;
|
| 198 |
+
padding: 10px 20px;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
</style>
|
| 202 |
+
</head>
|
| 203 |
+
<body>
|
| 204 |
+
<div class="spinner"></div>
|
| 205 |
+
|
| 206 |
+
<!-- ✅ Typing Animation -->
|
| 207 |
+
<div class="typing"><span class="text"></span></div>
|
| 208 |
+
|
| 209 |
+
<!-- 🌟 Profile Image with glow -->
|
| 210 |
+
<div class="image-glow">
|
| 211 |
+
<img src="https://i.ibb.co/j9n6nZxD/Op-log.png" alt="Bot Logo" />
|
| 212 |
+
</div>
|
| 213 |
+
|
| 214 |
+
<div class="container">
|
| 215 |
+
<div class="status"><i class="fas fa-robot"></i> Bot is running <i class="fas fa-check-circle"></i></div>
|
| 216 |
+
<div class="channel"><i class="fas fa-bullhorn"></i> Channel: <a href="https://t.me/Opleech_WD" target="_blank">@Opleech_WD</a></div>
|
| 217 |
+
<div class="developer"><i class="fas fa-user-cog"></i> Developer: <strong>𝐖𝐎𝐎𝐃𝐜𝐫𝐚𝐟𝐭</strong></div>
|
| 218 |
+
</div>
|
| 219 |
+
|
| 220 |
+
<div class="button-container">
|
| 221 |
+
<a href="https://t.me/Opleech_WD" class="channel-btn" target="_blank">
|
| 222 |
+
<i class="fab fa-telegram-plane"></i> Join Our Telegram Channel
|
| 223 |
+
</a>
|
| 224 |
+
</div>
|
| 225 |
+
|
| 226 |
+
<div class="footer-badge">
|
| 227 |
+
© 2025 Creator 𝐖𝐎𝐎𝐃𝐜𝐫𝐚𝐟𝐭 ⭐
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
<!-- ✅ JavaScript Typing Animation -->
|
| 231 |
+
<script>
|
| 232 |
+
document.addEventListener("DOMContentLoaded", function () {
|
| 233 |
+
const words = ["Terabox Bot is online..."];
|
| 234 |
+
let i = 0, j = 0, current = "", isDeleting = false;
|
| 235 |
+
const speed = 120;
|
| 236 |
+
const el = document.querySelector(".text");
|
| 237 |
+
|
| 238 |
+
function type() {
|
| 239 |
+
if (i < words.length) {
|
| 240 |
+
if (!isDeleting && j <= words[i].length) {
|
| 241 |
+
current = words[i].slice(0, j++);
|
| 242 |
+
} else if (isDeleting && j >= 0) {
|
| 243 |
+
current = words[i].slice(0, j--);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
el.innerHTML = current;
|
| 247 |
+
|
| 248 |
+
if (j === words[i].length) isDeleting = true;
|
| 249 |
+
if (isDeleting && j === 0) {
|
| 250 |
+
isDeleting = false;
|
| 251 |
+
i = (i + 1) % words.length;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
setTimeout(type, speed);
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
type();
|
| 259 |
+
});
|
| 260 |
+
</script>
|
| 261 |
+
</body>
|
| 262 |
+
</html>
|
utils/duration.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import os
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
def get_video_duration(file_path):
|
| 6 |
+
try:
|
| 7 |
+
result = subprocess.run(
|
| 8 |
+
[
|
| 9 |
+
"ffprobe",
|
| 10 |
+
"-v", "error",
|
| 11 |
+
"-select_streams", "v:0",
|
| 12 |
+
"-show_entries", "format=duration",
|
| 13 |
+
"-of", "default=noprint_wrappers=1:nokey=1",
|
| 14 |
+
file_path
|
| 15 |
+
],
|
| 16 |
+
stdout=subprocess.PIPE,
|
| 17 |
+
stderr=subprocess.STDOUT,
|
| 18 |
+
text=True,
|
| 19 |
+
timeout=180
|
| 20 |
+
)
|
| 21 |
+
duration_str = result.stdout.strip()
|
| 22 |
+
|
| 23 |
+
# ✅ Real float check
|
| 24 |
+
try:
|
| 25 |
+
duration = float(duration_str)
|
| 26 |
+
return int(duration)
|
| 27 |
+
except ValueError:
|
| 28 |
+
print("⚠️ Invalid duration format:", duration_str)
|
| 29 |
+
return 0
|
| 30 |
+
|
| 31 |
+
except subprocess.TimeoutExpired:
|
| 32 |
+
print("⚠️ ffprobe timed out")
|
| 33 |
+
return 0
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"⚠️ Duration error: {e}")
|
| 36 |
+
return 0
|
| 37 |
+
|
| 38 |
+
def sanitize_filename(filename):
|
| 39 |
+
return re.sub(r'[\\/*?:"<>|]', "_", filename)
|