Spaces:
Runtime error
Runtime error
Fix requirements
Browse files- requirements.txt +5 -104
requirements.txt
CHANGED
|
@@ -1,104 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
import logging
|
| 7 |
-
import tempfile
|
| 8 |
-
import yt_dlp
|
| 9 |
-
from pyrogram import Client, filters
|
| 10 |
-
from pyrogram.enums import ParseMode
|
| 11 |
-
from flask import Flask, request, abort
|
| 12 |
-
|
| 13 |
-
logging.basicConfig(level=logging.INFO)
|
| 14 |
-
logger = logging.getLogger(__name__)
|
| 15 |
-
|
| 16 |
-
API_ID = os.getenv('API_ID')
|
| 17 |
-
API_HASH = os.getenv('API_HASH')
|
| 18 |
-
BOT_TOKEN = os.getenv('BOT_TOKEN')
|
| 19 |
-
WEBHOOK_URL = os.getenv('WEBHOOK_URL', '')
|
| 20 |
-
|
| 21 |
-
logger.info(f"Bot starting with webhook...")
|
| 22 |
-
|
| 23 |
-
app = Client("TikTokDownloaderBot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 24 |
-
|
| 25 |
-
# Flask for webhook
|
| 26 |
-
flask_app = Flask(__name__)
|
| 27 |
-
|
| 28 |
-
@flask_app.route('/webhook', methods=['POST'])
|
| 29 |
-
async def webhook():
|
| 30 |
-
"""Handle incoming Telegram updates via webhook"""
|
| 31 |
-
if request.headers.get('Content-Type') != 'application/json':
|
| 32 |
-
abort(403)
|
| 33 |
-
|
| 34 |
-
json_update = request.get_json()
|
| 35 |
-
if not json_update:
|
| 36 |
-
abort(400)
|
| 37 |
-
|
| 38 |
-
await app.process_update(json_update)
|
| 39 |
-
return 'OK'
|
| 40 |
-
|
| 41 |
-
@app.on_message(filters.command("start") & filters.private)
|
| 42 |
-
async def start_handler(client, message):
|
| 43 |
-
await message.reply_text("π **Welcome!**\n\nSend TikTok link with `/tt <url>`", parse_mode=ParseMode.MARKDOWN)
|
| 44 |
-
|
| 45 |
-
@app.on_message(filters.command("help") & filters.private)
|
| 46 |
-
async def help_handler(client, message):
|
| 47 |
-
await message.reply_text("π **Help:**\n\nSend `/tt <tiktok_url>` to download video.", parse_mode=ParseMode.MARKDOWN)
|
| 48 |
-
|
| 49 |
-
@app.on_message(filters.command("tt") & filters.private)
|
| 50 |
-
async def download_handler(client, message):
|
| 51 |
-
if len(message.command) < 2:
|
| 52 |
-
await message.reply_text("β Usage: `/tt <tiktok_url>`", parse_mode=ParseMode.MARKDOWN)
|
| 53 |
-
return
|
| 54 |
-
|
| 55 |
-
url = message.command[1]
|
| 56 |
-
status_msg = await message.reply_text("π Searching...")
|
| 57 |
-
|
| 58 |
-
try:
|
| 59 |
-
await status_msg.edit("π‘ Fetching info...")
|
| 60 |
-
ydl_opts = {'quiet': True, 'extract_flat': False}
|
| 61 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 62 |
-
info = ydl.extract_info(url, download=False)
|
| 63 |
-
title, views, duration = info.get('title','Video'), info.get('view_count',0), info.get('duration',0)
|
| 64 |
-
|
| 65 |
-
await status_msg.edit("β¬οΈ Downloading...")
|
| 66 |
-
out_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
| 67 |
-
out_file.close()
|
| 68 |
-
|
| 69 |
-
ydl_opts = {"format": "mp4", "outtmpl": out_file.name, "quiet": True}
|
| 70 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 71 |
-
ydl.download([url])
|
| 72 |
-
|
| 73 |
-
await status_msg.edit("β¬οΈ Uploading...")
|
| 74 |
-
dur = f"{int(duration//60)}:{int(duration%60):02d}" if duration else "N/A"
|
| 75 |
-
caption = f"π΅ {title}\nποΈ {views:,} views\nβ±οΈ {dur}\nπ [Link]({url})"
|
| 76 |
-
|
| 77 |
-
await message.reply_video(video=out_file.name, caption=caption, parse_mode=ParseMode.MARKDOWN)
|
| 78 |
-
await status_msg.delete()
|
| 79 |
-
os.remove(out_file.name)
|
| 80 |
-
|
| 81 |
-
except Exception as e:
|
| 82 |
-
logger.error(f"Error: {e}")
|
| 83 |
-
await status_msg.edit(f"β Error: {str(e)}", parse_mode=ParseMode.MARKDOWN)
|
| 84 |
-
|
| 85 |
-
async def main():
|
| 86 |
-
"""Main function to run bot with webhook"""
|
| 87 |
-
if WEBHOOK_URL:
|
| 88 |
-
logger.info(f"Setting webhook to: {WEBHOOK_URL}")
|
| 89 |
-
await app.set_webhook(WEBHOOK_URL, drop_pending_updates=True)
|
| 90 |
-
logger.info("Webhook set! Running Flask + Pyrogram...")
|
| 91 |
-
|
| 92 |
-
# Run Flask in background
|
| 93 |
-
from threading import Thread
|
| 94 |
-
Thread(target=lambda: flask_app.run(host='0.0.0.0', port=7860, debug=False, use_reloader=False), daemon=True).start()
|
| 95 |
-
|
| 96 |
-
# Keep running
|
| 97 |
-
while True:
|
| 98 |
-
await asyncio.sleep(3600)
|
| 99 |
-
else:
|
| 100 |
-
logger.info("No WEBHOOK_URL set, running in polling mode...")
|
| 101 |
-
await app.run()
|
| 102 |
-
|
| 103 |
-
if __name__ == "__main__":
|
| 104 |
-
asyncio.run(main())
|
|
|
|
| 1 |
+
pyrogram
|
| 2 |
+
tgcrypto
|
| 3 |
+
yt-dlp
|
| 4 |
+
python-dotenv
|
| 5 |
+
flask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|