[Linux-Ubuntu] Setting up a radio stream

Started by Xmair, Jun 27, 2019, 08:17 AM

Previous topic - Next topic


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:
sudo apt-get install icecast2Note: 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:
sudo /etc/init.d/icecast2 startNote: 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. [nb]You can access the config file at /etc/icecast2/icecast.xml, in here you can change your passwords or the port and other configs.[/nb]
Now to install ezstream:

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:

sudo adduser radiostreamNote: 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). [nb]You can add more radio streams by repeating the same method.[/nb]

mkdir music
mkdir .ezstream

Now copy a template of ezstream's configuration file.

cp /usr/share/doc/ezstream/examples/ezstream_mp3.xml .ezstreamNote: 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:

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:

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:

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. [nb]Source: https://www.maketecheasier.com/run-a-diy-internet-radio-station-with-icecast-linux/[/nb]

nano hollywood.sh

Copy paste this into hollywood.sh:

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:

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.



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:

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

Adios y buena suerte!

Credits to Boystang!

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