2018-09-10 23:55:10 +02:00
|
|
|
local dkjson = require('dkjson')
|
|
|
|
local log = {}
|
|
|
|
local openGraph = {}
|
|
|
|
local streams = {}
|
|
|
|
local tables = {}
|
|
|
|
|
|
|
|
local urlPatterns = {
|
|
|
|
'hirado%.hu',
|
|
|
|
'm4sport%.hu',
|
|
|
|
'mediaklikk%.hu'
|
2017-09-09 17:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function probe()
|
2022-11-22 20:52:20 +01:00
|
|
|
return vlc.access:match('https?') and tables.find(urlPatterns, function(pattern)
|
|
|
|
return vlc.path:match(pattern)
|
|
|
|
end)
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function parse()
|
|
|
|
local pageSource = streams.readAll(vlc)
|
2022-11-22 20:52:20 +01:00
|
|
|
|
|
|
|
local playerOptionsJson = pageSource:match('pl.setup%( (%b{}) %);')
|
|
|
|
if playerOptionsJson then
|
2022-11-22 21:22:09 +01:00
|
|
|
log.dbg('Found player options json, finding playlist items of type hls')
|
2022-11-22 20:52:20 +01:00
|
|
|
|
|
|
|
local playerOptions = dkjson.decode(playerOptionsJson)
|
2022-11-22 21:22:09 +01:00
|
|
|
local playlistItems = tables.filter(playerOptions.playlist, function(playlistItem)
|
2022-11-22 20:52:20 +01:00
|
|
|
return playlistItem.type == 'hls'
|
|
|
|
end)
|
|
|
|
|
2022-11-22 21:22:09 +01:00
|
|
|
log.dbg('Number of playlist items:', #playlistItems)
|
2022-11-22 20:52:20 +01:00
|
|
|
|
|
|
|
local params = tables.map(tables.toMap(vlc.path:gmatch('[?&]([^=]+)=([^&]*)')), function(param)
|
|
|
|
return vlc.strings.decode_uri(param)
|
|
|
|
end)
|
|
|
|
|
2022-11-22 21:22:09 +01:00
|
|
|
return tables.map(playlistItems, function(playlistItem)
|
|
|
|
return {
|
2022-11-22 20:52:20 +01:00
|
|
|
path = vlc.access .. ':' .. playlistItem.file,
|
|
|
|
title = params.title,
|
|
|
|
arturl = params.bgimage
|
|
|
|
}
|
2022-11-22 21:22:09 +01:00
|
|
|
end)
|
2022-11-22 20:52:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
log.dbg('Cannot find player options json, finding embedded players');
|
|
|
|
|
|
|
|
local playerSetupJsons = tables.toArray(pageSource:gmatch('mtva_player_manager%.player%(document%.getElementById%("player_%d+_%d+"%), (%b{})%);'));
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
log.dbg('Number of players:', #playerSetupJsons)
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
return tables.map(playerSetupJsons, function(playerSetupJson)
|
|
|
|
local playerSetup = dkjson.decode(playerSetupJson)
|
|
|
|
local video = playerSetup.streamId or playerSetup.token
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
if not video then
|
|
|
|
log.warn('Cannot find either streamId or token in player setup json:', playerSetupJson)
|
|
|
|
return nil
|
2017-09-10 01:12:14 +02:00
|
|
|
end
|
|
|
|
|
2022-11-22 20:52:20 +01:00
|
|
|
local title = playerSetup.title or openGraph.property(pageSource, 'title')
|
|
|
|
local arturl = (playerSetup.bgImage and vlc.access .. ':' .. playerSetup.bgImage) or openGraph.property(pageSource, 'image')
|
|
|
|
local playerUrl = vlc.access .. '://player.mediaklikk.hu/playernew/player.php?video=' .. video ..
|
|
|
|
((title and '&title=' .. vlc.strings.encode_uri_component(title)) or '') ..
|
|
|
|
((arturl and '&bgimage=' .. vlc.strings.encode_uri_component(arturl)) or '')
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
log.dbg('Loading player:', playerUrl)
|
2017-09-10 01:12:14 +02:00
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
return {
|
2022-11-22 20:52:20 +01:00
|
|
|
path = playerUrl,
|
|
|
|
title = title,
|
|
|
|
arturl = arturl,
|
|
|
|
options = {
|
|
|
|
'http-referrer=' .. vlc.access .. '://' .. vlc.path
|
|
|
|
}
|
2018-09-10 23:55:10 +02:00
|
|
|
}
|
|
|
|
end)
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
local function logger(vlcLog)
|
|
|
|
return function(...)
|
|
|
|
vlcLog(table.concat({'mediaklikk-video:', ...}, ' '))
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
log.dbg = logger(vlc.msg.dbg)
|
|
|
|
log.warn = logger(vlc.msg.warn)
|
|
|
|
log.err = logger(vlc.msg.err)
|
|
|
|
log.info = logger(vlc.msg.info)
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
function openGraph.property(source, property)
|
|
|
|
return source:match('<meta property="og:' .. property .. '" content="(.-)"/>')
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
function streams.readAll(s)
|
|
|
|
local function iterator(size)
|
|
|
|
if s == vlc then
|
|
|
|
return s.read(size)
|
|
|
|
else
|
|
|
|
return s:read(size)
|
|
|
|
end
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
2017-09-10 01:12:14 +02:00
|
|
|
|
2022-11-22 20:52:20 +01:00
|
|
|
return table.concat(tables.toArray(iterator, 1024, nil));
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
function tables.find(values, predicate)
|
|
|
|
for key, value in pairs(values) do
|
|
|
|
if predicate(value, key, values) then
|
|
|
|
return value, key
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
|
|
|
end
|
2018-09-10 23:55:10 +02:00
|
|
|
end
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2022-11-22 20:52:20 +01:00
|
|
|
function tables.toArray(iterator, state, initialValue)
|
2018-09-10 23:55:10 +02:00
|
|
|
local result = {}
|
|
|
|
for value in iterator, state, initialValue do
|
|
|
|
table.insert(result, value)
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
2018-09-10 23:55:10 +02:00
|
|
|
return result
|
|
|
|
end
|
2017-09-09 17:22:14 +02:00
|
|
|
|
2022-11-22 20:52:20 +01:00
|
|
|
function tables.toMap(iterator, state, initialValue)
|
|
|
|
local result = {}
|
|
|
|
for key, value in iterator, state, initialValue do
|
|
|
|
result[key] = value
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2018-09-10 23:55:10 +02:00
|
|
|
function tables.map(values, transform)
|
|
|
|
local result = {}
|
|
|
|
for key, value in pairs(values) do
|
|
|
|
result[key] = transform(value, key, values)
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
2018-09-10 23:55:10 +02:00
|
|
|
return result
|
2017-09-09 17:22:14 +02:00
|
|
|
end
|
2022-11-22 21:22:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|