[Linux-Ubuntu] Setting up a radio stream

Xmair

  • Wiki Contributor
  • Posts: 951
[Linux-Ubuntu] Setting up a radio stream
« on June 27th, 2019, 09:17 AM »
I was asked by someone on how to set up a radio stream and instead of telling them, I figured I should make a guide so everyone can know how to do so. Please note that this guide is for Linux so please do not ask basic Linux questions here. This guide was tested on Ubuntu 18.10 (GNU/Linux 4.18.0-24-generic x86_64) (Ubuntu 18.10 x64) and works perfectly.

We will be needing 2 packages, icecast2 and ezstream.
So firstly start off by installing icecast2:
Code: [Select]
sudo apt-get install icecast2
Note: sudo isn't needed if you're on root.
You'll be prompted for configuring icecast2, choose yes and choose passwords which suit you well and write them down somewhere to remember them as they'll be used later.
After installing the icecast server, it should start itself (which it did for me). However if it does not, use the following command:
Code: [Select]
sudo /etc/init.d/icecast2 start
Note: sudo isn't needed if you're on root.
You should now be able to access the icecast2 server's administration page by opening your browser and visiting your domain with 8000 port, or your IP with the 8000 port. The 8000 port is currently the default one and it can be changed by opening and editing the config. [1]
Now to install ezstream:


Code: [Select]
sudo apt-get update
sudo apt-get install ezstream
Note: sudo isn't needed if you're on root.


Now I would suggest creating a different user for this, so:


Code: [Select]
sudo adduser radiostream
Note: sudo isn't needed if you're on root.


Now log into your newly created user either in a new session or by using the su command.
Make a directory named music, in this directory you'll be adding all your music files.
Make another directory named .ezstream, this is where we will keep the ezstream's configuration file(s). [2]


Code: [Select]
mkdir music
mkdir .ezstream


Now copy a template of ezstream's configuration file.


Code: [Select]
cp /usr/share/doc/ezstream/examples/ezstream_mp3.xml .ezstream
Note: You can take a look at /usr/share/doc/ezstream/examples/ for more of the examples.


This step is not mandatory, but this is for our own ease and should be done if you're going to host multiple streams.
In this step we change the name of the copied file:


Code: [Select]
cd .ezstream
mv ezstream_mp3.xml hollywood.xml
Note: This guide now assumes that you've changed the name to hollywood.xml and all the steps will now treat the file name as such.


Now edit the configuration file:


Code: [Select]
nano hollywood.xml


Change the <sourcepassword></sourcepassword> from hackme to whatever password you set before and the <filename></filename> to hollywood.txt. You can change other configurations as per required such as the <url></url> if you're going to host multiple streams. If you want your radio stream to be looped forever and not end once it has played all the songs in the playlist, set <stream_once></stream_once> to 0.
Press CTRL+X, press y and then press enter/return to save the file.

Now come back to the user directory:


Code: [Select]
cd -


We're now going to make a file that automatically puts all the mp3 files present in the music directory into the hollywood.txt file. [3]


Code: [Select]
nano hollywood.sh


Copy paste this into hollywood.sh:


Code: [Select]
#!/bin/bash
find music -name *mp3 -type f > .hollywood.txt
echo "Created the hollywood.txt playlist. Now starting the stream."
ezstream -c .ezstream/hollywood.xml


Press CTRL+X, press y and then press enter/return to save the file.
Now make the file executable:


Code: [Select]
chmod +0700 hollywood.sh


This is where you upload your music to the music folder. Please note that the format should be MP3.
After you're done uploading, create either a tmux session or use the screen command and execute the hollywood.sh file. However, tmux is recommended.


Code: [Select]
tmux
./hollywood.sh


OR


Code: [Select]
screen ./hollywood.sh


You're now basically done. Now head over to your icecast2 server's administration page. It should be yourdomain.com:8000 or yo.ur.i.p:8000 or localhost:8000 if you're browsing from the OS itself. Go to Administration > Mountpoint List and copy the link address of the M3U your stream. It should be something like ip:8000/stream.m3u or domain:8000/stream.m3u.





Now finally you can head over to your script and add this line:


Code: [Select]
CreateRadioStream( "Hollywood Songs Stream", "[paste copied url here]", true );


Adios y buena suerte!
 1. You can access the config file at /etc/icecast2/icecast.xml, in here you can change your passwords or the port and other configs.
 2. You can add more radio streams by repeating the same method.
 3. Source: https://www.maketecheasier.com/run-a-diy-internet-radio-station-with-icecast-linux/

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD