🤖
TG Media Downloader Bot
A telegram bot based on Pyrogram that downloads on a local storage the following media files: animation, audio, document, photo, video, voice.
The bot is inspired from the Telethon-based bot by rodriguezst.
TO-DO
- It runs
- It downloads supported media
- Use a fallback for missing metadata
- Allow custom names for un-named files instead of file_unique_id
- Improve error handling related to Telegram's service
🧐
Why should I use a MTProto bot? MTProto clients connect directly to Telegram’s servers, which means there is no HTTP connection, no “polling” or “web hooks”. This means less overhead, since the protocol used between you and the server is much more compact than HTTP requests with responses in wasteful JSON.
Since there is a direct connection to Telegram’s servers, even if their Bot API endpoint is down, you can still have connection to Telegram directly.
Using a MTProto client, you are also not limited to the public API that they expose, and instead, you have full control of what your bot can do.
HTTP Bots can't download file bigger than 10mb meanwhile MTProto can download files of 1.5~2GB!
🧠
How to use After the setup the bot is ready to use, send/forward any supported media to the bot to download on local storage.
The bot supports the following commands:
Command | Role |
---|---|
/start |
Initial command (invoked by Telegram) when you start the chat with the bot for the first time. |
/help |
Gives you the available commands list. |
/about |
Gives you information about the project. |
/abort |
Cancel all the pending downloads. |
/status |
Gives you the current configuration. |
/usage |
Gives you the usage instructions. |
⚙️
Setup The bot requires the following env-vars o work properly:
Variable Name | Role |
---|---|
TG_API_ID | Telegram API ID obtained via developer settings (see here) |
TG_API_HASH | Telegram API HASH obtained via developer settings (see here) |
TG_BOT_TOKEN | Telegram Bot Token obtained via BotFather (see here) |
TG_MAX_PARALLEL [OPTIONAL] | Maximum number of parallel downloads allowed (default: 4) A big number can cause flood bocks |
TG_DL_TIMEOUT [OPTIONAL] | Maximum time (in seconds) to wait for a download to complete (default: 5400) In case of timeout the download is aborted and a error is triggered |
TG_DOWNLOAD_PATH | Download folder on the local storage/docker mount where the files will be downloaded The files will appear inside the folder only after download completation |
TG_AUTHORIZED_USER_ID | List separated by comma of authorized users' id, you can get them using the userinfobot It can't be empty |
You can run the bot inside a Docker container or directly on your PC/Server OS.
🐋
Docker If you want to containerize the bot, just pull or build a image and provide the requires env-vars.
A official GitHub Packages is available here.
Make sure that the download path is a mounted as a volume to allow the host system to access the downloaded files.
🖥️
Barebone If you want to run the bot directly on your PC/Server OS, do the following:
-
Make sure to have Python 3.6+ installed on your system;
-
Create a folder anywhere on your pc and clone the repository there:
git clone https://github.com/LightDestory/TG_MediaDownloader
-
Install the requirements using pip:
pip install -r requirements.txt
-
Execute the bot and follow the wizard to provide the env-vars:
python ./tg_downloader.py
Generating Telegram API keys
Before working with Telegram's API, you need to get your own API ID and hash:
- Go to My Telegram and login with your phone number;
- Click under API Development tools;
- A Create new application window will appear. Fill in your application details. There is no need to enter any URL, and only the first two fields (App title and Short name) can currently be changed later;
- Click on Create application at the end. Remember that your API ID and API Hash are secrets and Telegram won't let you revoke it. Don't post it anywhere!
Creating a Telegram Bot
-
Open a conversation with @BotFather in Telegram
-
Use the /newbot command to create a new bot. The BotFather will ask you for a name and username, then generate an authorization token for your new bot.
- The name of your bot is displayed in contact details and elsewhere.
- The Username is a short name, to be used in mentions and telegram.me links. Usernames are 5-32 characters long and are case-insensitive, but may only include Latin characters, numbers, and underscores. Your bot`s username must end in ‘bot’, e.g. ‘tetris_bot’ or ‘TetrisBot’.
- The token is a string along the lines of 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw that is required to authorize the bot and send requests to the Bot API. Keep your token secure and store it safely, it can be used by anyone to control your bot.
Support
⚠️
License
This collection is under GNU GPL-3.0 License.