Table of Contents
In my last post, I explained how I’m using IceCast and Python to create my own LAN radio station. I’ve been using it for the last week, listening on via VLC on my homemade speaker, and it’s been really fun to just have some noise going on in the background throughout the day.
But I’ve also dabbled a little more with LiquidSoap (LS) to try some other things. LS may not be able to filter properly on filenames within a script (or at least I don’t know how to do that yet), but you can still setup some easy LS scripts and harness its power pretty easily.
PlaylistLink to heading
If you want to search for keywords in filenames to play via LS, you will need to create a playlist file; I’ll use a M3U file for this example.
find /music -type f \( -iname "*halloween*" -o -iname "*spooky*" \) | shuf > /tmp/halloween_playlist.m3u
In this command, I’m searching for keywords “halloween” and “spooky” in the /music directory, using “shuf” to shuffle the results, then outputting them to /tmp/halloween_playlist.m3u. Once you have your playlist file, you can create a LS script to “transmit” them to IceCast:
touch ~/radio.liqchmod +x ~/radio.liq # Make executable for direct calls
Open the LIQ file with your favorite text editor and drop this in:
#!/usr/bin/liquidsoapsource = mksafe(playlist("/tmp/halloween_playlist.m3u", mode="randomize"))
output.icecast( %mp3(bitrate=320, stereo=true), mount="stream", host="localhost", port=8000, password="hackme", description="Halloween LiquidSoap Stream", source)
In this script, we create a “source”, pointing to the M3U playlist file we created and setting the mode of playback to “randomize”. Then, we define the output as IceCast, 320 bitrate in stereo, some other important properties, and we’re done. Finally, run the script directly and check IceCast to see that it’s an active mountpoint.
./radio.liq
On your client of choice, you can open the network stream “http://<SERVER_IP>:8000 /stream” and listen to your tunes!
FolderLink to heading
What if you want to just point LS at your music folder and listen to everything? You can swap out the playlist filepath for a directory and LS will look in that directory recursively.
#!/usr/bin/liquidsoapsource = mksafe(playlist("/music", mode="randomize"))
output.icecast( %mp3(bitrate=320, stereo=true), mount="stream", host="localhost", port=8000, password="hackme", description="All Music LiquidSoap Stream", source)
Side NotesLink to heading
One thing to note is that by default, LS will add an automatic crossfade and play all available items indefinitely.
Even though I don’t have one of these LS scripts in a SystemD service yet, I’ve enjoyed running them manually and just listening to my collection of music during my work day. I hope to create a few services based on different scripts that I write, and then I can just use my client to select which stream I want to listen to.
LS is a pretty powerful tool if you care to do more than just play random music. For example, you can create a schedule to where LS will play specific playlists between certain times, or even throw in some jingles here and there using weights. Heck, you can even setup and stream video, not just audio, due to the combination of LS and FFMPEG! I haven’t tried this yet, but it’s on my list of things to test.