You will likely want to customize the metadata of your stream to change in various ways, be it
the currently playing DJ or song or something else.
Files/Playlists
For files in backup playlists, the metadata is read directly from the files. The best thing to do is to have your files tagged properly. If you want to change the metadata in some other way it is possible.
Annotate protocol in playlist file
If you are using a playlist file, a simple way to change the metadata of the files is to add some annotations to the playlist file using the annotate protocol.
This will replace the title metadata with the artist metadata.
There is also an if statement operator, in case the metadata you want to rewrite is blank, the function won’t be called.
pattern='$(if $(title)), "$(title)", "$(title) - my radio station"'source=rewrite_metadata(["title",pattern],source)
Map metadata
Honestly I think map_metadata is a lot easier to use, and if you have simple needs it may be better for you.
defappend_title(m)=# Grab the current titletitle=m["title"]# Return a new title metadata[("title","#{title} - www.station.com")]end# Apply map_metadata to s using append_titles=map_metadata(append_title,s)
Using this syntax you can replace any element of the metadata, title, artist, etc.
Live streams
To rewrite the metadata in my live stream, I keep track of a ref called title_prefix that I set when my dj authenticates to the stream.
#auth functiondefdj_auth(user,password)=u=get_user(user,password)p=get_password(user,password)#get the output of the php scriptret=get_process_lines("bundle exec ./dj_auth.rb #{u}#{p}")#ret has now the value of the live client (dj1,dj2, or djx), or "ERROR"/"unknown"ret=list.hd(ret)#return true to let the client transmit data, or false to tell harbor to declineifret=="true"thentitle_prefix:="LIVE NOW ♫✩ -- #{u} ✩♪"current_dj:="#{u}"trueelsefalseendend
Then I set the metadata with this ref, using map_metadata:
I will discuss dj authentication more in the next chapter.
Strip metadata from Traktor
If your DJs stream with Traktor, you may notice that Traktor automatically inserts the track’s metadata into the stream. If you wish to remove this, its possible. By default, map_metadata updates the metadata with the value returns, and keeps the other metadata you did not specify to update. If you wish to remove the other metadata you did not explicitly specify, just pass the update=false option to map_metadata:
If you are embedding an HTML5 or flash player on your site, you may find it difficult to get the metadata displaying in the player properly. Most HTML5 players don’t seem to read the metadata directly from the stream very well. Icecast provides a JSON endpoint with current metadata and statistics.
http://myserver.com:8000/status-json.xsl
Don’t ask why the extension is .xsl when its actually json data, I have no clue. The json support was introduced only recently, and before only XML format was available.
You can use this file to set your player’s metadata if you know a little bit of Javascript. This example inserts the title into a div with a class named jp-title, using jQuery to fetch the JSON from the icecast server and parse it.
Now just call this function periodically, say every 10 seconds, with setInterval.
setInterval(radioTitle,10000);
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.