Control your speakers with Telegram and play music from YouTube Music
If you've ever used Discord, you've probably heard of music bots that play music for you. All you had to do was just type "-p <track_name>" to listen to your favorite song. I also liked it, so I made the real one!
This script works as a service and allows you to play music on speakers from YouTube Music and control playback using Telegram. It uses an awesome MPV media player as a backend.
To be clear, this is not a regular music bot. It plays music directly on the connected speakers, not in voice chat or audio messages.
List of available commands:
- /s - Skip the currently playing song
- /stop - Stop playback and clear the queue
- /q - Show current queue
- /p - Pause playback
- /v - Show current volume
- /v +10 - Change current volume
- /v 50 - Set volume
- /r - Search for radio
- /l - Search for lyrics
Make sure you have Python 3.7+ installed
$ sudo apt install mpv
$ pip3 install https://github.com/raitonoberu/realmusicbot/archive/master.zip
pip install https://github.com/raitonoberu/realmusicbot/archive/master.zip
Before running, you must configure your bot by editing the file ~/.config/realmusicbot.ini:
$ nano ~/.config/realmusicbot.ini
notepad %USERPROFILE%\.config\realmusicbot.ini
TOKEN=yourtoken
# Whether to process messages simultaneously
THREADED=true
# Select YouTube ITAG code
# - 251 is the highest quality
# - More here: https://gist.github.com/sidneys/7095afe4da4ae58694d128b1034e01e2
ITAG=251
# Bot privatization (HIGHLY RECOMMENDED)
# - Get your User ID using tg @userinfobot and add it to the list
# - https://t.me/userinfobot
# - If you leave it empty, everyone can use the bot
# - example: 123456789,987641234
ALLOWED_IDS=
There are two ways to run Real Music Bot. It's recommended to run it in a terminal first to make sure that it works.
$ realmusicbot
Press Ctrl+C to close.
$ systemctl --user start realmusicbot
$ systemctl --user enable realmusicbot
Check logs:
$ journalctl | grep realmusicbot
$ systemctl --user stop realmusicbot
$ systemctl --user disable realmusicbot
$ sudo rm ~/.config/systemd/user/realmusicbot.service
$ sudo rm -r ~/.config/realmusicbot.ini
$ pip3 uninstall realmusicbot
where realmusicbot | python -c "import os;os.remove(os.path.dirname(input())+r'\mpv-2.dll')"
del /f "%USERPROFILE%\.config\realmusicbot.ini"
pip uninstall realmusicbot
GPLv3, see LICENSE for additional info.
- Localization
- Passing params to MPV