From 7a27725d6dc19dddc9ebf5eb453ff5bf6b572dac Mon Sep 17 00:00:00 2001 From: Tibor Baksa Date: Tue, 22 Nov 2022 21:22:09 +0100 Subject: [PATCH] Add all HLS playlist items from player options --- mediaklikk-video.lua | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/mediaklikk-video.lua b/mediaklikk-video.lua index 72dd6d4..d59e688 100644 --- a/mediaklikk-video.lua +++ b/mediaklikk-video.lua @@ -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 { - { + 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