This Telegram Bot, based on the Telethon client, is designed to automatically download multimedia files sent to it. Additionally, it now has the capability to download videos or audios from YouTube and direct links to files via their URL.
File Organization:
Extended Functionality:
Enjoy an automated and organized downloading experience with telethon_downloader!
Pull or build the docker image and launch it with the following environment variables:
TG_AUTHORIZED_USER_ID : <telegram ´chat_id´ authorized>
NOTE: Unique identification of the user who has permissions to send files to the bot.
TG_API_ID : <telegram API key generated at ´Generating Telegram API keys´>
TG_API_HASH : <telegram API hash generated at ´Generating Telegram API keys´>
TG_BOT_TOKEN : <telegram BOT token generated at ´Creating a Telegram Bot´>
PUID [OPTIONAL]: <Unique identification of the user in the system, used for assigning permissions.>
PGID [OPTIONAL]: <Unique identifier for a group of users, used for assigning specific permissions to the group.>
PERMISSIONS_FOLDER [OPTIONAL]: <Folder permissions. (default: 777)>
PERMISSIONS_FILE [OPTIONAL]: <File permissions. (default: 755)>
TZ [OPTIONAL]: <Sets the system timezone, adjusting it based on the geographical location of the server or user.>
Example: America/Santiago
APP_LANGUAGE [OPTIONAL]: <bot messages will appear in the language configured in this variable (default: en_EN)>
NOTE: Now messages can be in English, Spanish, or any other language by modifying or adding language templates in the "locale" path. For example: Creating the template "de_DE.txt" for the German language and adding "de_DE" to the environment variable.
NOTE: The community is encouraged to generate templates in the languages they use and add them to the "locale" folder of this project.
TG_UNZIP_TORRENTS [OPTIONAL]: <In backlog (default: True)>
ENABLED_UNZIP [OPTIONAL]: <Enables unzip functionality for zip files (default: True)>
ENABLED_UNRAR [OPTIONAL]: <Enables unrar functionality for rar files (default: True)>
ENABLED_7Z [OPTIONAL]: <In backlog (default: True)>
TG_MAX_PARALLEL [OPTIONAL]: <maximum number of parallel downloads allowed (default: 4)>
TG_DL_TIMEOUT [OPTIONAL]: <maximum time (in seconds) to wait for a download to complete. after this time the download is cancelled and an error is triggered (default: 3600)>
NOTE: DOWNLOADED FILES ARE SAVED AT A TMP DIRECTORY UNTIL THE DOWNLOAD IS COMPLETED TO PROTECT FROM MOVING UNFINISHED FILES
TG_PROGRESS_DOWNLOAD [OPTIONAL]: <Show download progress (default: True)>
PROGRESS_STATUS_SHOW [OPTIONAL]: <Show download progress every 10% (default: 10)>
YOUTUBE_FORMAT_AUDIO [OPTIONAL]: <YouTube audio download format (default: bestaudio/best)>
YOUTUBE_FORMAT_VIDEO [OPTIONAL]: <YouTube video download format (default: bestvideo+bestaudio/best)>
YOUTUBE_DEFAULT_DOWNLOAD [OPTIONAL]: <Automatic YouTube download preference, AUDIO or VIDEO (default: VIDEO)>
YOUTUBE_DEFAULT_EXTENSION [OPTIONAL]: <Extension format for downloading YouTube videos (default: MKV)>
YOUTUBE_SHOW_OPTION [OPTIONAL]: <Show or hide buttons to select YouTube Video or Audio download (default: True)>
YOUTUBE_TIMEOUT_OPTION [OPTIONAL]: <Time in which buttons are displayed to download YouTube Video or Audio before the default option "YOUTUBE_DEFAULT_DOWNLOAD" is chosen (default: 5)>
YOUTUBE_AUDIO_FOLDER [OPTIONAL]: <Folder where YouTube audios will be downloaded (default: /download/youtube)>
NOTE: To add a new path to these variables, remember to map them in the "volumes" section in docker.
YOUTUBE_VIDEO_FOLDER [OPTIONAL]: <Folder where YouTube videos will be downloaded (default: /download/youtube)>
NOTE: To add a new path to these variables, remember to map them in the "volumes" section in docker.
YOUTUBE_LINKS_SUPPORTED [OPTIONAL]: <YouTube links supported for downloading videos (default: youtube.com,youtu.be)>
NOTE: NOTE: THIS VARIABLE MUST BE UPDATED IF MORE URL IS REQUIRED TO BE ADDED TO THE YOUTUBE DOWNLOAD SUPPORT
/config: Path where configuration files, pending downloads, and recent downloads are stored.
/download: Folder where files are downloaded.
/watch: Folder where torrent files are downloaded, and transmission will upload them.
A config.ini file is created that contains file extensions and paths where these files should be downloaded based on:
[DEFAULT_PATH]
mp4 = /download/mp4
[GROUP_PATH]
-100118xxxxxxxx = /download/games
[REGEX_PATH]
/Halo/ = /download/Serie YYYYYY
[DEFAULT]
pdf = /download/pdf
cbr = /download/pdf
[DEFAULT_PATH]
pdf = /download/pdf
flac = /download/mp3
jpg = /download/jpg
mp4 = /download/mp4
[REGEX_PATH]
/example/i = /download/example
[GROUP_PATH]
0000000000 = /download/example
Before working with Telegram's API, you need to get your own API ID and hash:
Go to https://my.telegram.org/ 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 hash is secret and Telegram won't let you revoke it. Don't post it anywhere!
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.
If you need to obtain the PUID (User ID) and PGID (Group ID) in Linux, you can easily do so with the following commands:
Make sure to replace
id -u <USUARIO>
id -g <USUARIO>
root@Jonas > id -u nobody
99
root@Jonas > id -g nobody
100
version: '3'
services:
telethon-downloader:
image: jsavargas/telethon_downloader
container_name: telethon-downloader
restart: unless-stopped
network_mode: host
environment:
- PUID=1000
- PGID=1000
- PERMISSIONS_FOLDER=777
- PERMISSIONS_FILE=755
- TG_AUTHORIZED_USER_ID=63460,645261 #<telegram chat_id authorized>
- TG_API_ID=<telegram API key generated at ´Generating Telegram API keys´>
- TG_API_HASH=<telegram API hash generated at ´Generating Telegram API keys´>
- TG_BOT_TOKEN=<telegram BOT token generated at ´Creating a Telegram Bot´>
- TZ=America/Santiago
- APP_LANGUAGE=es_ES # OPTIONAL
- TG_UNZIP_TORRENTS=True # OPTIONA
- ENABLED_UNZIP=True # OPTIONA
- ENABLED_UNRAR=True # OPTIONA
- TG_MAX_PARALLEL=4 # OPTIONAL
- TG_DL_TIMEOUT=4600 # OPTIONAL
- TG_PROGRESS_DOWNLOAD=True # OPTIONAL
- PROGRESS_STATUS_SHOW=10 # OPTIONAL
- YOUTUBE_FORMAT_AUDIO=bestaudio/best # OPTIONAL
- YOUTUBE_FORMAT_VIDEO=bestvideo+bestaudio/best # OPTIONAL
- YOUTUBE_DEFAULT_DOWNLOAD=VIDEO # OPTIONAL (AUDIO/VIDEO)
- YOUTUBE_DEFAULT_EXTENSION=MKV # OPTIONAL (mkv/mp4)
- YOUTUBE_SHOW_OPTION=True # OPTIONAL (True/False)
- YOUTUBE_TIMEOUT_OPTION=3 # OPTIONAL
- YOUTUBE_AUDIO_FOLDER=/youtube/audio # OPTIONAL
- YOUTUBE_VIDEO_FOLDER=/youtube/video # OPTIONAL
volumes:
- /path/to/config:/config
- /path/to/download/torrent/watch:/watch
- /path/to/download:/download
- /path/to/youtube:/youtube
pending_messages
via DISABLE_PENDING_MESSAGES
environment variable.telethon
to version 1.37.0.yt_dlp
to version 2024.11.04.yt_dlp
to version 2024.08.06.telethon
to version 1.36.0.yt_dlp
to version 2024.05.27.MESSAGE_NO_LINKS_DOWNLOAD
feature./config/download_files.json
to track the last 500 downloaded files, including download dates, original file names, and, if renamed, the new names along with the renaming date.download_pending_messages
.