How ritikroy960/uploader-bot works
Project type and purpose
• This is a backend-only Python Telegram Bot (“Uploader-Bot”) designed to download media (via yt-dlp/ffmpeg) from supported sites or HTTP/HTTPS links and upload them to Telegram chats. It also supports user management, permanent thumbnails, broadcasting, and stores user data in MongoDB. It runs on Heroku.
File structure
• Top-level scripts/config:
– bot.py: entry point; initializes the Pyrogram client, loads plugins, handles updates
– config.py: holds environment variables (API keys, database URIs)
– translation.py: multi-language message strings
– Procfile, runtime.txt, app.json: Heroku deployment descriptors
– requirements.txt: Python dependencies (pyrogram, pymongo, yt-dlp, ffmpeg, etc.)
• database/
– database.py: connection logic to MongoDB
– access.py, adduser.py: CRUD operations for user data, thumbnails, stats
• helper_funcs/
– display_progress.py: progress callbacks for uploads/downloads
– help_Nekmo_ffmpeg.py: ffmpeg wrapper utilities
– help_uploadbot.py: common routines for assembling/sending files
• plugins/
– modules named after commands: admin.py, broadcast.py, buttons.py, force-sub, youtube_dl_button.py, etc.
– Each plugin registers handlers for specific commands or callback queries.
Diagramming main components
a. Components
1) Telegram API (Cloud)
2) Uploader-Bot Application (Heroku dyno)
– Entry Point (bot.py & Pyrogram client)
– Plugin Layer (plugins/*.py)
– Helper Utilities (helper_funcs/*.py)
– Data Access Layer (database/*.py)
– Configuration & Translation
3) MongoDB Service (external, via URI)
4) External Media Sources (YouTube, HTTP hosts, Zee5, Voot, etc.)
5) System Tools (yt-dlp, ffmpeg buildpacks)
b. Relationships and data flow
1) Telegram client polls or receives webhooks from Telegram API → bot.py
2) bot.py dispatches updates to plugin handlers (plugins/*.py)
3) Handlers invoke helper_funcs for downloads/uploads:
– Call yt-dlp/ffmpeg subprocess → raw media files
– Use Pyrogram APIs to send media back to Telegram
– Use display_progress callbacks for user feedback
4) Plugins & data layer interact with MongoDB via database/*.py to:
– Create & retrieve user records (adduser/access)
– Store/delete thumbnail URLs
– Track broadcast statistics
5) Config drives all environment-specific settings; translation provides user messages.
6) Heroku buildpacks supply ffmpeg and dependencies.
c. Architectural patterns & principles
– Modular plugin architecture: each command lives in its own file, loosely coupled by a central dispatcher
– Layered separation: entry point → plugin handlers → helper functions → database access
– Externalization of configuration for 12-factor compliance on Heroku
– Use of asynchronous callbacks (Pyrogram) and subprocess calls for long-running tasks
d. Key technologies
– Python 3.x, Pyrogram (Telegram MTProto library)
– yt-dlp & ffmpeg for media handling
– MongoDB (pymongo) for persistence
– Heroku (Procfile, buildpacks) for deployment
Essential details to capture
• Bot entry point (bot.py with Pyrogram client) and plugin loader
• Separation of handlers (plugins) vs. utility code (helper_funcs) vs. data layer (database)
• Configuration module driving environment settings (Heroku, MongoDB URI, API keys)
• External services: Telegram, MongoDB, yt-dlp/ffmpeg, supported media websites
• Data flows for download, upload, database operations, broadcast