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.

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:

  1. A way to save the output of the live stream to a file on disk.
  2. 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.)
  3. 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 - 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.