Advertisement
Guest User

Untitled

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