and_cesbo icon

Astra Script. Play a list of the files

and_cesbo | PRO | 12/01/15 05:57:11 AM UTC | 0 ⭐ | 783 👁️ | Never ⏰ | []
Lua |

2.24 KB

|

None

|

0 👍

/

0 👎

-- Astra Script
-- Play a list of the files (m3u or simple text file)
-- Address format: pls://path
-- path - full path to the playlist
-- Additional options:
-- loop - start from begining after the end of list
 
astra_storage["/mod.js"] = [[
make_url_format.pls = function(data, except) {
    var r = "pls://";
    if(data.addr) { r += data.addr; except.push("addr"); }
    return r;
};
]]
 
init_input_module.pls = function(config)
    local instance = transmit({ current = 0 })
 
    local f = io.open(config.addr)
    if not f then
        log.error("[" .. config.name .. "] playlist not found")
        return instance
    end
 
    local list = {}
    while true do
        local l = f:read()
        if not l then
            break
        end
 
        if l:find("^#") then
            --
        else
            table.insert(list, l)
        end
    end
    f:close()
 
    if #list == 0 then
        log.error("[" .. config.name .. "] empty playlist")
        return instance
    end
 
    local function playnext()
        local current = instance.__options.current + 1
        if current > #list then
            instance.__options.current = 0
            if config.loop then
                playnext()
                return nil
            else
                instance.__options.input = nil
                instance.__options.tail = transmit({})
                log.info("[" .. config.name .. "] end of playlist")
            end
        else
            instance.__options.current = current
            instance.__options.input = file_input({
                filename = list[current],
                callback = playnext
            })
            instance.__options.tail = channel({
                upstream = instance.__options.input:stream(),
                name = config.name,
                pnr = 0,
                set_pnr = 1,
                map = { {"pmt",100}, {"video",101}, {"audio",102} }
            })
        end
        instance:set_upstream(instance.__options.tail:stream())
    end
 
    playnext()
 
    return instance
end
 
kill_input_module.pls = function(instance)
    instance.__options.current = nil
    instance.__options.input = nil
    instance.__options.tail = nil
end

Comments