1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# berndsdomain.org -*- Tuareg -*- vim: ft=ocaml
#
# This Liquidsoap file controls the playlists and output for polemon.org
#   - written by Bernd
#
# Tree:
#
# jingles  pl
#    |     | 
#   2 \___/ 3
#       |
#     auto (switch)
#       |
#   crossfade
#       |    
#       |
#       |     input.harbor ("/dj.ogg")
#       |       |
#       |       |     input.harbor ("/")
#       |       |b      |
#      c \______|______/ a
#            |
#          full (fallback, where 1.a, 2.b, and transition)
#            |
#            |- mksafe
#            |- clear_metadata
#            |- insert_metadata (node for telnet)
#           /|\
#          / | \
#         /  |  \
#        /   | output.icecast.mp3 (128kbps)
#       /    |
#      /   output.icecast.ogg (Q = 3)
#     /
#   output.icecast.ogg (Q = -1) 
#
#
# This file is under public domain
#

# Run external command to check if source has permission to stream
def checkpass(user, pass)
  test_process("checkpass.sh " ^ quote(user) ^ " " ^ quote(pass)) 
end

# Functions to write logs
def conn()
  ignore(test_process("wlog connect"))
end

def disconn()
  ignore(test_process("wlog disconnect"))
end

# Simple transition with 3 sec overlap.
# Source a is faded to silence, without waiting for the track to end.
def cfade(a, b)
  add(normalize = false, [ fade.initial(duration = 1., b),
			   fade.final(duration = 1., a) ])
end

def highaacenc(_) = "aacplusenc - - 64" end
def lowaacenc(_) = "aacplusenc - - 16" end

# Log file
set( "log.file.path",
     "/usr/local/var/log/liquidsoap/gnihihi.log" )

# Log to stdout, discarded when daemonized
set("log.stdout", true)

# Log all info available
set("log.level", 5)

# Log scheduler
set("scheduler.log", false)

# Telnet server on 1234
set("server.telnet", true)

# harbor input settings
set("harbor.bind_addr", "0.0.0.0")
set("harbor.port", 4010)
set("harbor.icy", true)
#set("harbor.password", "FICK NEIN")

# Jingles playlist
#jingles = mksafe(playlist( reload_mode = "seconds",
#			   reload = 60,
#			   "~liquidsoap/jingles.lst" ))

# Main playlist
pl = mksafe(playlist( reload_mode = "seconds",
		      reload = 60,
		      "~liquidsoap/playlist.lst" ))

# Live mountpoints (supports both, ICY and HTTP)
root = input.harbor( auth = checkpass, 
		     on_connect = conn,
		     on_disconnect = disconn,
		     "/" )

ogg = input.harbor( auth = checkpass, 
		    on_connect = conn,
		    on_disconnect = disconn,
		    "/dj.ogg" )

# Played hourly
# clock = single("file.mp3")

# merging jingles with music
#auto = random( weights = [2, 3],
#	       [jingles, pl] )
auto = pl

# Hourly file
# REPLACE WITH add()
#auto = add([ 
#      	      auto,
#      	      switch([( 
#		        {0m0s},
#		       	clock
#		      )])
#	    ])

# crossfading for playlist
auto = crossfade( start_next = 0.25,
		  fade_out = 0.5,
		  fade_in = 0.5,
		  auto )

# switching to DJ mountpoint with fading
full = fallback( track_sensitive = false,
		 transitions = [ cfade, cfade, cfade ],
		 [root, ogg, auto] )

# clearing metadata
full = clear_metadata(full)

# metadata node to make updates from telnet possible
full = insert_metadata( id = "meta_full", 
			full )

# MP3 output (128kbps)
output.icecast.mp3( host = "localhost",
                    port = 4000,
                    password = "O_o",
                    mount = "high.mp3",
                    bitrate = 128,
                    full )

# Ogg/Vorbis output (Q=3)
output.icecast.vorbis( host = "localhost",
		       port = 4000,
		       password = "ARGHHGHGH",
		       mount = "high.ogg",
		       quality = 3.,
		       full )

# Ogg/Vorbis output (Q=-1)
output.icecast.vorbis( host = "localhost",
		       port = 4000,
		       password = "DU W√úNSCHTEST?!",
		       mount = "low.ogg",
		       quality = -1.,
		       full )

# AAC+ output (64kbs CBR)
output.icecast.external( restart = true,
                         restart_on_crash = true,
                         process = highaacenc,
                         host = "localhost",
                         port = 4000,
                         password = "HAHA, ALS OB",
                         mount = "high.aac",
                         header = true,
                         shout_raw = true,
                         mime =  "audio/aacp",
                         bitrate = 64,
                         full )

# AAC+ output (16kbs CBR)
output.icecast.external( restart = true,
                         restart_on_crash = true,
                         process = lowaacenc,
                         host = "localhost",
                         port = 4000,
                         password = "NEIN DU",
                         mount = "low.aac",
                         header = true,
                         shout_raw = true,
                         mime =  "audio/aacp",
                         bitrate = 16,
                         full )

# clipinc metadata stream
clipinc = blank()
clipinc = insert_metadata( id = "meta_clipinc",
			   clipinc )

# mountpoiunt for secodary data
output.icecast.mp3( host = "localhost",
		    port = 4000,
		    password = "NEIN DU",
		    mount = "clipinc.mp3",
		    bitrate = 128,
		    clipinc )

#playlists = [pl, jingles]
playlists = [pl]

#sources = [root, ogg]

def global_skip(_) = list.iter(source.skip, playlists) "Done !" end

#def kickall(_) = list.iter(harbor.stop, sources) "Done !" end

def get_ip(_)
    lines = get_process_lines("get_ip")
    if list.length(lines) > 0 then
	list.hd(lines)
    else
	"no source client connected"
    end    
end

#server.register( namespace = "",
#		 usage = "kick",
#		 description = "perform kick on all live sources",
#		 "kick",
#		 kickall ) 

server.register( namespace = "",
		 usage = "gskip",
		 description = "Perform a skip on all sources",                
		 "gskip",
		 global_skip )

server.register( namespace = "",
		 usage = "getip",
		 description = "Get IP from connected harbor",                
		 "getip",
		 get_ip )