set("log.file.path","/home/liquidsoap/liquid.log");
set("log.level",2);
#set("server.telnet",true);
#set("server.telnet.port", 6666);
#harbor live settings
set("harbor.bind_addr","0.0.0.0");
set("harbor.port",8900);
set("harbor.password","xxxxxxx");
#set("scheduler.generic_queues",4);
#set("scheduler.non_blocking_queues",4);
#set("scheduler.fast_queues",4);
set("scheduler.log",true);

# livepoint in override alla playlist
livepointit = input.harbor("livecasting-it");
livepointen = input.harbor("livecasting-en");
# live della regia con silence threshold 
#regiregi = input.harbor("livefromregia");
regiregi = input.http("http://127.0.0.1:8000/livefromregia");

# questo viene attivato con prioritÃ  solo quando il segnale non Ã¨ silenzioso
# vedi thresshold e lunghezza del silenzio in secondi
trxregia = strip_blank(threshold=-35.,length=15.,regiregi);
#trxregia = input.harbor("liveregia");

# main playlist...ogni playlist Ã¨ rigenerata con cronjobs
defplay = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/playlist.m3u"));
# jingle playlist
jingleplay = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/jingle.m3u"));

mainjingle = single("/home/ftp/radiolina/jingle/Jingle_RadioLina_01.mp3");

# fasce musicali 
elettronica = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/elettronica.m3u"));
jazz = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/jazz.m3u"));
reggae = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/reggae.m3u"));
ska_rocksteady = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/ska_rocksteady.m3u"));
sud_america = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/sud_america.m3u"));
trx = mksafe(playlist(mode = "randomize", reload = 3600, reload_mode = "rounds", "/home/liquidsoap/liste/trx.m3u"));

# la playlist jingle Ã¨ pronta ogni 5 minuti
jingle_timed = delay(300.,jingleplay);
# i jingle vanno in tutte le fasce musicali 
elettronica = fallback([jingle_timed, elettronica]);
jazz = fallback([jingle_timed, jazz]);
reggae = fallback([jingle_timed, reggae]);
ska_rocksteady = fallback([jingle_timed, ska_rocksteady]);
sud_america = fallback([jingle_timed, sud_america]);
trx = fallback([jingle_timed, trx]);

# fallback on the first ready child
final_list = fallback([jingle_timed,defplay]);

final_list = crossfade(start_next = 2., fade_in = 2., fade_out = 2., final_list);

#Â would really like to understand how to declare overnight
# (crossing midnight) transmissions (e porcoddio)
palinsesto = switch(track_sensitive=false,
			[ ( { (0w or 1w or 2w or 3w or 4w or 5w or 6w) and 08h00m-11h00m }, trx),
			  ( { (0w or 1w or 2w or 3w or 5w or 6w) and 20h00m-22h00m }, reggae),
			  ( { (0w or 1w or 2w or 3w or 4w or 5w or 6w) and 23h00m-01h30m }, trx),
			  ( { (4w) and 20h30m-23h30m }, sud_america),
			  ( { (4w) and 23h30m-06h30m }, jazz),
			  ( { true }, final_list ),
				
			]);
radiolist = fallback(track_sensitive=false,[trxregia,palinsesto]);
#radiolist = fallback(track_sensitive=false,[trxregia,livepointit,palinsesto]);
#radioen = fallback(track_sensitive=false,[livepointen,palinsesto]);

# outputs
radiout = output.icecast.mp3(restart=true,password="xxxxxxxxxxxx",
	host="sources.stream.teknusi.org",port=8000,
	mount="radiolina",url="http://www.radiolina.info",
	bitrate=56,samplerate=44100,description="RadioLina WebRadio capestre",
	radiolist);

#radiouten = output.icecast.mp3(restart=true,password="xxxxxxxxxx",
#	host="sources.stream.teknusi.org",port=8000,
#	mount="radiolina-en",url="http://www.radiolina.info",
#	bitrate=56,samplerate=44100,description="RadioLina WebRadio capestre",
#	radioen);

#vorbisout = output.icecast.vorbis(restart=true,password="xxxxxx",
#	host="sources.stream.teknusi.org", port=8000,
#	mount="radiolina.ogg",url="http://www.radiolina.info",
#	quality=0.5,samplerate=44100, description="RadioLina WebRadio capestre",
#	radiolist);

add([final_list,
	switch([
		({0m0s}, mainjingle)
	])
]);