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

If you could help me. When i apply your “autodj” i have nothing connect to icecast2. Cant figure out the problem.

I modified the ls_script from version 1.4.

Jun 10 21:43:21 libretime systemd[1]: Started LibreTime Liquidsoap Service.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: notification: Speex header too small
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: [mp3 @ 0x55ac52fd9300] Estimating duration from bitrate, this may be inaccurate
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: [mp3 @ 0x55ac52fd9300] Estimating duration from bitrate, this may be inaccurate
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 >>> LOG START
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [main:3] Liquidsoap 1.4.3
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [main:3] Using: bytes=[distributed with OCaml 4.02 or above] pcre=[unspecified] sedlex=2.2 menhirLib=20201216 dtools=0.4.2 duppy=0.8.0 cry=0.6.5 mm=0.5.0 xmlplaylist=0.1.5 lastfm=0.3.2 ogg=0.5.2 vorbis=0.7.1 opus=0.1.3 speex=0.2.1 mad=0.4.6 flac=0.1.7 flac.ogg=0.1.7 dynlink=[distributed with Ocaml] lame=0.3.4 shine=0.2.1 gstreamer=0.3.0 frei0r=0.1.1 theora=0.3.1 gavl=0.1.6 ffmpeg=0.4.3 bjack=0.1.5 alsa=0.3.0 ao=0.2.1 samplerate=0.1.4 taglib=0.3.6 ssl=0.5.9 magic=0.7.3 camomile=[unspecified] inotify=2.3 yojson=[unspecified] faad=0.4.0 soundtouch=0.1.8 portaudio=0.2.1 pulseaudio=0.1.3 ladspa=0.1.5 sdl=0.9.1 camlimages=4.2.6 lo=0.1.2 gd=1.0a5
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [gstreamer.loader:3] Loaded GStreamer 1.18.4 0
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [dynamic.loader:3] Could not find dynamic module for fdkaac encoder.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz master.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [frame:3] Targetting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:24 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [decoder.ffmpeg:3] File "/srv/libretime/autodj/hour.ogg" has an incompatible number of channels.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [decoder:3] Unable to decode "/srv/libretime/autodj/hour.ogg" as {audio=2;video=0;midi=0}!
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [decoder:3] Method "FFMPEG" accepted "/srv/libretime/autodj/secure.mp3".
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [lang:3] timeout --signal=KILL 45 libretime-playout-notify started &
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [sandbox:3] Could not find binary bwrap, disabling sandboxing..
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [video.converter:3] Using preferred video converter: gavl.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [audio.converter:3] Using samplerate converter: ffmpeg.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [harbor:3] Adding mountpoint '/dj' on port 8085
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [harbor:3] Adding mountpoint '/main' on port 8090
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [jingles:3] Loading playlist...
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [jingles:3] Playlist is a directory.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [jingles:3] Successfully loaded a playlist of 0 tracks.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [imported:3] Loading playlist...
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [imported:3] Playlist is a directory.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [imported:3] Successfully loaded a playlist of 1584 tracks.
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock:3] "/srv/libretime/autodj/hour.ogg" is static, resolving once for all...
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:2] Error when starting icecast:1: Req_simple.Invalid_URI!
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Raised at Req_simple.unqueued#wake_up in file "sources/req_simple.ml", line 36, characters 56-73
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Switch.switch#wake_up.(fun) in file "operators/switch.ml", line 109, characters 10-46
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Switch.switch#wake_up.(fun) in file "operators/switch.ml", line 109, characters 10-46
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Switch.switch#wake_up.(fun) in file "operators/switch.ml", line 109, characters 10-46
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Switch.switch#wake_up.(fun) in file "operators/switch.ml", line 109, characters 10-46
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Switch.switch#wake_up.(fun) in file "operators/switch.ml", line 109, characters 10-46
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Output.output#wake_up in file "outputs/output.ml", line 134, characters 6-57
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Source.operator#get_ready in file "source.ml", line 413, characters 8-31
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock.wallclock_main:3] Called from Clock.clock#start_outputs.(fun) in file "clock.ml", line 228, characters 16-43
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [icecast:1:1] Got ill-balanced activations (from icecast:1)!
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock:2] Error when leaving output icecast:1: File "source.ml", line 435, characters 12-18: Assertion failed!
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock:3] Raised at Source.operator#leave.remove in file "source.ml", line 435, characters 12-24
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock:3] Called from Source.operator#leave in file "source.ml", line 440, characters 33-61
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [clock:3] Called from Clock.leave in file "clock.ml", line 84, characters 6-27
Jun 10 21:43:25 libretime libretime-liquidsoap[169138]: 2025/06/10 21:43:25 [main:3] Shutdown started!
Jun 10 21:43:25

