A simple Telegram bot built with aiogram and yt-dlp that listens for YouTube links in chats, asks what to download, and sends back either MP3 audio, 720p video, or 1080p video.
- A Telegram bot token (from @BotFather)
API_IDandAPI_HASH(from https://my.telegram.org)- A valid
cookies.txtfile exported from your browser (optional, but required for some videos)
-
Clone this repo:
git clone https://github.com/timamz/link-to-audio-bot cd link-to-audio-bot
- Open an incognito/private Chrome window.
- Log into YouTube.
- Visit
https://www.youtube.com/robots.txtto isolate the YouTube session. - Export only the
youtube.comcookies (e.g., using the "Get cookies.txt LOCALLY" extension).
Create a .env file in the project root (or set environment variables directly):
API_ID=1234567
API_HASH=your_api_hash
BOT_TOKEN=your_bot_token
COOKIE_FILE=/app/cookies.txt
PORT=8080- API_ID and API_HASH: Obtain from https://my.telegram.org
- BOT_TOKEN: Provided by @BotFather
- COOKIE_FILE: Optional path to a mounted
cookies.txt - PORT: Optional healthcheck port exposed by the container
Build and run in one command with Docker Compose:
docker compose up --build -dStop the bot:
docker compose downIf you do not need YouTube cookies, remove the volumes section from compose.yaml and omit COOKIE_FILE from .env.
Check that the bot is healthy:
docker compose logs
curl http://localhost:8080/healthzOnce running, send a YouTube link into any chat with the bot. It will show buttons for:
- 🎧 Audio MP3
- 🎬 Video 720p
- 🎬 Video 1080p
After you choose an option, it downloads and sends the selected file.