""" app.py β FastAPI + CompresUltra Bot DiseΓ±ado para Hugging Face Spaces (o cualquier servidor con uvicorn). El bot Pyrogram y FastAPI comparten el MISMO event loop asyncio. Esto evita conflictos con asyncio y garantiza que el bot funcione. Arrancar con: uvicorn app:app --host 0.0.0.0 --port 7860 """ import asyncio import logging from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.responses import HTMLResponse # Importamos las funciones de inicio/parada del bot from main import start_bot, stop_bot logger = logging.getLogger(__name__) @asynccontextmanager async def lifespan(application: FastAPI): """ Ciclo de vida de FastAPI: - Al arrancar: inicia el bot en el mismo event loop. - Al apagar: detiene el bot limpiamente. """ logger.info("π§ Arrancando CompresUltra Bot...") await start_bot() # β awaitable, mismo event loop logger.info("β Bot activo y FastAPI listo.") yield # β FastAPI sirve peticiones aquΓ logger.info("π Apagando bot...") await stop_bot() app = FastAPI( title="CompresUltra Bot", description="Bot de Telegram para comprimir videos con FFmpeg y colas por plan", version="6.0", lifespan=lifespan, ) @app.get("/", response_class=HTMLResponse) async def root(): return """
Bot de Telegram para comprimir videos con FFmpeg y colas por plan
β‘ Motor: libx265 | ποΈ DB: Supabase / Postgres