Using youtube-dl/yt-dlp and MPV, host your own free audio streaming service locally on the Raspberry Pi (or Unix system).
If you want a free, easy to use audio streaming service (and without ads!), seeking an alternative to expensive surround sound systems being tethered to restrictive apps. Or just want a free alternative to audio services like Spotify. Sounds too good to be true? Then this project might be for you!
- Doesn't require Bluetooth
- Doesn't require HDMI
- Doesn't require an app
- Doesn't require linking separate services
- Doesn't require any accounts (or paid accounts)
A good DIY project to tinker with, and even better, you can host this alongside all the different things you otherwise use the Pi for, e.g. retropie, without needing to mess with configs or flashing.
🎉 Song queue
🎉 Playback controls
🎉 History
🎉 Realtime playback information across all connected devices
🎉 Optionally get search results via API
🎉 Settings menu
🪄 Sleek AI generated visuals
sudo apt install mpv python3-pip nodejs socat
sudo pip3 install yt-dlp
sudo pip3 install youtube-dl
sudo cp /usr/local/bin/yt-dlp /usr/local/bin/youtube-dl
mkdir ELPi; cd ELPi
wget https://github.com/DefaultV/ELPi/releases/download/v1.13/elpi_1.13.zip
unzip elpi_1.13.zip; rm elpi_1.13.zip
sudo node dist/server.min.js
yt-dlp
as an alternative.
-
If you're building MPV from source, look into the alternative downloader path configuration.
-
If you don't want to do this, you might run into upload id extraction issues. Using the
Experimental faster searching & streaming
setting will allow you to stream without changing binaries, but with it's own cons.
Optionally (For API query results)
cd dist; ./settoken.sh
Enter your API token
TL;DR
echo '#!/bin/bash\ncd /home/pi/ELPi/; sudo node dist/server.min.js' > /home/pi/ELPi/elpi.sh
echo '[Service]\nType=simple\nRemainAfterExit=yes\nExecStart=/home/pi/ELPi/elpi.sh\nTimeoutStartSec=0\n\n[Install]\nWantedBy=default.target' > /home/pi/ELPi/elpi.service
sudo chmod +x /home/pi/ELPi/elpi.sh
sudo mv /home/pi/ELPi/elpi.service /etc/systemd/system/elpi.service
systemctl enable elpi && systemctl start elpi
OR
Read the Startup section for running on boot.
At the current state, this project:
- Either take the first result of a given youtube search string or directly play a "video", given a URL (You can however pass a token and get the first 10 results to choose from)
- Requires manually updating yt-dlp from pip3 rarely
Some values or arguments might differ from Pi to Pi, like the jack audio card in the MPV command arguments. Find out what your audio jack is through alsa aplay -L
and replace the argument --audio-device=alsa/plughw:CARD=Headphones,DEV=0
. This project has only been tested on a Raspberry Pi A+
Please post features in the Issues tab, prefix issue with Feature Suggestion:
and label it feature
Your raspberry will be the sole agent in this, any other device will merely be a client. Meaning, the audio will not be streamed from external devices to the pi, the pi itself will be the one playing the audio, all by itself. External devices will only be used to tell the pi what to "search" for, or "play" directly from youtube (Assuming the device has a web-browser)
As simple as 1, 2!
The following packages are required for the system to work
node
mpv
socat
python3-pip
yt-dlp (Through pip3, apt is outdated)
youtube-dl (Through pip3, apt is outdated)
This can be done with:
sudo apt install mpv python3-pip nodejs socat
Then, using pip:
sudo pip3 install yt-dlp
sudo pip3 install youtube-dl
For better performance, make sure nodejs
is somewhat the latest version, the apt version is 10.x
Clone the repo and run tsc
(having typescript installed), then after compilation you can run the command
sudo node dist/server.js
That's it! Everything should work now and you should see a webpage when accessing the ip of your Pi on your network.
If you want, you can run the application on startup. If you are using systemd (by default on raspberry pi's) you can achieve this the following way:
/home/pi/ELPi/elpi.sh
#!/bin/bash
cd /home/pi/ELPi/; sudo node dist/server.min.js
/etc/systemd/system/elpi.service
[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/home/pi/ELPi/elpi.sh
TimeoutStartSec=0
[Install]
WantedBy=default.target
Then to enable on boot
systemctl enable elpi && systemctl start elpi
If everything works as it should, then navigating to the local website and upon searching for a song or inputting a youtube url directly into the search field.
Do not host this publicly to the rest of the internet, the system is vulnerable to format string attacks and exposes both the terminal and multiple commands which should only be used by admins of the system. ONLY USE ON YOUR LOCAL NETWORK