liquidsoap dynamic playlist

big balls of mud killer
, in 16 October 2014

In my liquidsoap getting started guide I show you how to use a simple text based playlist. In this guide I wanted show you how to use request.dynamic to build a playlist that is based on any function at all, not just reading a simple text file. You could determine the next song by user votes, hitting some arbitrary HTTP api, randomly, the results are limitless.

On datafruits I mostly use this to add the most recent podcasts to the playlist, as well as mix in jingles every couple of tracks. Its actually a function that calls a ruby script that connects to redis to determing the next track to play.

def my_request_function () =
  result = get_process_lines("bundle exec ./next_song.rb")
  log("next song: #{result}")

The script can really do anything, as long as it prints out the path to the next song. Here is what my script looks like.

#!/usr/bin/env ruby

R =

next_song = R.lpop ""
puts next_song

When I run the script:

$ bundle exec ruby ./next_song.rb

I have to mark this source as fallible, since its calling an external script.

backup_playlist = request.dynamic(my_request_function)

Then I hook this up to my normal fallback mechanism.

source = fallback(track_sensitive=false,

You can pass any function to request.dynamic. You typically enqueue a new song with request.create.

You’ll see something like this in the logs.

2014/09/30 14:58:32 [request.dynamic_5130:3] Prepared "/tmp/playlist/Mondaystudio_Nov23_2013.mp3" (RID 3).

Then this when the track finishes.

2014/09/30 15:20:09 [request.dynamic_5130:3] Finished with "/tmp/playlist/Mondaystudio_Nov23_2013.mp3".

Since the script for enqueuing the next request can be any program, the possibilities are really limitless here. The next track could be the result of a tweet, a user request on a webpage, a telnet command, or anything else you can think of. I will go into more possibilities in an upcoming post.

Here is the documentation on request sources from savonet’s site.

Modern Online Radio with Liquidsoap Book - Free Sample

Need more help with liquidsoap? Can’t get your script to work?

I wrote a book to help you learn Liquidsoap. The book covers all aspects of liquidsoap, from getting started, to making dynamic streams, audio processing, video, customizing metadata, authentication, and more. The book is available for purchase now here!

You can get a free sample chapter of my book! Just enter your email address to subscribe to my mailing list and I'll send you a free PDF sample of the book in return.