My "AutoDJ" liquidsoap code. What is yours?

Basically, AutoDJ is a feature that plays random songs (with jingles every 4 tracks) if no show is scheduled in Libretime. I’m curious to know your AutoDj solution !

My AutoDJ solution works this way :

1- You have to comment (disable) those line in ls_script.liq :

#default = amplify(id="silence_src", 0.00001, noise())

and

#if !off_air_meta == "" then
#    off_air_meta := "LibreTime - offline"
#end
#def map_off_air_meta(m) =
#  [("title", !off_air_meta)]
#end
#default = map_metadata(map_off_air_meta, default)

2- Then copy your AutoDJ code just after the amplify function you just disabled

Here is my AutoDJ code :

# Your jingles
jingles = playlist("/home/myradio/jingle")

# Your backup playlist
musics = playlist(mode="randomize",reload=1,reload_mode="rounds","/home/myradio/music")

# Your hours time signals 
clock = single(id="clock","/home/myradio/clock/clock.mp3")

# Your security jingle if the AutoDJ drop
security = single("/home/myradio/offair/offair.mp3")

# 1 jingle every 4 songs
streamradio = rotate(weights=[1,4], [jingles, musics])

# Setting up the crossfade
def crossfade (~start_next=5.,~fade_in=3.,
               ~fade_out=3., ~width=2.,
               ~conservative=false,s)
  high   = -20.
  medium = -32.
  margin = 4.
  fade.out = fade.out(type="sin",duration=fade_out)
  fade.in  = fade.in(type="sin",duration=fade_in)
  add = fun (a,b) -> add(normalize=false,[b,a])
  log = log(label="crossfade")

  def transition(a,b,ma,mb,sa,sb)

    list.iter(fun(x)->
       log(level=4,"Before: #{x}"),ma)
    list.iter(fun(x)->
       log(level=4,"After : #{x}"),mb)

    if
      # If A and B and not too loud and close,
      # fully cross-fade them.
      a <= medium and
      b <= medium and
      abs(a - b) <= margin
    then
      log("Transition: crossed, fade-in, fade-out.")
      add(fade.out(sa),fade.in(sb))

    elsif
      # If B is significantly louder than A,
      # only fade-out A.
      # We don't want to fade almost silent things,
      # ask for >medium.
      b >= a + margin and a >= medium and b <= high
    then
      log("Transition: crossed, fade-out.")
      add(fade.out(sa),sb)

    elsif
      # Do not fade if it's already very low.
      b >= a + margin and a <= medium and b <= high
    then
      log("Transition: crossed, no fade-out.")
      add(sa,sb)

    elsif
      # Opposite as the previous one.
      a >= b + margin and b >= medium and a <= high
    then
      log("Transition: crossed, fade-in.")
      add(sa,fade.in(sb))

    # What to do with a loud end and
    # a quiet beginning ?
    # A good idea is to use a jingle to separate
    # the two tracks, but that's another story.

    else
      # Otherwise, A and B are just too loud
      # to overlap nicely, or the difference
      # between them is too large and
      # overlapping would completely mask one
      # of them.
      log("No transition: just sequencing.")
      sequence([sa, sb])
    end
  end

  cross(width=width, duration=start_next,
        conservative=conservative,
        transition,s)
end

# Enable crossfade between Tracks and Jingles
streamradio = crossfade(start_next=5.,fade_out=3.,fade_in=3.,streamradio)


# Enable every hours time signals 
streamradio = add([streamradio, switch([
                        ({0m0s},clock),
                        ])
])

# Metadata updater
def update_metadata(m) =
  title = m["title"]
  ignore(title)
  artist = m["artist"]
  ignore(artist)

  [("artist","#{artist}"),("title","#{title}")]
end

# Enable AutoDJ with metadata
default = fallback(track_sensitive = false,[streamradio,security])
default = map_metadata(update_metadata, default)

Hi, any hints as to where I need to place the ls_script.liq file on my server?
Thanks

Hello. I don’t really understand your question as ls_script.liq is a file already on your system…
You can use the Locate command to find ls_script.liq on your server.

It depends of your libretime version but in my case here is the location of ls_script.liq :
/opt/libretime/lib/python3.8/site-packages/libretime_playout/liquidsoap/1.4/ls_script.liq