and_cesbo

Astra Script. Play a list of the files

Dec 1st, 2015
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. -- Astra Script
  2. -- Play a list of the files (m3u or simple text file)
  3. -- Address format: pls://path
  4. -- path - full path to the playlist
  5. -- Additional options:
  6. -- loop - start from begining after the end of list
  7.  
  8. astra_storage["/mod.js"] = [[
  9. make_url_format.pls = function(data, except) {
  10.     var r = "pls://";
  11.     if(data.addr) { r += data.addr; except.push("addr"); }
  12.     return r;
  13. };
  14. ]]
  15.  
  16. init_input_module.pls = function(config)
  17.     local instance = transmit({ current = 0 })
  18.  
  19.     local f = io.open(config.addr)
  20.     if not f then
  21.         log.error("[" .. config.name .. "] playlist not found")
  22.         return instance
  23.     end
  24.  
  25.     local list = {}
  26.     while true do
  27.         local l = f:read()
  28.         if not l then
  29.             break
  30.         end
  31.  
  32.         if l:find("^#") then
  33.             --
  34.         else
  35.             table.insert(list, l)
  36.         end
  37.     end
  38.     f:close()
  39.  
  40.     if #list == 0 then
  41.         log.error("[" .. config.name .. "] empty playlist")
  42.         return instance
  43.     end
  44.  
  45.     local function playnext()
  46.         local current = instance.__options.current + 1
  47.         if current > #list then
  48.             instance.__options.current = 0
  49.             if config.loop then
  50.                 playnext()
  51.                 return nil
  52.             else
  53.                 instance.__options.input = nil
  54.                 instance.__options.tail = transmit({})
  55.                 log.info("[" .. config.name .. "] end of playlist")
  56.             end
  57.         else
  58.             instance.__options.current = current
  59.             instance.__options.input = file_input({
  60.                 filename = list[current],
  61.                 callback = playnext
  62.             })
  63.             instance.__options.tail = channel({
  64.                 upstream = instance.__options.input:stream(),
  65.                 name = config.name,
  66.                 pnr = 0,
  67.                 set_pnr = 1,
  68.                 map = { {"pmt",100}, {"video",101}, {"audio",102} }
  69.             })
  70.         end
  71.         instance:set_upstream(instance.__options.tail:stream())
  72.     end
  73.  
  74.     playnext()
  75.  
  76.     return instance
  77. end
  78.  
  79. kill_input_module.pls = function(instance)
  80.     instance.__options.current = nil
  81.     instance.__options.input = nil
  82.     instance.__options.tail = nil
  83. end
Advertisement
Add Comment
Please, Sign In to add comment