Skip to content

naftoli44/telegram_youtube_downloader

 
 

Repository files navigation

Telegram YouTube downloader


Multithreaded Telegram bot that downloads YouTube videos, you can run it with single command.

GitHub top language GitHub repo size GitHub Docker Pulls Docker Image Size (tag)

Table of contents

Demo

drawing drawing


Bot commands

  • /about
  • /help
  • /formats
  • /audio <youtube link> or /a <youtube link>
  • /video <youtube link> or /v 1080p <youtube link>
  • /search <query> or /s <query>

Setting it up

Docker

  1. Get a telegram bot key.
  2. (optional) Get a youtube api key. See search command
  3. Install Docker. docker docs
sudo apt update
sudo apt install docker.io -y
  1. Run the container with your bot key. docker image
sudo docker run -d --name telegram_youtube_downloader -e TELEGRAM_BOT_KEY=<YOUR_BOT_KEY> cccaaannn/telegram_youtube_downloader:latest
  • (optional) To run bot with search feature
sudo docker run -d --name telegram_youtube_downloader -e TELEGRAM_BOT_KEY=<YOUR_BOT_KEY> -e YOUTUBE_API_KEY=<YOUR_API_KEY> cccaaannn/telegram_youtube_downloader:latest
  • (optional) Also you can map logs to a volume.
sudo docker run -d --name telegram_youtube_downloader -e TELEGRAM_BOT_KEY=<YOUR_BOT_KEY> -e YOUTUBE_API_KEY=<YOUR_API_KEY> -v /home/can/logs:/telegram_youtube_downloader/logs cccaaannn/telegram_youtube_downloader:latest

Ubuntu

  1. Get a telegram bot key.
  2. (optional) Get a youtube api key. See search command
  3. Install ffmpeg
sudo apt update
sudo apt upgrade -y
sudo apt install ffmpeg -y
  1. Install python and virtualenv
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt install python3.7 -y

sudo apt install python3-virtualenv -y
  1. Add your bot key to environment. Also check the alternative ways to pass keys.
export TELEGRAM_BOT_KEY=<YOUR_BOT_KEY>
source /etc/environment
  • (optional) To run bot with search feature
export YOUTUBE_API_KEY=<YOUR_API_KEY>
source /etc/environment
  1. Install the repository and run the bot
# Install repository
git clone https://github.com/cccaaannn/telegram_youtube_downloader.git
cd telegram_youtube_downloader

# Create virtualenv
virtualenv -p /usr/bin/python3.7 venv
source venv/bin/activate

# Install requirements
pip install -r requirements.txt

# Run
python telegram_youtube_downloader

Windows

  1. Get a telegram bot key.
  2. (optional) Get a youtube api key. See search command
  3. Download ffmpeg from ffmpeg.org.
  4. Add ffmpeg to environment or add the path to telegram_youtube_downloader\configs\config.yaml. configurations.
  5. Install python from python.org.
  6. Install requirements.
pip install -r requirements.txt
  1. Run on cmd/terminal. Also check alternative ways to pass keys.
python telegram_youtube_downloader -k <YOUR_BOT_KEY>
  • (optional) To run bot with search feature
python telegram_youtube_downloader -k <YOUR_BOT_KEY>,<YOUR_API_KEY>

Search command

  • /search is an optional feature, and requires a youtube api key.
  • With search enabled you can make youtube searches and download from search results that listed as a button menu.
  • You can get the key from console.developers.google.com

Alternative ways to pass keys

  1. With environment (Default)
    • TELEGRAM_BOT_KEY key must be present on environment variables.
    • To use /search, YOUTUBE_API_KEY key must be present on environment variables.
python telegram_youtube_downloader
  1. With file
    • First line has to be <YOUR_BOT_KEY>.
    • To use /search, <YOUR_API_KEY> should be on the second line.
python telegram_youtube_downloader -f <FILE_PATH_FOR_KEYS>
  1. Directly
python telegram_youtube_downloader -k <YOUR_BOT_KEY>
python telegram_youtube_downloader -k <YOUR_BOT_KEY>,<YOUR_API_KEY>

Configurations

Configuration file telegram_youtube_downloader\configs\config.yaml.

logger_options:
  log_path: logs                                  # Can be abs path
  log_level: 20                                   # info

youtube_downloader_options:
  preferred_video_format: mp4
  preferred_audio_codec: mp3
  default_video_quality: 720p
  max_video_duration_seconds: 1200                # 20 min
  max_audio_duration_seconds: 7200                # 2 hours
  max_file_size: 45M                              # Telegram bots can send up to 50M
  ffmpeg_location: null                           # null will try to get from env as ffmpeg

telegram_bot_options:
  text_timeout_seconds: 30
  video_timeout_seconds: 300                      # 5 min  
  audio_timeout_seconds: 300                      # 5 min

youtube_search_options:
  max_results: 5                                  # Limit search results with 5

About

Easy to run multithreaded Telegram bot that downloads YouTube videos.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.0%
  • Dockerfile 1.0%