Skip to content

A Telegram Bot designed to download and stream audio from YouTube

Notifications You must be signed in to change notification settings

SidSun-Experiments/rainbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rainbot

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.

Features

  • 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-dlp updated to the latest version.
  • Systemd Integration: Comes with a systemd service file for running as a background daemon.

Prerequisites

  • Python 3.8+
  • mpv installed on the host machine.
  • yt-dlp installed or placed in the expected directory.
  • curl (for updating yt-dlp).

Installation

  1. Clone the repository or copy the project files: Ensure all files (rainbot.py, start.sh, requirements.txt, etc.) are in your project directory.

  2. Create a virtual environment and install dependencies:

    python -m venv pyenv
    source pyenv/bin/activate
    pip install -r requirements.txt
  3. 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
  4. Adjust paths (if necessary): The project assumes certain paths like /home/sids/stacks/rainbot/. Make sure to update the paths in rainbot.py, start.sh, and rainbot.service according to your actual setup.

Usage

Running manually

You can start the bot by running the start.sh script:

./start.sh

Bluetooth Audio Streaming

I 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.

Running as a Systemd Service

To ensure Rainbot runs in the background and starts on boot:

  1. Update paths in rainbot.service.
  2. Copy the service file to systemd's user directory:
    cp rainbot.service ~/.config/systemd/user/
  3. Enable and start the service:
    systemctl --user daemon-reload
    systemctl --user enable rainbot.service
    systemctl --user start rainbot.service

Bot Commands

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 - Update yt-dlp to the latest release seamlessly.
  • /help - Show the help message.

About

A Telegram Bot designed to download and stream audio from YouTube

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published