I was able to kind of put it to work, I leave here the complete script. It fails to play other audio then the auto dj it self. What could be wrong?

boot_timestamp = string_of(gettimeofday())

web_stream_enabled = ref false
web_stream_id = ref '-1'

show_name = interactive.string("show_name", "")

dynamic_metadata_callback = ref fun (~new_track=false, s) -> begin () end

just_switched = ref false

%include "ls_lib.liq"

sources = ref []
source_id = ref 0

def create_source()
    this_source_id = !source_id

    l = request.equeue(id="s#{this_source_id}", length=0.5)

    l = audio_to_stereo(id="queue_src", l)
    l = cue_cut(l)
    l = amplify(1., override="replay_gain", l)

    # Fade the tracks to avoid hard cuts in between two tracks and at the end of the shows.
    # Liquidsoap reads the fade in/out durations from the annotation "liq_fade_in/out" which
    # value can be set via Libretime settings.
    l = fade.in(l)
    l = fade.out(l)

    l = on_metadata(notify_queue, l)

    sources := list.append([l], !sources)
    server.register(namespace="queues",
                "s#{this_source_id}_skip",
                fun (s) -> begin log("queues.s#{this_source_id}_skip")
                    clear_queue(l)
                    "Done"
                end)
    source_id := !source_id + 1
end

create_source()
create_source()
create_source()
create_source()

queue = add(!sources, normalize=false)
pair = insert_metadata(queue)
dynamic_metadata_callback := fst(pair)
queue = snd(pair)

output.dummy(fallible=true, queue)

http = input.http_restart(id="http")
http = cross_http(http_input_id="http",http)
output.dummy(fallible=true, http)
stream_queue = http_fallback(http_input_id="http", http=http, default=queue)
stream_queue = map_metadata(id="map_metadata:schedule", update=false, append_title, stream_queue)

ignore(output.dummy(stream_queue, fallible=true))

def web_stream_set_id(value)
    web_stream_id := value
    string_of(!web_stream_id)
end

def web_stream_get_id()
    string_of(!web_stream_id)
end

server.register(namespace="sources",
                description="Start webstream source",
                "start_web_stream",
                fun (s) -> begin log("sources.start_web_stream")
                    notify([("schedule_table_id", !web_stream_id)])
                    web_stream_enabled := true "enabled" end)
server.register(namespace="sources",
                description="Stop webstream source",
                "stop_web_stream",
                fun (s) -> begin log("sources.stop_web_stream") web_stream_enabled := false "disabled" end)

server.register(namespace="web_stream",
                description="Set the web stream id",
                "set_id",
                fun (s) -> begin log("web_stream.set_id") web_stream_set_id(s) end)

server.register(namespace="web_stream",
                description="Get the web stream id",
                "get_id",
                fun (s) -> begin log("web_stream.get_id") web_stream_get_id() end)

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

def map_message_offline(m) =
  [("title", message_offline())]
end

#default = map_metadata(id="map_metadata:offline", map_message_offline, default)

# autodj start

# Your jingles
jingles = playlist("/srv/libretime/autodj/jingles/")

# Your backup playlist
musics = playlist(mode="randomize",reload=1,reload_mode="rounds","/srv/libretime/autodj/music/")

