Recording Icecast livestreams, a foolproof method.
If you want just the how-to guide skip to the end of this post. I’m including the backstory because I think it’s mildly interesting.
There are several podcast live streams I enjoy listening to at certain times of the week. However, due to the fact that I can’t always be around at the right time to listen to them live, I sometimes miss out.
A fair question would be, why not just listen to the published show? Well, I have a few reasons.
- I like to have the show as soon as possible.
- I actually enjoy unedited podcasts more than edited ones. There are often stories or jokes that don’t make it to the final show, and are only a part of the live stream.
- I enjoy hearing the hosts talk to each other about some of the behind the scenes aspects of creating the show.
- It’s interesting to hear if and when the hosts mess up, and how they will potentially fix or work around that in editing.
- Even though the audio quality is worse, I find it easy enough to listen to. The above points more than make up for the lack of high audio fidelity. I will admit, part of the fun is collecting these files that very few people have.
These live streams in question run on the on Icecast platform. This is fairly old technology, so there’s not much documentation on how to record or work with these streams. So I got to work on finding a solution. I needed 3 things:
- A way to save the output of the live stream to a file on disk.
- A method to try to constantly connect to the stream. That way it would connect right when the stream started and it would be able to pick back up in case of a disconnection. (I also needed to make sure that the first file was not overwritten if the stream reconnected, I found that out the hard way.)
- And finally, I needed a way to trigger this at certain times of the day.
I considered trying to use the command tool Streamripper. However, as far as I can tell, it hasn’t updated since 2008. That normally wouldn’t matter, but it hasn’t been updated to support recording secure HTTPS streams. That made it useless for my purposes since every stream I was interested in was HTTPS.
#The Solution
Finally, I discovered a way to do this on the command line. Thankfully, the way to record is a one-liner. You’ll just need the direct url to the stream. Let’s use a local station, WFIU as an example:
while true; do curl -o - http://hannibal.ucs.indiana.edu:8000/wfiu_hi output.mp3 ; done >$(date +"%FT%H%M%S").mp3
If my 7 year old self would have had this technology, he would have loved it. There were certain songs on the radio he would always try to record with Voice Memos, before the days that Spotify and YouTube made music more readily available.
If I knew how to write MacOS apps I would create a GUI app for this exact purpose. None exist, sadly.