Add all HLS playlist items from player options

This commit is contained in:
Tibor Baksa 2022-11-22 21:22:09 +01:00
parent f81cadd6d1
commit 7a27725d6d
1 changed files with 17 additions and 9 deletions

View File

@ -21,29 +21,26 @@ function parse()
local playerOptionsJson = pageSource:match('pl.setup%( (%b{}) %);')
if playerOptionsJson then
log.dbg('Found player options json, finding playlist item of type hls')
log.dbg('Found player options json, finding playlist items of type hls')
local playerOptions = dkjson.decode(playerOptionsJson)
local playlistItem = tables.find(playerOptions.playlist, function(playlistItem)
local playlistItems = tables.filter(playerOptions.playlist, function(playlistItem)
return playlistItem.type == 'hls'
end)
if not playlistItem then
log.warn('Cannot find playlist item of type hls in player options json:', playerOptionsJson)
return nil
end
log.dbg('Number of playlist items:', #playlistItems)
local params = tables.map(tables.toMap(vlc.path:gmatch('[?&]([^=]+)=([^&]*)')), function(param)
return vlc.strings.decode_uri(param)
end)
return tables.map(playlistItems, function(playlistItem)
return {
{
path = vlc.access .. ':' .. playlistItem.file,
title = params.title,
arturl = params.bgimage
}
}
end)
end
log.dbg('Cannot find player options json, finding embedded players');
@ -138,3 +135,14 @@ function tables.map(values, transform)
end
return result
end
function tables.filter(values, predicate)
local result = {}
for key, value in pairs(values) do
if predicate(value, key, values) then
result[key] = value
end
end
return result
end