Download bot.py from alaskavix/README: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/spaces/alaskavix/README/resolve/main/bot.py
- Command line
-
hf download hf://spaces/alaskavix/README/bot.py
-
curl -L -o bot.py https://huggingface.co/spaces/alaskavix/README/resolve/main/bot.py
2.7 kB
| 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) | |
| async def start_command(client, message): | |
| await message.reply_text("Bot has started!") | |
| logger.info("Start command received and responded") | |
| 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}") | |
| 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 | |