and_cesbo

Astra: play files

Mar 1st, 2015
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. source_path = "/home/iptv/xxx"
  2. output_addr = "192.168.0.11"
  3. output_port = 8806
  4.  
  5. playlist = {}
  6. current_item = 0
  7.  
  8. for d in utils.readdir(source_path) do
  9.     table.insert(playlist, d)
  10. end
  11.  
  12. channel_data = {}
  13. channel_data.input = nil
  14. channel_data.transmit = transmit()
  15.  
  16. function on_http_read(self, client, request)
  17.     if not request then
  18.         return nil
  19.     end
  20.  
  21.     local client_data = self:data(client)
  22.     self:send(client, channel_data.transmit:stream())
  23. end
  24.  
  25. channel_data.output = http_server({
  26.     addr = output_addr,
  27.     port = output_port,
  28.     route = {
  29.         { "/xxx", http_upstream({ callback = on_http_read, }) },
  30.     },
  31. })
  32.  
  33. function play_item()
  34.     current_item = current_item + 1
  35.     if current_item > #playlist then
  36.         log.info("End of playlist")
  37.         astra.exit()
  38.     end
  39.  
  40.     log.debug("Play: " .. playlist[current_item])
  41.  
  42.     if channel_data.input then
  43.         kill_input(channel_data.input)
  44.         channel_data.input = nil
  45.     end
  46.     local source_file = playlist[current_item]
  47.     local channel_conf = {
  48.         name = source_file,
  49.         format = "file",
  50.         filename = source_path .. "/" .. source_file,
  51.         on_error = function() play_item() end,
  52.         map = { { "pmt", "100" }, { "video", "101" }, { "audio", "102" }, },
  53.         set_pnr = 100,
  54.     }
  55.     channel_data.input = init_input(channel_conf)
  56.  
  57.     channel_data.transmit:set_upstream(channel_data.input.tail:stream())
  58. end
  59.  
  60. play_item()
Advertisement
Add Comment
Please, Sign In to add comment