ls_script.liq 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. %include "/etc/airtime/liquidsoap.cfg"
  2. set("log.file.path", log_file)
  3. set("server.telnet", true)
  4. set("server.telnet.port", 1234)
  5. # set("init.daemon.pidfile.path", "/var/run/airtime/airtime-liquidsoap.pid")
  6. %include "library/pervasives.liq"
  7. #Dynamic source list
  8. #dyn_sources = ref []
  9. webstream_enabled = ref false
  10. time = ref string_of(gettimeofday())
  11. #live stream setup
  12. set("harbor.bind_addr", "0.0.0.0")
  13. current_dyn_id = ref '-1'
  14. pypo_data = ref '0'
  15. stream_metadata_type = ref 0
  16. default_dj_fade = ref 0.
  17. station_name = ref ''
  18. show_name = ref ''
  19. dynamic_metadata_callback = ref fun (s) -> begin () end
  20. s1_connected = ref ''
  21. s2_connected = ref ''
  22. s3_connected = ref ''
  23. s1_namespace = ref ''
  24. s2_namespace = ref ''
  25. s3_namespace = ref ''
  26. just_switched = ref false
  27. %include "ls_lib.liq"
  28. sources = ref []
  29. source_id = ref 0
  30. def create_source()
  31. l = request.equeue(id="s#{!source_id}", length=0.5)
  32. l = audio_to_stereo(id="queue_src", l)
  33. l = cue_cut(l)
  34. l = amplify(1., override="replay_gain", l)
  35. # the crossfade function controls fade in/out
  36. l = crossfade_airtime(l)
  37. l = on_metadata(notify_queue, l)
  38. sources := list.append([l], !sources)
  39. server.register(namespace="queues",
  40. "s#{!source_id}_skip",
  41. fun (s) -> begin log("queues.s#{!source_id}_skip")
  42. clear_queue(l)
  43. "Done"
  44. end)
  45. source_id := !source_id + 1
  46. end
  47. create_source()
  48. create_source()
  49. create_source()
  50. create_source()
  51. create_source()
  52. create_source()
  53. create_source()
  54. create_source()
  55. queue = add(!sources, normalize=false)
  56. pair = insert_metadata(queue)
  57. dynamic_metadata_callback := fst(pair)
  58. queue = snd(pair)
  59. output.dummy(fallible=true, queue)
  60. http = input.http_restart(id="http")
  61. http = cross_http(http_input_id="http",http)
  62. output.dummy(fallible=true, http)
  63. stream_queue = http_fallback(http_input_id="http", http=http, default=queue)
  64. stream_queue = map_metadata(update=false, append_title, stream_queue)
  65. ignore(output.dummy(stream_queue, fallible=true))
  66. server.register(namespace="vars",
  67. "pypo_data",
  68. fun (s) -> begin log("vars.pypo_data") pypo_data := s "Done" end)
  69. server.register(namespace="vars",
  70. "stream_metadata_type",
  71. fun (s) -> begin log("vars.stream_metadata_type") stream_metadata_type := int_of_string(s) s end)
  72. server.register(namespace="vars",
  73. "show_name",
  74. fun (s) -> begin log("vars.show_name") show_name := s s end)
  75. server.register(namespace="vars",
  76. "station_name",
  77. fun (s) -> begin log("vars.station_name") station_name := s s end)
  78. server.register(namespace="vars",
  79. "bootup_time",
  80. fun (s) -> begin log("vars.bootup_time") time := s s end)
  81. server.register(namespace="streams",
  82. "connection_status",
  83. fun (s) -> begin log("streams.connection_status") "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected}" end)
  84. server.register(namespace="vars",
  85. "default_dj_fade",
  86. fun (s) -> begin log("vars.default_dj_fade") default_dj_fade := float_of_string(s) s end)
  87. server.register(namespace="dynamic_source",
  88. description="Enable webstream output",
  89. usage='start',
  90. "output_start",
  91. fun (s) -> begin log("dynamic_source.output_start")
  92. notify([("schedule_table_id", !current_dyn_id)])
  93. webstream_enabled := true "enabled" end)
  94. server.register(namespace="dynamic_source",
  95. description="Enable webstream output",
  96. usage='stop',
  97. "output_stop",
  98. fun (s) -> begin log("dynamic_source.output_stop") webstream_enabled := false "disabled" end)
  99. server.register(namespace="dynamic_source",
  100. description="Set the streams cc_schedule row id",
  101. usage="id <id>",
  102. "id",
  103. fun (s) -> begin log("dynamic_source.id") set_dynamic_source_id(s) end)
  104. server.register(namespace="dynamic_source",
  105. description="Get the streams cc_schedule row id",
  106. usage="get_id",
  107. "get_id",
  108. fun (s) -> begin log("dynamic_source.get_id") get_dynamic_source_id() end)
  109. #server.register(namespace="dynamic_source",
  110. # description="Start a new dynamic source.",
  111. # usage="start <uri>",
  112. # "read_start",
  113. # fun (uri) -> begin log("dynamic_source.read_start") begin_stream_read(uri) end)
  114. #server.register(namespace="dynamic_source",
  115. # description="Stop a dynamic source.",
  116. # usage="stop <id>",
  117. # "read_stop",
  118. # fun (s) -> begin log("dynamic_source.read_stop") stop_stream_read(s) end)
  119. #server.register(namespace="dynamic_source",
  120. # description="Stop a dynamic source.",
  121. # usage="stop <id>",
  122. # "read_stop_all",
  123. # fun (s) -> begin log("dynamic_source.read_stop") destroy_dynamic_source_all() end)
  124. default = amplify(id="silence_src", 0.00001, noise())
  125. ref_off_air_meta = ref off_air_meta
  126. if !ref_off_air_meta == "" then
  127. ref_off_air_meta := "Airtime - offline"
  128. end
  129. default = rewrite_metadata([("title", !ref_off_air_meta)], default)
  130. ignore(output.dummy(default, fallible=true))
  131. master_dj_enabled = ref false
  132. live_dj_enabled = ref false
  133. scheduled_play_enabled = ref false
  134. def make_master_dj_available()
  135. master_dj_enabled := true
  136. end
  137. def make_master_dj_unavailable()
  138. master_dj_enabled := false
  139. end
  140. def make_live_dj_available()
  141. live_dj_enabled := true
  142. end
  143. def make_live_dj_unavailable()
  144. live_dj_enabled := false
  145. end
  146. def make_scheduled_play_available()
  147. scheduled_play_enabled := true
  148. just_switched := true
  149. end
  150. def make_scheduled_play_unavailable()
  151. scheduled_play_enabled := false
  152. end
  153. def update_source_status(sourcename, status) =
  154. command = "timeout --signal=KILL 45 pyponotify --source-name=#{sourcename} --source-status=#{status} &"
  155. system(command)
  156. log(command)
  157. end
  158. def live_dj_connect(header) =
  159. update_source_status("live_dj", true)
  160. end
  161. def live_dj_disconnect() =
  162. update_source_status("live_dj", false)
  163. end
  164. def master_dj_connect(header) =
  165. update_source_status("master_dj", true)
  166. end
  167. def master_dj_disconnect() =
  168. update_source_status("master_dj", false)
  169. end
  170. #auth function for live stream
  171. def check_master_dj_client(user,password) =
  172. log("master connected")
  173. #get the output of the php script
  174. ret = get_process_lines("python #{auth_path} --master #{user} #{password}")
  175. #ret has now the value of the live client (dj1,dj2, or djx), or "ERROR"/"unknown" ...
  176. ret = list.hd(ret)
  177. #return true to let the client transmit data, or false to tell harbor to decline
  178. ret == "True"
  179. end
  180. def check_dj_client(user,password) =
  181. log("live dj connected")
  182. #get the output of the php script
  183. ret = get_process_lines("python #{auth_path} --dj #{user} #{password}")
  184. #ret has now the value of the live client (dj1,dj2, or djx), or "ERROR"/"unknown" ...
  185. hd = list.hd(ret)
  186. log("Live DJ authenticated: #{hd}")
  187. hd == "True"
  188. end
  189. s = switch(id="schedule_noise_switch",
  190. track_sensitive=false,
  191. transitions=[transition_default, transition],
  192. [({!scheduled_play_enabled}, stream_queue), ({true}, default)]
  193. )
  194. s = if dj_live_stream_port != 0 and dj_live_stream_mp != "" then
  195. dj_live =
  196. audio_to_stereo(
  197. input.harbor(id="live_dj_harbor",
  198. dj_live_stream_mp,
  199. port=dj_live_stream_port,
  200. auth=check_dj_client,
  201. max=40.,
  202. on_connect=live_dj_connect,
  203. on_disconnect=live_dj_disconnect))
  204. ignore(output.dummy(dj_live, fallible=true))
  205. switch(id="show_schedule_noise_switch",
  206. track_sensitive=false,
  207. transitions=[transition, transition],
  208. [({!live_dj_enabled}, dj_live), ({true}, s)]
  209. )
  210. else
  211. s
  212. end
  213. s = if master_live_stream_port != 0 and master_live_stream_mp != "" then
  214. master_dj =
  215. audio_to_stereo(
  216. input.harbor(id="master_harbor",
  217. master_live_stream_mp,
  218. port=master_live_stream_port,
  219. auth=check_master_dj_client,
  220. max=40.,
  221. on_connect=master_dj_connect,
  222. on_disconnect=master_dj_disconnect))
  223. ignore(output.dummy(master_dj, fallible=true))
  224. switch(id="master_show_schedule_noise_switch",
  225. track_sensitive=false,
  226. transitions=[transition, transition],
  227. [({!master_dj_enabled}, master_dj), ({true}, s)]
  228. )
  229. else
  230. s
  231. end
  232. # Attach a skip command to the source s:
  233. #add_skip_command(s)
  234. server.register(namespace="streams",
  235. description="Stop Master DJ source.",
  236. usage="master_dj_stop",
  237. "master_dj_stop",
  238. fun (s) -> begin log("streams.master_dj_stop") make_master_dj_unavailable() "Done." end)
  239. server.register(namespace="streams",
  240. description="Start Master DJ source.",
  241. usage="master_dj_start",
  242. "master_dj_start",
  243. fun (s) -> begin log("streams.master_dj_start") make_master_dj_available() "Done." end)
  244. server.register(namespace="streams",
  245. description="Stop Live DJ source.",
  246. usage="live_dj_stop",
  247. "live_dj_stop",
  248. fun (s) -> begin log("streams.live_dj_stop") make_live_dj_unavailable() "Done." end)
  249. server.register(namespace="streams",
  250. description="Start Live DJ source.",
  251. usage="live_dj_start",
  252. "live_dj_start",
  253. fun (s) -> begin log("streams.live_dj_start") make_live_dj_available() "Done." end)
  254. server.register(namespace="streams",
  255. description="Stop Scheduled Play source.",
  256. usage="scheduled_play_stop",
  257. "scheduled_play_stop",
  258. fun (s) -> begin log("streams.scheduled_play_stop") make_scheduled_play_unavailable() "Done." end)
  259. server.register(namespace="streams",
  260. description="Start Scheduled Play source.",
  261. usage="scheduled_play_start",
  262. "scheduled_play_start",
  263. fun (s) -> begin log("streams.scheduled_play_start") make_scheduled_play_available() "Done." end)
  264. if output_sound_device then
  265. success = ref false
  266. log(output_sound_device_type)
  267. %ifdef output.alsa
  268. if output_sound_device_type == "ALSA" then
  269. ignore(output.alsa(s))
  270. success := true
  271. end
  272. %endif
  273. %ifdef output.ao
  274. if output_sound_device_type == "AO" then
  275. ignore(output.ao(s))
  276. success := true
  277. end
  278. %endif
  279. %ifdef output.oss
  280. if output_sound_device_type == "OSS" then
  281. ignore(output.oss(s))
  282. success := true
  283. end
  284. %endif
  285. %ifdef output.portaudio
  286. if output_sound_device_type == "Portaudio" then
  287. ignore(output.portaudio(s))
  288. success := true
  289. end
  290. %endif
  291. %ifdef output.pulseaudio
  292. if output_sound_device_type == "Pulseaudio" then
  293. ignore(output.pulseaudio(s))
  294. success := true
  295. end
  296. %endif
  297. if (!success == false) then
  298. ignore(output.prefered(s))
  299. end
  300. end
  301. if s1_enable == true then
  302. if s1_output == 'shoutcast' then
  303. s1_namespace := "shoutcast_stream_1"
  304. else
  305. s1_namespace := s1_mount
  306. end
  307. server.register(namespace=!s1_namespace, "connected", fun (s) -> begin log("#{!s1_namespace}.connected") !s1_connected end)
  308. output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass,
  309. s1_mount, s1_url, s1_description, s1_genre, s1_user, s, "1",
  310. s1_connected, s1_name, s1_channels)
  311. end
  312. if s2_enable == true then
  313. if s2_output == 'shoutcast' then
  314. s2_namespace := "shoutcast_stream_2"
  315. else
  316. s2_namespace := s2_mount
  317. end
  318. server.register(namespace=!s2_namespace, "connected", fun (s) -> begin log("#{!s2_namespace}.connected") !s2_connected end)
  319. output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass,
  320. s2_mount, s2_url, s2_description, s2_genre, s2_user, s, "2",
  321. s2_connected, s2_name, s2_channels)
  322. end
  323. if s3_enable == true then
  324. if s3_output == 'shoutcast' then
  325. s3_namespace := "shoutcast_stream_3"
  326. else
  327. s3_namespace := s3_mount
  328. end
  329. server.register(namespace=!s3_namespace, "connected", fun (s) -> begin log("#{!s3_namespace}.connected") !s3_connected end)
  330. output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass,
  331. s3_mount, s3_url, s3_name, s3_genre, s3_user, s, "3",
  332. s3_connected, s3_description, s3_channels)
  333. end
  334. command = "timeout --signal=KILL 45 pyponotify --liquidsoap-started &"
  335. log(command)
  336. system(command)