Rainbot is a personalized Telegram Bot designed to download and stream audio from YouTube directly to a host machine. It utilizes yt-dlp for downloading and mpv for media playback, providing a seamless way to play music or podcasts from YouTube links via Telegram commands.
- Direct YouTube Downloads: Send a YouTube link to the bot, and it will automatically download the audio and start playing it.
- Media Controls: Play, pause, and adjust the volume of the audio directly from Telegram.
- Library Management: List your recently downloaded files and play them directly by clicking inline buttons.
- Access Control: Restrict bot usage to specific Telegram user IDs to keep it private.
- Auto-Update: Built-in command to keep
yt-dlpupdated to the latest version. - Systemd Integration: Comes with a systemd service file for running as a background daemon.
- Python 3.8+
mpvinstalled on the host machine.yt-dlpinstalled or placed in the expected directory.curl(for updating yt-dlp).
-
Clone the repository or copy the project files: Ensure all files (
rainbot.py,start.sh,requirements.txt, etc.) are in your project directory. -
Create a virtual environment and install dependencies:
python -m venv pyenv source pyenv/bin/activate pip install -r requirements.txt -
Configure the environment: Copy the example environment file and edit it to include your Telegram bot token and your Telegram User ID(s).
cp .env.example .env nano .env
-
Adjust paths (if necessary): The project assumes certain paths like
/home/sids/stacks/rainbot/. Make sure to update the paths inrainbot.py,start.sh, andrainbot.serviceaccording to your actual setup.
You can start the bot by running the start.sh script:
./start.shI use the bot to stream audio over bluetooth and since the BT connection in Linux is set up at user level, once there are no user sessions remaining, the BT connection is lost and/or pipewire audio server is terminated. To workaround this, I have a SSH session from root to my user running all the time in a tmux session.
To ensure Rainbot runs in the background and starts on boot:
- Update paths in
rainbot.service. - Copy the service file to systemd's user directory:
cp rainbot.service ~/.config/systemd/user/ - Enable and start the service:
systemctl --user daemon-reload systemctl --user enable rainbot.service systemctl --user start rainbot.service
Once the bot is running, interact with it on Telegram using the following commands:
- Send a YouTube URL: The bot will download the audio and play it automatically.
/play- Resume playback/pause- Pause playback/volup [amount]- Increase volume (default: 10)/voldown [amount]- Decrease volume (default: 10)/list- List up to 20 recently downloaded files with inline buttons to play them./update- Updateyt-dlpto the latest release seamlessly./help- Show the help message.