Advertisement
Mitch_sgg

Untitled

Feb 12th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.97 KB | None | 0 0
  1. init.daemon.set(false)
  2. init.daemon.pidfile.path.set("/var/azuracast/stations/renovaradio/config/liquidsoap.pid")
  3. log.stdout.set(true)
  4. log.file.set(false)
  5. settings.server.log.level.set(4)
  6. settings.server.telnet.set(true)
  7. settings.server.telnet.bind_addr.set("0.0.0.0")
  8. settings.server.telnet.port.set(8004)
  9. settings.harbor.bind_addrs.set(["0.0.0.0"])
  10.  
  11. settings.tag.encodings.set(["UTF-8","ISO-8859-1"])
  12. settings.encoder.metadata.export.set(["artist","title","album","song"])
  13.  
  14. setenv("TZ", "America/Sao_Paulo")
  15.  
  16. autodj_is_loading = ref(true)
  17. ignore(autodj_is_loading)
  18.  
  19. autodj_ping_attempts = ref(0)
  20. ignore(autodj_ping_attempts)
  21.  
  22. # Track live-enabled status script-wide for fades.
  23. live_enabled = ref(false)
  24. ignore(live_enabled)
  25.  
  26. azuracast_api_url = "http://web/api/internal/1"
  27. azuracast_api_key = "a0ea126ac160c2c121d4eb2c30c3d185a1df65a438602beffd9522c64a5158f966409d71fce617b8738c07194a7434f93e85"
  28.  
  29. def azuracast_api_call(~timeout=2, url, payload) =
  30. full_url = "#{azuracast_api_url}/#{url}"
  31.  
  32. log("API #{url} - Sending POST request to '#{full_url}' with body: #{payload}")
  33. try
  34. response = http.post(full_url,
  35. headers=[
  36. ("Content-Type", "application/json"),
  37. ("User-Agent", "Liquidsoap AzuraCast"),
  38. ("X-Liquidsoap-Api-Key", "#{azuracast_api_key}")
  39. ],
  40. timeout=timeout,
  41. data=payload
  42. )
  43.  
  44. log("API #{url} - Response (#{response.status_code}): #{response}")
  45. {success = response.status_code == 200, data = "#{response}"}
  46. catch err do
  47. log("API #{url} - Error: #{error.kind(err)} - #{error.message(err)}")
  48. {success = false, data = ""}
  49. end
  50. end
  51.  
  52. playlist_geral = playlist(id="playlist_geral",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_geral.m3u")
  53. playlist_geral = cue_cut(id="cue_playlist_geral", playlist_geral)
  54.  
  55. 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")
  56. playlist_tuga_som = cue_cut(id="cue_playlist_tuga_som", playlist_tuga_som)
  57.  
  58. 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")
  59. playlist_0_10 = cue_cut(id="cue_playlist_0_10", playlist_0_10)
  60.  
  61. playlist_playfitas = playlist(id="playlist_playfitas",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_playfitas.m3u")
  62. playlist_playfitas = cue_cut(id="cue_playlist_playfitas", playlist_playfitas)
  63.  
  64. playlist_eletronicas = mksafe(buffer(buffer=60., input.http(max_buffer=60., "http://104.227.175.125:80/livemix")))
  65.  
  66. 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")
  67. playlist_el_bar_de_moteros = cue_cut(id="cue_playlist_el_bar_de_moteros", playlist_el_bar_de_moteros)
  68.  
  69. 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")
  70. playlist_la_hora_del_relax = cue_cut(id="cue_playlist_la_hora_del_relax", playlist_la_hora_del_relax)
  71.  
  72. 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")
  73. playlist_la_ventana_espanhola = cue_cut(id="cue_playlist_la_ventana_espanhola", playlist_la_ventana_espanhola)
  74.  
  75. 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")
  76. playlist_raizes_do_sertao = cue_cut(id="cue_playlist_raizes_do_sertao", playlist_raizes_do_sertao)
  77.  
  78. 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")
  79. playlist_siempre_ladys = cue_cut(id="cue_playlist_siempre_ladys", playlist_siempre_ladys)
  80.  
  81. 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")
  82. playlist_especial_ntal = cue_cut(id="cue_playlist_especial_ntal", playlist_especial_ntal)
  83.  
  84. def schedule_42_date_range() =
  85. # 2021-12-23 00:00:00
  86. range_start = 1640228400.
  87. # 2022-01-02 23:59:59
  88. range_end = 1641178799.
  89. current_time = time()
  90. range_start <= current_time and current_time <= range_end
  91. end
  92.  
  93. 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")
  94. playlist_especial_natal2 = cue_cut(id="cue_playlist_especial_natal2", playlist_especial_natal2)
  95.  
  96. def schedule_43_date_range() =
  97. # 2021-12-23 00:00:00
  98. range_start = 1640228400.
  99. # 2022-01-02 23:59:59
  100. range_end = 1641178799.
  101. current_time = time()
  102. range_start <= current_time and current_time <= range_end
  103. end
  104.  
  105. 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")
  106. playlist_eletro_party = cue_cut(id="cue_playlist_eletro_party", playlist_eletro_party)
  107.  
  108. playlist_sertanejo = playlist(id="playlist_sertanejo",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_sertanejo.m3u")
  109. playlist_sertanejo = cue_cut(id="cue_playlist_sertanejo", playlist_sertanejo)
  110.  
  111. playlist_80s90s = playlist(id="playlist_80s90s",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_80s90s.m3u")
  112. playlist_80s90s = cue_cut(id="cue_playlist_80s90s", playlist_80s90s)
  113.  
  114. playlist_chamadas = playlist(id="playlist_chamadas",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_chamadas.m3u")
  115. playlist_chamadas = cue_cut(id="cue_playlist_chamadas", playlist_chamadas)
  116. playlist_chamadas = drop_metadata(playlist_chamadas)
  117.  
  118. playlist_vinhetas = playlist(id="playlist_vinhetas",mime_type="audio/x-mpegurl",mode="randomize",reload_mode="watch","/var/azuracast/stations/renovaradio/playlists/playlist_vinhetas.m3u")
  119. playlist_vinhetas = cue_cut(id="cue_playlist_vinhetas", playlist_vinhetas)
  120. playlist_vinhetas = drop_metadata(playlist_vinhetas)
  121.  
  122. # Standard Playlists
  123. radio = random(id="standard_playlists", weights=[3, 2], [playlist_geral, playlist_sertanejo])
  124.  
  125. # Standard Schedule Switches
  126.  
  127. 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) ])
  128.  
  129. # Once per x Songs Playlists
  130. radio = rotate(weights=[1,30], [playlist_80s90s, radio])
  131. radio = rotate(weights=[1,15], [playlist_chamadas, radio])
  132. radio = rotate(weights=[1,2], [playlist_vinhetas, radio])
  133.  
  134. # AutoDJ Next Song Script
  135. def autodj_next_song() =
  136. response = azuracast_api_call(
  137. "nextsong",
  138. ""
  139. )
  140. if (response.success != true) or (response.data == "") or (string.match(pattern="Error", response.data)) then
  141. null()
  142. else
  143. r = request.create(response.data)
  144. if request.resolve(r) then
  145. r
  146. else
  147. null()
  148. end
  149. end
  150. end
  151.  
  152. # Delayed ping for AutoDJ Next Song
  153. def wait_for_next_song(autodj)
  154. autodj_ping_attempts := !autodj_ping_attempts + 1
  155.  
  156. if source.is_ready(autodj) then
  157. log("AutoDJ is ready!")
  158. autodj_is_loading := false
  159. -1.0
  160. elsif !autodj_ping_attempts > 200 then
  161. log("AutoDJ could not be initialized within the specified timeout.")
  162. autodj_is_loading := false
  163. -1.0
  164. else
  165. 0.5
  166. end
  167. end
  168.  
  169. dynamic = request.dynamic(id="next_song", timeout=20., retry_delay=2., autodj_next_song)
  170. dynamic = cue_cut(id="cue_next_song", dynamic)
  171.  
  172. dynamic_startup = fallback(
  173. id = "dynamic_startup",
  174. track_sensitive = false,
  175. [
  176. dynamic,
  177. source.available(
  178. blank(id = "autodj_startup_blank", duration = 120.),
  179. predicate.activates({!autodj_is_loading})
  180. )
  181. ]
  182. )
  183. radio = fallback(id="autodj_fallback", track_sensitive = true, [dynamic_startup, radio])
  184.  
  185. ref_dynamic = ref(dynamic);
  186. thread.run.recurrent(delay=0.25, { wait_for_next_song(!ref_dynamic) })
  187.  
  188. # Interrupting Schedule Switches
  189. 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) ])
  190.  
  191. requests = request.queue(id="requests")
  192. requests = cue_cut(id="cue_requests", requests)
  193.  
  194. radio = fallback(id="requests_fallback", track_sensitive = true, [requests, radio])
  195. add_skip_command(radio)
  196.  
  197. radio = crossfade(smart=false, duration=3.2, fade_out=2.7, fade_in=0.4, radio)
  198. # DJ Authentication
  199. last_authenticated_dj = ref("")
  200. live_dj = ref("")
  201.  
  202. live_record_path = ref("")
  203.  
  204. def dj_auth(login) =
  205. auth_info =
  206. if (login.user == "source" or login.user == "") and (string.match(pattern="(:|,)+", login.password)) then
  207. auth_string = string.split(separator="(:|,)", login.password)
  208. {user = list.nth(default="", auth_string, 0),
  209. password = list.nth(default="", auth_string, 2)}
  210. else
  211. {user = login.user, password = login.password}
  212. end
  213.  
  214. response = azuracast_api_call(
  215. timeout=5,
  216. "auth",
  217. json.stringify(auth_info)
  218. )
  219. if response.success then
  220. last_authenticated_dj := auth_info.user
  221. true
  222. else
  223. false
  224. end
  225. end
  226.  
  227. def live_connected(header) =
  228. dj = !last_authenticated_dj
  229. log("DJ Source connected! Last authenticated DJ: #{dj} - #{header}")
  230.  
  231. live_enabled := true
  232. live_dj := dj
  233.  
  234. j = json()
  235. j.add("user", dj)
  236.  
  237. response = azuracast_api_call(
  238. timeout=5,
  239. "djon",
  240. json.stringify(j)
  241. )
  242. if response.success and string.contains(prefix="/", response.data) then
  243. live_record_path := response.data
  244. end
  245. end
  246.  
  247. def live_disconnected() =
  248. dj = !live_dj
  249.  
  250. j = json()
  251. j.add("user", dj)
  252.  
  253. _ = azuracast_api_call(
  254. timeout=5,
  255. "djoff",
  256. json.stringify(j)
  257. )
  258.  
  259. live_enabled := false
  260. last_authenticated_dj := ""
  261. live_dj := ""
  262.  
  263. live_record_path := ""
  264. end
  265.  
  266. # A Pre-DJ source of radio that can be broadcast if needed',
  267. radio_without_live = radio
  268. ignore(radio_without_live)
  269.  
  270. # Live Broadcasting
  271. 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)
  272.  
  273. def insert_missing(m) =
  274. if m == [] then
  275. [("title", "Live Broadcast")]
  276. else
  277. m
  278. end
  279. end
  280. live = map_metadata(insert_missing, live)
  281.  
  282. radio = fallback(id="live_fallback", replay_metadata=true, track_sensitive=false, [live, radio])
  283.  
  284. # Allow for Telnet-driven insertion of custom metadata.
  285. radio = server.insert_metadata(id="custom_metadata", radio)
  286.  
  287. # Apply amplification metadata (if supplied)
  288. radio = amplify(override="liq_amplify", 1., radio)
  289.  
  290. # Normalization and Compression
  291. radio = normalize(target = 0., window = 0.03, gain_min = -16., gain_max = 0., radio)
  292. radio = compress.exponential(radio, mu = 1.0)
  293.  
  294. radio = fallback(id="safe_fallback", track_sensitive = false, [radio, single(id="error_jingle", "/usr/local/share/icecast/web/error.mp3")])
  295.  
  296. # Send metadata changes back to AzuraCast
  297. def metadata_updated(m) =
  298. def f() =
  299. if (m["song_id"] != "") then
  300. j = json()
  301. j.add("song_id", m["song_id"])
  302. j.add("media_id", m["media_id"])
  303. j.add("playlist_id", m["playlist_id"])
  304.  
  305. _ = azuracast_api_call(
  306. "feedback",
  307. json.stringify(j)
  308. )
  309. end
  310. end
  311.  
  312. thread.run(f)
  313. end
  314.  
  315. radio.on_metadata(metadata_updated)
  316.  
  317. # Local Broadcasts
  318. 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)
  319. 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