How to Host Your Own Internet Radio Station
As a modern day collector of CDs, I still like to have easy access of all of my music. Obviously, carrying around over 200 CDs is not a realistic option. Also, sometimes I would to travel light and not bring my media player and headphones with me. How did I fill the gap?
I created a playlist of my music and host it online. This is great not only within my personal network, but while travelling away from home. I set mine up as a internet radio station playing my directory of music in a random order. In the past, I have even set up multiple stations for different genres of music.
Disclaimer
Please take the appropriate actions to ensure you do not get in trouble for the media you are using and sharing. There is regional legislation for media reproduction and broadcasting. Please do your homework before broadcasting online or monetizing your project. This project was made using backups of my physical media for personal use.
Install the Required Software
The below command will install all the prerequisites required to build a internet stream. You will have to install all the dependencies.
sudo apt-get install icecast2 ices2
Once you run this command, the icecasts2 configuration will come up. Select Yes.
This is where you can configure all your passwords for the services provided by icecast2. It will also include the password for the admin web GUI.
At this point, you should be able to access the web interface at the IP address using port 8000.
Note: If you do not have supported media formats for icecast2 and ices, you will need to convert your media
Optional: Convert Your Music
There are a few reasons why I convert my music before creating a radio station. The first is processing power. I will not be doing transcoding on the fly. I will be playing the files in the format they are. The second is bandwith. If we compare the Blink-182 California album's size in FLAC versus OGG, there is about a 90% space savings. If we base the broadcast statistics on raw size, that is an easy decision to make.
Firstly, install the FFMPEG packages in order to convert your media from your current format to your desired format.
sudo apt-get install ffmpeg
In this case, I will be converting my archives from FLAC to OGG.
I have created a repository for all the scripts used in this project. The most up to date version of the below script can be found in the hosting-own-radio repository.
In summary, the above script takes the flac files from a "FLAC" directory, then creates a replicated version of the files in an "OGG" directory using the OGG format. This is a very primitive script with very little options, however, it can be tweaked to do things like change the audio quality, change the format, change the directories or even be given more functionality.
Again, right now, it will take FLAC files from the "FLAC" folder and make OGG files in the "OGG" folder.
Build the Playlist
The make-playlist.sh script in the hosting-own-radio repository is listed below and used to generate the playlist for the radio.
directory=/home/seanland/Desktop/test-music/OGG
playlist=/home/seanland/Desktop/test-music/OGG/playlist.txt
find $directory -type f -name "*.ogg" > $playlist
The directory variable is root location where the music files are listed. The playlist variable is where the output will be created.
Make the Icecast2 Configuration Changes
Let will start by making some changes to the icecast2 config file.
# icecast2 configuration file
sudo vi /etc/icecast2/icecast.xml
You can change the hostname, usable port and limits; just to name a few.
<icecast>
<!-- location and admin are two arbitrary strings that are e.g. visible
on the server info page of the icecast web interface
(server_version.xsl). -->
<location>Canada</location>
<admin>me@seanland.ca</admin>
...
...
This is an example of the location and admin being changed. There are a number of options that maybe beneficial for specific use cases.
Restart the service to update the above configuration changes
sudo /etc/init.d/icecast2 restart
Configure the Ices2 Process
Copy the default playlist to the desired directory (I am configuring it from my home folder) for modification.
sudo cp /usr/share/doc/ices2/examples/ices-playlist.xml ~
Rename the file to the desired playlist title.
sudo mv ices-playlist.xml ices-seanland.xml
Open the file and make the following changes:
- Change the background tag to 1. This will allow the process to run in the background.
- Change the metadata information.
- Change the playlist file name if required and set the random parameter to 1.
- Change the password and mount point as required.
These are just samples of the sections, if you cut and copy the entire thing it will not work.
You can run ices2 referencing your playlist xml file and start the broadcast.
sudo ices2 ices-seanland.xml
If you go back to your icecast2 page you should see a music stream available.
Now, If you enter the \<IP Address>:\<Port>/\<Mount Point> you will have a stream!
Configure Ices2 to Run On Startup
As all the other files are maintain in the home directory, we will do the same with the start up script.
vi ~/ice2-startup.sh
I added the one line into the bash script.
/usr/bin/ices2 /home/ubuntu/ices-seanland.xml
I set it up this way in the event I want to run multiple stations. In order to set up a second station you would just have to configure a second xml file and run a second command directing to set file.
After that, we create the "ices2" service. This is a service that is triggered on boot.
sudo vi /usr/lib/systemd/system/ices2.service
[Unit]
Description=Ices Startup Script
[Install]
WantedBy=multi-user.target
[Service]
ExecStartPre=/bin/sleep 30
ExecStart=/bin/bash /home/ubuntu/ices2-startup.sh
Type=simple
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu
Restart=on-failure
The above configuration file, waits 30 seconds, then calls of the ices2 startup script we created earlier.
We then enable the service so it runs on start up.
sudo systemctl enable ices2
Listen to Your Music!
You now have an operating music stream. If you did your conversion correct, you will also have metadata!
I prefer to do this through VLC or Clementine. In VLC, you can add the URL listed earlier in the File > Open Network Stream option; enter the URL and hit play!
Depending on the application, metadata will be passed and the song name will be visible.
How I Set it Up
As my Icecast2 and Ices2 server is a Raspberry Pi, I have tried to limit the resources required to operate the stream. This is why, the music is converted to a different format and even stored on a different machine.
I also put it behind a proxy to centralize the setup for easy of use.
Throw it Online
I am not adding these steps, but you can do numerous ways to access these online safely. The two most popular routes would probably be through a VPN or a proxy; alright, a third option would be both.
You can then share (legally of course) your favourite music with your friends and family. You could create playlists based on the people you would like to share it with. You could also build stations on genres.
It really makes picking a radio station a lot easier.