A Haskell-based Telegram bot for converting YouTube videos to audio tracks.
- 🎧 Download audio from YouTube with best quality
- 🔄 Automatic conversion to MP3 (320kbps)
- 📤 Send tracks directly to Telegram
- 🖼️ Automatic thumbnail extraction from YouTube
- 📝 Video title as audio metadata
- 🔥 Built with Nix for reproducible builds
- ⚡ Asynchronous request processing
- 🛡️ File size limit (50 MB)
- 🔢 Concurrent download control (max 3)
- 🚀 Faster downloads with concurrent fragments
- Nix with flakes support
- Telegram account
If you don't have Nix installed:
# Install Nix
sh <(curl -L https://nixos.org/nix/install) --daemon
# Enable flakes (add to ~/.config/nix/nix.conf or /etc/nix/nix.conf)
experimental-features = nix-command flakes- Open Telegram and find @BotFather
- Send command
/newbot - Enter bot name (e.g.,
Melodilambda Music Bot) - Enter bot username (must end with
bot, e.g.,melodilambda_bot) - Get your bot token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
Important: Save the token in a secure place!
The easiest way to get a Windows executable is to use the provided GitHub Actions workflow.
- Push your code to GitHub.
- Go to the Actions tab in your repository.
- Click on the latest Windows Build run.
- Download the
melodilambda-windows-bundleartifact. - Extract the archive. It will contain
melodilambda.exe,yt-dlp.exe, andffmpeg.exeready to go.
You can try to cross-compile from Linux using Nix, but this may be unstable due to GHC/MinGW mismatches:
nix build .#windowsNote: For both methods, you will need to download yt-dlp.exe and ffmpeg.exe separately and place them in the same directory as the bot executable.
# Clone the repository
git clone <your-repo-url>
cd Melodiλ
# Create .env file
cp .env.example .envEdit .env and insert your token:
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz./run.shThat's it! The script will:
- ✅ Enter Nix development environment
- ✅ Download all dependencies (yt-dlp, ffmpeg, GHC, etc.)
- ✅ Build the project with Stack
- ✅ Run the bot
On any other machine with Nix: Just repeat steps 3-4. Everything is reproducible!
- Find your bot in Telegram by username
- Press
/start - Send a YouTube video link:
https://youtu.be/nOJSmXSFCWk - Wait for conversion
- Receive the audio file, which you can:
- Listen directly in Telegram
- Download to your device
- Forward to friends
# Enter Nix development shell
nix develop
# Inside the shell, you have access to:
# - stack (build tool)
# - ghc (Haskell compiler)
# - haskell-language-server (LSP)
# - hlint (linter)
# - ormolu (formatter)
# - yt-dlp & ffmpeg (runtime deps)
# Build
stack --nix build
# Run
stack --nix exec melodilambdaMelodiλ/
├── src/
│ └── Main.hs # Main bot code
├── downloads/ # Temporary files (auto-created)
├── flake.nix # Nix flake configuration
├── stack.yaml # Stack configuration
├── package.yaml # Haskell dependencies
├── run.sh # Run script
└── README.md # Documentation
| Variable | Description | Required |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Bot token from @BotFather | ✅ |
- Max file size: 50 MB (Telegram limitation)
- Concurrent downloads: 3 simultaneously
- Audio format: MP3
- Audio quality: 0 (best quality, ~320kbps)
- Metadata: Embedded title and thumbnail
Edit src/Main.hs:
-- Change concurrent download limit (line 73)
if count >= 3 -- Change to desired number
-- Change audio quality (line 147)
"--audio-quality 0" -- 0 = best, 9 = worst
-- Change format (line 146)
"--audio-format mp3" -- Options: mp3, m4a, opus, vorbis, wav
-- Disable thumbnail embedding (line 148)
-- "--embed-thumbnail" -- Comment out this line
-- Disable metadata (line 149)
-- "--add-metadata" -- Comment out this lineAfter changes, rebuild:
./run.sh- Check token in
.env - Verify bot is running (check terminal output)
- Test with a simple YouTube link
The YouTube video is too long. Try:
- A shorter video
- Check that the link is valid
- Video might be unavailable or deleted
- Check your internet connection
- If the error mentions
Failed to resolve/Name or service not known, that's DNS (not yt-dlp): checkcat /etc/resolv.confandgetent hosts www.youtube.comin the same environment where the bot runs - If you see
HTTP Error 403: Forbiddenor SABR-related warnings, updateyt-dlp(it breaks frequently):- Nix: run
nix flake update(or update channels) and rebuild - Or set
MELODILAMBDA_YTDLP=/path/to/yt-dlpto use a newer binary - Optional: set
MELODILAMBDA_YTDLP_ARGS="--extractor-args youtube:player_client=android"to force a more compatible YouTube client
- Nix: run
- Language: Haskell (GHC 9.4)
- Framework: telegram-bot-simple
- Downloader: yt-dlp
- Converter: ffmpeg
- Build System: Nix + Stack
- Package Manager: Nix
MIT License - see LICENSE file for details
- Playlist support
- Support for other platforms (SoundCloud, Spotify)
- Best audio quality
- Thumbnail extraction
- Video title metadata
- Faster downloads
Made with ❤️ and λ