Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- init.daemon.set(false)
- init.daemon.pidfile.path.set("/var/azuracast/stations/renovaradio/config/liquidsoap.pid")
- log.stdout.set(true)
- log.file.set(false)
- settings.server.log.level.set(4)
- settings.server.telnet.set(true)
- settings.server.telnet.bind_addr.set("0.0.0.0")
- settings.server.telnet.port.set(8004)
- settings.harbor.bind_addrs.set(["0.0.0.0"])
- settings.tag.encodings.set(["UTF-8","ISO-8859-1"])
- settings.encoder.metadata.export.set(["artist","title","album","song"])
- setenv("TZ", "America/Sao_Paulo")
- autodj_is_loading = ref(true)
- ignore(autodj_is_loading)
- autodj_ping_attempts = ref(0)
- ignore(autodj_ping_attempts)
- # Track live-enabled status script-wide for fades.
- live_enabled = ref(false)
- ignore(live_enabled)
- azuracast_api_url = "http://web/api/internal/1"
- azuracast_api_key = "a0ea126ac160c2c121d4eb2c30c3d185a1df65a438602beffd9522c64a5158f966409d71fce617b8738c07194a7434f93e85"
- def azuracast_api_call(~timeout=2, url, payload) =
- full_url = "#{azuracast_api_url}/#{url}"
- log("API #{url} - Sending POST request to '#{full_url}' with body: #{payload}")
- try
- response = http.post(full_url,
- headers=[
- ("Content-Type", "application/json"),
- ("User-Agent", "Liquidsoap AzuraCast"),
- ("X-Liquidsoap-Api-Key", "#{azuracast_api_key}")
- ],
- timeout=timeout,
- data=payload
- )
- log("API #{url} - Response (#{response.status_code}): #{response}")
- {success = response.status_code == 200, data = "#{response}"}
- catch err do
- log("API #{url} - Error: #{error.kind(err)} - #{error.message(err)}")
- {success = false, data = ""}
- end
- end
- playlist_geral = playlist(id="playlist_geral",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_geral.m3u")
- playlist_geral = cue_cut(id="cue_playlist_geral", playlist_geral)
- playlist_tuga_som = playlist(id="playlist_tuga_som",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_tuga_som.m3u")
- playlist_tuga_som = cue_cut(id="cue_playlist_tuga_som", playlist_tuga_som)
- playlist_0_10 = playlist(id="playlist_0_10",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_0-10.m3u")
- playlist_0_10 = cue_cut(id="cue_playlist_0_10", playlist_0_10)
- playlist_playfitas = playlist(id="playlist_playfitas",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_playfitas.m3u")
- playlist_playfitas = cue_cut(id="cue_playlist_playfitas", playlist_playfitas)
- playlist_eletronicas = mksafe(buffer(buffer=60., input.http(max_buffer=60., "http://104.227.175.125:80/livemix")))
- playlist_el_bar_de_moteros = playlist(id="playlist_el_bar_de_moteros",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_el_bar_de_moteros.m3u")
- playlist_el_bar_de_moteros = cue_cut(id="cue_playlist_el_bar_de_moteros", playlist_el_bar_de_moteros)
- playlist_la_hora_del_relax = playlist(id="playlist_la_hora_del_relax",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_la_hora_del_relax.m3u")
- playlist_la_hora_del_relax = cue_cut(id="cue_playlist_la_hora_del_relax", playlist_la_hora_del_relax)
- playlist_la_ventana_espanhola = playlist(id="playlist_la_ventana_espanhola",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_la_ventana_espanhola.m3u")
- playlist_la_ventana_espanhola = cue_cut(id="cue_playlist_la_ventana_espanhola", playlist_la_ventana_espanhola)
- playlist_raizes_do_sertao = playlist(id="playlist_raizes_do_sertao",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_raizes_do_sertão.m3u")
- playlist_raizes_do_sertao = cue_cut(id="cue_playlist_raizes_do_sertao", playlist_raizes_do_sertao)
- playlist_siempre_ladys = playlist(id="playlist_siempre_ladys",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_siempre_ladys.m3u")
- playlist_siempre_ladys = cue_cut(id="cue_playlist_siempre_ladys", playlist_siempre_ladys)
- playlist_especial_ntal = playlist(id="playlist_especial_ntal",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_especial_ntal.m3u")
- playlist_especial_ntal = cue_cut(id="cue_playlist_especial_ntal", playlist_especial_ntal)
- def schedule_42_date_range() =
- # 2021-12-23 00:00:00
- range_start = 1640228400.
- # 2022-01-02 23:59:59
- range_end = 1641178799.
- current_time = time()
- range_start <= current_time and current_time <= range_end
- end
- playlist_especial_natal2 = playlist(id="playlist_especial_natal2",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_especial_natal2.m3u")
- playlist_especial_natal2 = cue_cut(id="cue_playlist_especial_natal2", playlist_especial_natal2)
- def schedule_43_date_range() =
- # 2021-12-23 00:00:00
- range_start = 1640228400.
- # 2022-01-02 23:59:59
- range_end = 1641178799.
- current_time = time()
- range_start <= current_time and current_time <= range_end
- end
- playlist_eletro_party = playlist(id="playlist_eletro_party",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_eletro_party.m3u")
- playlist_eletro_party = cue_cut(id="cue_playlist_eletro_party", playlist_eletro_party)
- playlist_sertanejo = playlist(id="playlist_sertanejo",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_sertanejo.m3u")
- playlist_sertanejo = cue_cut(id="cue_playlist_sertanejo", playlist_sertanejo)
- playlist_80s90s = playlist(id="playlist_80s90s",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_80s90s.m3u")
- playlist_80s90s = cue_cut(id="cue_playlist_80s90s", playlist_80s90s)
- playlist_chamadas = playlist(id="playlist_chamadas",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_chamadas.m3u")
- playlist_chamadas = cue_cut(id="cue_playlist_chamadas", playlist_chamadas)
- playlist_chamadas = drop_metadata(playlist_chamadas)
- playlist_vinhetas = playlist(id="playlist_vinhetas",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_vinhetas.m3u")
- playlist_vinhetas = cue_cut(id="cue_playlist_vinhetas", playlist_vinhetas)
- playlist_vinhetas = drop_metadata(playlist_vinhetas)
- # Standard Playlists
- radio = random(id="standard_playlists", weights=[3, 2], [playlist_geral, playlist_sertanejo])
- # Standard Schedule Switches
- radio = switch(id="schedule_switch", track_sensitive=true, [ ({ (1w) and 14h0m }, playlist_tuga_som), ({ (4w) and 11h10m }, playlist_0_10), ({ (2w) and 12h10m }, playlist_0_10), ({ (5w or 0w) and 16h10m }, playlist_playfitas), ({ (3w) and 12h10m }, playlist_el_bar_de_moteros), ({ (5w) and 13h10m }, playlist_el_bar_de_moteros), ({ (6w) and 8h10m }, playlist_el_bar_de_moteros), ({ (6w or 0w) and 21h10m }, playlist_la_hora_del_relax), ({ (1w or 5w) and 12h10m }, playlist_la_ventana_espanhola), ({ (4w) and 13h10m }, playlist_la_ventana_espanhola), ({ (0w) and 10h10m }, playlist_raizes_do_sertao), ({ (6w) and 16h10m }, playlist_raizes_do_sertao), ({ (2w or 4w) and 16h10m }, playlist_siempre_ladys), ({ (5w or 6w) and 19h10m }, playlist_eletro_party), ({true}, radio) ])
- # Once per x Songs Playlists
- radio = rotate(weights=[1,30], [playlist_80s90s, radio])
- radio = rotate(weights=[1,15], [playlist_chamadas, radio])
- radio = rotate(weights=[1,2], [playlist_vinhetas, radio])
- # AutoDJ Next Song Script
- def autodj_next_song() =
- response = azuracast_api_call(
- "nextsong",
- ""
- )
- if (response.success != true) or (response.data == "") or (string.match(pattern="Error", response.data)) then
- null()
- else
- r = request.create(response.data)
- if request.resolve(r) then
- r
- else
- null()
- end
- end
- end
- # Delayed ping for AutoDJ Next Song
- def wait_for_next_song(autodj)
- autodj_ping_attempts := !autodj_ping_attempts + 1
- if source.is_ready(autodj) then
- log("AutoDJ is ready!")
- autodj_is_loading := false
- -1.0
- elsif !autodj_ping_attempts > 200 then
- log("AutoDJ could not be initialized within the specified timeout.")
- autodj_is_loading := false
- -1.0
- else
- 0.5
- end
- end
- dynamic = request.dynamic(id="next_song", timeout=20., retry_delay=2., autodj_next_song)
- dynamic = cue_cut(id="cue_next_song", dynamic)
- dynamic_startup = fallback(
- id = "dynamic_startup",
- track_sensitive = false,
- [
- dynamic,
- source.available(
- blank(id = "autodj_startup_blank", duration = 120.),
- predicate.activates({!autodj_is_loading})
- )
- ]
- )
- radio = fallback(id="autodj_fallback", track_sensitive = true, [dynamic_startup, radio])
- ref_dynamic = ref(dynamic);
- thread.run.recurrent(delay=0.25, { wait_for_next_song(!ref_dynamic) })
- # Interrupting Schedule Switches
- radio = switch(id="interrupt_switch", track_sensitive=false, [ ({ 0h15m-7h0m }, playlist_eletronicas), ({ schedule_42_date_range() and (5w or 6w) and 16h10m }, playlist_especial_ntal), ({ schedule_43_date_range() and (5w or 6w) and 12h10m }, playlist_especial_natal2), ({true}, radio) ])
- requests = request.queue(id="requests")
- requests = cue_cut(id="cue_requests", requests)
- radio = fallback(id="requests_fallback", track_sensitive = true, [requests, radio])
- add_skip_command(radio)
- radio = crossfade(smart=false, duration=3.2, fade_out=2.7, fade_in=0.4, radio)
- # DJ Authentication
- last_authenticated_dj = ref("")
- live_dj = ref("")
- live_record_path = ref("")
- def dj_auth(login) =
- auth_info =
- if (login.user == "source" or login.user == "") and (string.match(pattern="(:|,)+", login.password)) then
- auth_string = string.split(separator="(:|,)", login.password)
- {user = list.nth(default="", auth_string, 0),
- password = list.nth(default="", auth_string, 2)}
- else
- {user = login.user, password = login.password}
- end
- response = azuracast_api_call(
- timeout=5,
- "auth",
- json.stringify(auth_info)
- )
- if response.success then
- last_authenticated_dj := auth_info.user
- true
- else
- false
- end
- end
- def live_connected(header) =
- dj = !last_authenticated_dj
- log("DJ Source connected! Last authenticated DJ: #{dj} - #{header}")
- live_enabled := true
- live_dj := dj
- j = json()
- j.add("user", dj)
- response = azuracast_api_call(
- timeout=5,
- "djon",
- json.stringify(j)
- )
- if response.success and string.contains(prefix="/", response.data) then
- live_record_path := response.data
- end
- end
- def live_disconnected() =
- dj = !live_dj
- j = json()
- j.add("user", dj)
- _ = azuracast_api_call(
- timeout=5,
- "djoff",
- json.stringify(j)
- )
- live_enabled := false
- last_authenticated_dj := ""
- live_dj := ""
- live_record_path := ""
- end
- # A Pre-DJ source of radio that can be broadcast if needed',
- radio_without_live = radio
- ignore(radio_without_live)
- # Live Broadcasting
- live = input.harbor("/", id = "input_streamer", port = 8005, auth = dj_auth, icy = true, icy_metadata_charset = "UTF-8", metadata_charset = "UTF-8", on_connect = live_connected, on_disconnect = live_disconnected)
- def insert_missing(m) =
- if m == [] then
- [("title", "Live Broadcast")]
- else
- m
- end
- end
- live = map_metadata(insert_missing, live)
- radio = fallback(id="live_fallback", replay_metadata=true, track_sensitive=false, [live, radio])
- # Allow for Telnet-driven insertion of custom metadata.
- radio = server.insert_metadata(id="custom_metadata", radio)
- # Apply amplification metadata (if supplied)
- radio = amplify(override="liq_amplify", 1., radio)
- # Normalization and Compression
- radio = normalize(target = 0., window = 0.03, gain_min = -16., gain_max = 0., radio)
- radio = compress.exponential(radio, mu = 1.0)
- radio = fallback(id="safe_fallback", track_sensitive = false, [radio, single(id="error_jingle", "/usr/local/share/icecast/web/error.mp3")])
- # Send metadata changes back to AzuraCast
- def metadata_updated(m) =
- def f() =
- if (m["song_id"] != "") then
- j = json()
- j.add("song_id", m["song_id"])
- j.add("media_id", m["media_id"])
- j.add("playlist_id", m["playlist_id"])
- _ = azuracast_api_call(
- "feedback",
- json.stringify(j)
- )
- end
- end
- thread.run(f)
- end
- radio.on_metadata(metadata_updated)
- # Local Broadcasts
- output.icecast(%mp3(samplerate=44100, stereo=true, bitrate=128, id3v2=true), id="local_1", host = "127.0.0.1", port = 8000, password = "ZK7ymz9C", mount = "/radio.mp3", name = "RenovaRadio", description = "A Renovação Do Som!", genre = "Variado", url = "https://www.renovagames.com/radio", public = false, encoding = "UTF-8", radio)
- output.icecast(%fdkaac(channels=2, samplerate=44100, bitrate=32, afterburner=false, aot="mpeg4_he_aac_v2", sbr_mode=true), id="local_2", host = "127.0.0.1", port = 8000, password = "ZK7ymz9C", mount = "/radio.aac", name = "RenovaRadio", description = "A Renovação Do Som!", genre = "Variado", url = "https://www.renovagames.com/radio", public = true, encoding = "UTF-8", radio)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement