File size: 2,697 Bytes
bbe8697 63cca97 bbe8697 c99eae0 63cca97 bbe8697 63cca97 f1bbba1 bbe8697 080dcca bbe8697 d3fb920 bbe8697 d3fb920 0c07060 c99eae0 437ba06 5c8fe4f bbe8697 0b24781 437ba06 c8af977 437ba06 0b24781 c99eae0 0b24781 d044791 8e3c807 63cca97 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | from fastapi import FastAPI, Request
from pyrogram import Client, filters
import os
import requests
import logging
import asyncio
from aria import Aria, DownloadResult
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
API_ID = os.environ.get("API_ID", 2589472)
API_HASH = os.environ.get("API_HASH", "5243628014db9798d6775b330e542602")
TOKEN = os.environ.get("TOKEN", "6520286363:AAEe0c5v_JQf8ztatUx8ZeO_ARXrJkYsluI")
async def clientbot():
bot = Client(":memory:", api_id=API_ID, api_hash=API_HASH, bot_token=TOKEN)
aria2 = Aria(bot)
@bot.on_message(filters.command("start"))
async def start_command(client, message):
await message.reply_text("Bot has started!")
logger.info("Start command received and responded")
@bot.on_message(filters.command("download"))
async def download_command(client, message):
if len(message.command) < 2:
await message.reply_text("Please provide a URL to download.")
return
url = message.command[1]
chat_id = message.chat.id
result = aria2.add_download(url, chat_id)
if isinstance(result, str) and result.startswith("Failed"):
await message.reply_text(f"Failed to start download: {result}")
logger.error(f"Failed to start download for URL: {url} - Error: {result}")
else:
await message.reply_text(f"Download started: {url}\nGID: {result}\nDownload path: /app/download")
logger.info(f"Download started: {url} - GID: {result}")
@bot.on_message(filters.command("status"))
async def status_command(client, message):
if len(message.command) < 2:
await message.reply_text("Please provide the GID of the download.")
return
gid = message.command[1]
result = aria2.get_download_status(gid)
if isinstance(result, str):
await message.reply_text(f"Failed to get download status: {result}")
logger.error(f"Failed to get download status for GID: {gid} - Error: {result}")
else:
status_message = (
f"Download status:\n"
f"Name: {result.name}\n"
f"Status: {result.status}\n"
f"Total Length: {result.total_length}\n"
f"Completed Length: {result.completed_length}\n"
f"Download Speed: {result.download_speed}\n"
f"Directory: {result.dir}"
)
await message.reply_text(status_message)
logger.info(f"Download status requested: {gid}")
aria2.start_listener()
await bot.start()
return bot
|