# Your hours time signals
clock = single(id="clock","/srv/libretime/autodj/clock.mp3")

# Your security jingle if the AutoDJ drop
security = single("/srv/libretime/autodj/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)

# autodj end
#ignore(output.dummy(default, fallible=true))



input_main_streaming = ref false
input_show_streaming = ref false
schedule_streaming = ref false

def start_input_main() input_main_streaming := true end
def stop_input_main() input_main_streaming := false end
def start_input_show() input_show_streaming := true end
def stop_input_show() input_show_streaming := false end
def start_schedule() schedule_streaming := true; just_switched := true end
def stop_schedule() schedule_streaming := false end

def update_source_status(sourcename, status) =
    gateway("live '#{sourcename}' '#{status}'")
end

def input_main_on_connect(header) update_source_status("master_dj", true) end
def input_main_on_disconnect() update_source_status("master_dj", false) end
def input_show_on_connect(header) update_source_status("live_dj", true) end
def input_show_on_disconnect() update_source_status("live_dj", false) end

def make_input_func(secure)
    if secure then
        input.harbor.ssl
    else
        input.harbor
    end
end

def make_input_auth_handler(input_name)
    def auth_handler(user, password)
        log("user '#{user}' connected", label="#{input_name}_input")

        # Check auth based on return value from auth script
        ret = test_process("libretime-playout-notify live-auth '#{input_name}' '#{user}' '#{password}'")
        if ret then
            log("user '#{user}' authenticated", label="#{input_name}_input")
        else
            log("user '#{user}' auth failed", label="#{input_name}_input",level=2)
        end

        ret
    end
    auth_handler
end

s = switch(id="switch:blank+schedule",
            track_sensitive=false,
            transitions=[transition_default, transition],
            [({!schedule_streaming}, stream_queue), ({true}, default)]
    )

s = if input_show_port != 0 and input_show_mount != "" then
    input_show_func = make_input_func(input_show_secure)
    input_show_source =
        audio_to_stereo(
            input_show_func(id="harbor:input_show",
                input_show_mount,
                port=input_show_port,
                auth=make_input_auth_handler("show"),
                max=40.,
                on_connect=input_show_on_connect,
                on_disconnect=input_show_on_disconnect))

    ignore(output.dummy(input_show_source, fallible=true))

    switch(id="switch:blank+schedule+show",
            track_sensitive=false,
            transitions=[transition, transition],
            [({!input_show_streaming}, input_show_source), ({true}, s)]
        )
else
    s
end

s = if input_main_port != 0 and input_main_mount != "" then
    input_main_func = make_input_func(input_main_secure)
    input_main_source =
        audio_to_stereo(
            input_main_func(id="harbor:input_main",
                input_main_mount,
                port=input_main_port,
                auth=make_input_auth_handler("main"),
                max=40.,
                on_connect=input_main_on_connect,
                on_disconnect=input_main_on_disconnect))

    ignore(output.dummy(input_main_source, fallible=true))

    switch(id="switch:blank+schedule+show+main",
            track_sensitive=false,
            transitions=[transition, transition],
            [({!input_main_streaming}, input_main_source), ({true}, s)]
        )
else
    s
end

server.register(namespace="sources",
    description="Stop main input source.",
    usage="stop_input_main",
    "stop_input_main",
    fun (s) -> begin log("sources.stop_input_main") stop_input_main() "Done." end)
server.register(namespace="sources",
    description="Start main input source.",
    usage="start_input_main",
    "start_input_main",
    fun (s) -> begin log("sources.start_input_main") start_input_main() "Done." end)
server.register(namespace="sources",
    description="Stop show input source.",
    usage="stop_input_show",
    "stop_input_show",
    fun (s) -> begin log("sources.stop_input_show") stop_input_show() "Done." end)
server.register(namespace="sources",
    description="Start show input source.",
    usage="start_input_show",
    "start_input_show",
    fun (s) -> begin log("sources.start_input_show") start_input_show() "Done." end)
server.register(namespace="sources",
    description="Stop schedule source.",
    usage="stop_schedule",
    "stop_schedule",
    fun (s) -> begin log("sources.stop_schedule") stop_schedule() "Done." end)
server.register(namespace="sources",
    description="Start schedule source.",
    usage="start_schedule",
    "start_schedule",
    fun (s) -> begin log("sources.start_schedule") start_schedule() "Done." end)

Final working script. Also check if your mp3’s are good quality and no problems with channels and stuff. Mine was not working due to a clock.mp3 with one channel with problems.

boot_timestamp = string_of(gettimeofday())

web_stream_enabled = ref false
web_stream_id = ref '-1'

show_name = interactive.string("show_name", "")

dynamic_metadata_callback = ref fun (~new_track=false, s) -> begin () end

just_switched = ref false

%include "ls_lib.liq"

sources = ref []
source_id = ref 0

def create_source()
    this_source_id = !source_id

    l = request.equeue(id="s#{this_source_id}", length=0.5)

    l = audio_to_stereo(id="queue_src", l)
    l = cue_cut(l)
    l = amplify(1., override="replay_gain", l)

    # Fade the tracks to avoid hard cuts in between two tracks and at the end of the shows.
    # Liquidsoap reads the fade in/out durations from the annotation "liq_fade_in/out" which
    # value can be set via Libretime settings.
    l = fade.in(l)
    l = fade.out(l)

    l = on_metadata(notify_queue, l)

    sources := list.append([l], !sources)
    server.register(namespace="queues",
                "s#{this_source_id}_skip",
                fun (s) -> begin log("queues.s#{this_source_id}_skip")
                    clear_queue(l)
                    "Done"
                end)
    source_id := !source_id + 1
end

create_source()
create_source()
create_source()
create_source()

queue = add(!sources, normalize=false)
pair = insert_metadata(queue)
dynamic_metadata_callback := fst(pair)
queue = snd(pair)

output.dummy(fallible=true, queue)

http = input.http_restart(id="http")
http = cross_http(http_input_id="http",http)
output.dummy(fallible=true, http)
stream_queue = http_fallback(http_input_id="http", http=http, default=queue)
stream_queue = map_metadata(id="map_metadata:schedule", update=false, append_title, stream_queue)

ignore(output.dummy(stream_queue, fallible=true))

def web_stream_set_id(value)
    web_stream_id := value
    string_of(!web_stream_id)
end

def web_stream_get_id()
    string_of(!web_stream_id)
end

server.register(namespace="sources",
                description="Start webstream source",
                "start_web_stream",
                fun (s) -> begin log("sources.start_web_stream")
                    notify([("schedule_table_id", !web_stream_id)])
                    web_stream_enabled := true "enabled" end)
server.register(namespace="sources",
                description="Stop webstream source",
                "stop_web_stream",
                fun (s) -> begin log("sources.stop_web_stream") web_stream_enabled := false "disabled" end)

server.register(namespace="web_stream",
                description="Set the web stream id",
                "set_id",
                fun (s) -> begin log("web_stream.set_id") web_stream_set_id(s) end)

server.register(namespace="web_stream",
                description="Get the web stream id",
                "get_id",
                fun (s) -> begin log("web_stream.get_id") web_stream_get_id() end)


# Autodj

# Your jingles
jingles = playlist("/srv/libretime/autodj/jingles")

# Your backup playlist
musics = playlist(mode="randomize",reload=1,reload_mode="rounds","/srv/libretime/autodj/music")

# Your hours time signals
clock = single(id="clock","/srv/libretime/autodj/clock.mp3")

# Your security jingle if the AutoDJ drop
security = single("/srv/libretime/autodj/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)
# Autodj
#default = amplify(id="silence_src", 0.00001, noise())

def map_message_offline(m) =
  [("title", message_offline())]
end

default = map_metadata(id="map_metadata:offline", map_message_offline, default)
ignore(output.dummy(default, fallible=true))

input_main_streaming = ref false
input_show_streaming = ref false
schedule_streaming = ref false

def start_input_main() input_main_streaming := true end
def stop_input_main() input_main_streaming := false end
def start_input_show() input_show_streaming := true end
def stop_input_show() input_show_streaming := false end
def start_schedule() schedule_streaming := true; just_switched := true end
def stop_schedule() schedule_streaming := false end

def update_source_status(sourcename, status) =
    gateway("live '#{sourcename}' '#{status}'")
end

def input_main_on_connect(header) update_source_status("master_dj", true) end
def input_main_on_disconnect() update_source_status("master_dj", false) end
def input_show_on_connect(header) update_source_status("live_dj", true) end
def input_show_on_disconnect() update_source_status("live_dj", false) end

def make_input_func(secure)
    if secure then
        input.harbor.ssl
    else
        input.harbor
    end
end

def make_input_auth_handler(input_name)
    def auth_handler(user, password)
        log("user '#{user}' connected", label="#{input_name}_input")

        # Check auth based on return value from auth script
        ret = test_process("libretime-playout-notify live-auth '#{input_name}' '#{user}' '#{password}'")
        if ret then
            log("user '#{user}' authenticated", label="#{input_name}_input")
        else
            log("user '#{user}' auth failed", label="#{input_name}_input",level=2)
        end

        ret
    end
    auth_handler
end

s = switch(id="switch:blank+schedule",
            track_sensitive=false,
            transitions=[transition_default, transition],
            [({!schedule_streaming}, stream_queue), ({true}, default)]
    )

s = if input_show_port != 0 and input_show_mount != "" then
    input_show_func = make_input_func(input_show_secure)
    input_show_source =
        audio_to_stereo(
            input_show_func(id="harbor:input_show",
                input_show_mount,
                port=input_show_port,
                auth=make_input_auth_handler("show"),
                max=40.,
                on_connect=input_show_on_connect,
                on_disconnect=input_show_on_disconnect))

    ignore(output.dummy(input_show_source, fallible=true))

    switch(id="switch:blank+schedule+show",
            track_sensitive=false,
            transitions=[transition, transition],
            [({!input_show_streaming}, input_show_source), ({true}, s)]
        )
else
    s
end

s = if input_main_port != 0 and input_main_mount != "" then
    input_main_func = make_input_func(input_main_secure)
    input_main_source =
        audio_to_stereo(
            input_main_func(id="harbor:input_main",
                input_main_mount,
                port=input_main_port,
                auth=make_input_auth_handler("main"),
                max=40.,
                on_connect=input_main_on_connect,
                on_disconnect=input_main_on_disconnect))

    ignore(output.dummy(input_main_source, fallible=true))

    switch(id="switch:blank+schedule+show+main",
            track_sensitive=false,
            transitions=[transition, transition],
            [({!input_main_streaming}, input_main_source), ({true}, s)]
        )
else
    s
end

server.register(namespace="sources",
    description="Stop main input source.",
    usage="stop_input_main",
    "stop_input_main",
    fun (s) -> begin log("sources.stop_input_main") stop_input_main() "Done." end)
server.register(namespace="sources",
    description="Start main input source.",
    usage="start_input_main",
    "start_input_main",
    fun (s) -> begin log("sources.start_input_main") start_input_main() "Done." end)
server.register(namespace="sources",
    description="Stop show input source.",
    usage="stop_input_show",
    "stop_input_show",
    fun (s) -> begin log("sources.stop_input_show") stop_input_show() "Done." end)
server.register(namespace="sources",
    description="Start show input source.",
    usage="start_input_show",
    "start_input_show",
    fun (s) -> begin log("sources.start_input_show") start_input_show() "Done." end)
server.register(namespace="sources",
    description="Stop schedule source.",
    usage="stop_schedule",
    "stop_schedule",
    fun (s) -> begin log("sources.stop_schedule") stop_schedule() "Done." end)
server.register(namespace="sources",
    description="Start schedule source.",
    usage="start_schedule",
    "start_schedule",
    fun (s) -> begin log("sources.start_schedule") start_schedule() "Done." end)