%include "secrets.liq" %include "tweaks.liq" %include "restful.liq" set("init.daemon", true) set("init.daemon.change_user", true) set("init.daemon.change_user.group", "liquidsoap") set("init.daemon.change_user.user", "liquidsoap") set("init.daemon.pidfile", true) set("init.daemon.pidfile.path", pid_file) set("log.file", true) set("log.file.path", log_file) set("log.stdout", true) set("log.level", 4) set("server.telnet", false) set("scheduler.generic_queues", 5) set("scheduler.fast_queues", 3) set("scheduler.non_blocking_queues", 3) set("audio.converter.samplerate.libsamplerate.quality", "best") def next_song() = log = log(label="next_song") log("Requesting the next song from #{url_next}") let (status_code, data) = get_http_data(api_headers_next, url_next) log(data) if status_code == 200 then request.create(data) else request.create(fallback_annotate) end end def change_meta(m) = log = log(label="change_meta") artist = m["artist"] game = m["game"] title = m["title"] log("Request ID: "^string.quote(m["req_id"])) log("Artist: #{artist} -- Game: #{game} -- Title: #{title}") [("artist","#{artist}"), ("title","#{title} [#{game}]"), ("req_id",m["req_id"]), ("type",m["type"]), ("game",m["game"]), ("replay_gain",m["replay_gain"])] end def just_played(m) = log = log(label="just_played") if m["req_id"] != "" then log('Letting server know we played request ID #{m["req_id"]} here: #{url_played}') played_song = json_of(compact=true, [("song_request", int_of_string(m["req_id"]))]) let (status_code, data) = post_http_data(api_headers_played, played_song, url_played) if status_code == 204 then log('Successfully reported that the song was played.') else log('Error while reporting the song was played: #{data}') end else log("No request ID! Stream just started or there are other problems.") end end security = single(id="default", fallback_audio) radio = request.dynamic(id="main", default_duration=120., length=60., next_song) radio = map_metadata(update=false, change_meta, radio) radio = on_metadata(id="main", just_played, radio) radio = amplify(1., override="replay_gain", radio) radio = smart_cross(radio) radio = fallback(track_sensitive=false, [radio, security]) output.icecast(%mp3, encoding="UTF-8", protocol="http", name=radio_name, description=radio_description, genre=radio_genre, url=radio_url_main, host=stream_address, port=stream_port, password=stream_password, mount="stream128.mp3", radio) output.icecast(%vorbis(samplerate=44100, channels=2, quality=0.9), encoding="UTF-8", protocol="http", name=radio_name, description=radio_description, genre=radio_genre, url=radio_url_main, host=stream_address, port=stream_port, password=stream_password, mount="stream320.ogg", radio) output.icecast(%vorbis(samplerate=44100, channels=2, quality=0.4), encoding="UTF-8", protocol="http", name=radio_name, description=radio_description, genre=radio_genre, url=radio_url_main, host=stream_address, port=stream_port, password=stream_password, mount="stream128.ogg", radio) output.icecast(%vorbis(samplerate=44100, channels=2, quality=0.0), encoding="UTF-8", protocol="http", name=radio_name, description=radio_description, genre=radio_genre, url=radio_url_main, host=stream_address, port=stream_port, password=stream_password, mount="stream64.ogg", radio)