Advertisement
Guest User

Untitled

a guest
Oct 30th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 4.77 KB | None | 0 0
  1. #!/usr/local/bin/liquidsoap
  2.  
  3. pathToSocket="/home/radio/musicas/sckt";
  4. set("server.socket",true); #use a socket
  5. set("server.socket.path",pathToSocket); #the path to a socket
  6. set("server.socket.permissions",511) #the permission for the file, here is the equivalent to 777 .Ideally you would use a more restrictive permission
  7.  
  8.  
  9. set("harbor.bind_addr","0.0.0.0")
  10. set("server.telnet", true)
  11.  
  12. ###########################################################
  13. ###########################################################
  14.  
  15. # First, we create a list referencing the dynamic sources:
  16. dyn_sources = ref []
  17.  
  18. # This is our icecast output.
  19. # It is a partial application: the source needs to be given!
  20. out = output.icecast(%mp3(bitrate=64, samplerate=44100, id3v2=true, stereo=false),
  21.    host = "localhost",
  22.    port = 8085,
  23.    password = "_____",
  24.    mount = "pgplaylist",
  25.    fallible = true)
  26.  
  27.    
  28.    
  29. # Now we write a function to create
  30. # a playlist source and output it.
  31. def create_playlist(uri) =
  32.   # The playlist source
  33.   s = mean(playlist.once(uri))
  34.  
  35.   # The output
  36.   output = out(s)
  37.  
  38.   # We register both source and output
  39.   # in the list of sources
  40.   dyn_sources :=
  41.       list.append( [(uri,s),(uri,output)],
  42.                     !dyn_sources )
  43.   "Done!"
  44. end
  45.  
  46. # And a function to destroy a dynamic source
  47. def destroy_playlist(uri) =
  48.   # We need to find the source in the list,
  49.   # remove it and destroy it. Currently, the language
  50.   # lacks some nice operators for that so we do it
  51.   # the functional way
  52.  
  53.   # This function is executed on every item in the list
  54.   # of dynamic sources
  55.   def parse_list(ret, current_element) =
  56.     # ret is of the form: (matching_sources, remaining_sources)
  57.     # We extract those two:
  58.     matching_sources = fst(ret)
  59.     remaining_sources = snd(ret)
  60.  
  61.     # current_element is of the form: ("uri", source) so
  62.     # we check the first element
  63.     current_uri = fst(current_element)
  64.     if current_uri == uri then
  65.       # In this case, we add the source to the list of
  66.       # matched sources
  67.       (list.append( [snd(current_element)],
  68.                      matching_sources),
  69.        remaining_sources)
  70.     else
  71.       # In this case, we put the element in the list of remaining
  72.       # sources
  73.       (matching_sources,
  74.        list.append([current_element],
  75.                     remaining_sources))
  76.     end
  77.   end
  78.    
  79.   # Now we execute the function:
  80.   result = list.fold(parse_list, ([], []), !dyn_sources)
  81.   matching_sources = fst(result)
  82.   remaining_sources = snd(result)
  83.  
  84.   # We store the remaining sources in dyn_sources
  85.   dyn_sources := remaining_sources
  86.  
  87.   # If no source matched, we return an error
  88.   if list.length(matching_sources) == 0 then
  89.     "Error: no matching sources!"
  90.   else
  91.     # We stop all sources
  92.     list.iter(source.shutdown, matching_sources)
  93.     # And return
  94.     "Done!"
  95.   end
  96. end
  97.  
  98.  
  99. # Now we register the telnet commands:
  100. server.register(namespace="dynamic_playlist",
  101.                 description="Start a new dynamic playlist.",
  102.                 usage="start <uri>",
  103.                 "start",
  104.                 create_playlist)
  105. server.register(namespace="dynamic_playlist",
  106.                 description="Stop a dynamic playlist.",
  107.                 usage="stop <uri>",
  108.                 "stop",
  109.                 destroy_playlist)
  110.  
  111. ###########################################################
  112. ###########################################################
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. # Some code...
  123.  
  124. vinhetas = mean(mksafe(playlist("/home/radio/vinhetas/vinhetas.txt")))
  125. musicas = mean(mksafe(playlist(mode="normal", "/home/radio/musicas/playlist.txt")))
  126.  
  127. files = rotate(weights=[1,7], [vinhetas, musicas])
  128.  
  129.  
  130. # This defines a source waiting on mount point
  131. # /test-harbor
  132. live = input.harbor("/",port=8080,password="_____",icy=true)
  133. pgplaylist = input.harbor("pgplaylist",port=8085,password="_____")
  134.  
  135. # This is the final stream.
  136. # Uses the live source as soon as available,
  137. # and don't wait for an end of track, since
  138. # we don't want to cut the beginning of the live
  139. # stream.
  140. #
  141. # You may insert a jingle transition here...
  142. radio = fallback(track_sensitive=false,
  143.                  [live,pgplaylist,files])
  144.  
  145.  
  146. # A function applied to each metadata chunk
  147. def append_title(m) =
  148.   # Grab the current title
  149.   title = m["title"]
  150.  
  151.   # Return a new title metadata
  152.   [("title","#{title} - #RadioCollegeRock (em testes)")]
  153. end
  154.  
  155. # Apply map_metadata to s using append_title
  156. #radio = map_metadata(append_title, radio)
  157.  
  158. output.icecast(%mp3(bitrate=64, samplerate=44100, id3v2=true, stereo=false),
  159.    host = "localhost",
  160.    port = 8000,
  161.    password = "_____",
  162.    icy_metadata = "true",
  163.    url = "http://facebook.com/teucollegerock",
  164.    description = "#RadioCollegeRock (em testes)",
  165.    mount = "radiocollegerock.mp3", radio)
  166.  
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement