Create separate playlist item for player URL and send referrer
This commit is contained in:
parent
8b6793c6a7
commit
f81cadd6d1
|
@ -11,16 +11,44 @@ local urlPatterns = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function probe()
|
function probe()
|
||||||
return vlc.access:match('https?')
|
return vlc.access:match('https?') and tables.find(urlPatterns, function(pattern)
|
||||||
and tables.find(urlPatterns, function(pattern)
|
return vlc.path:match(pattern)
|
||||||
return vlc.path:match(pattern)
|
end)
|
||||||
end)
|
|
||||||
and not vlc.path:match('player%.mediaklikk%.hu')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function parse()
|
function parse()
|
||||||
local pageSource = streams.readAll(vlc)
|
local pageSource = streams.readAll(vlc)
|
||||||
local playerSetupJsons = tables.collect(pageSource:gmatch('mtva_player_manager%.player%(document%.getElementById%("player_%d+_%d+"%), (%b{})%);'));
|
|
||||||
|
local playerOptionsJson = pageSource:match('pl.setup%( (%b{}) %);')
|
||||||
|
if playerOptionsJson then
|
||||||
|
log.dbg('Found player options json, finding playlist item of type hls')
|
||||||
|
|
||||||
|
local playerOptions = dkjson.decode(playerOptionsJson)
|
||||||
|
local playlistItem = tables.find(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
|
||||||
|
|
||||||
|
local params = tables.map(tables.toMap(vlc.path:gmatch('[?&]([^=]+)=([^&]*)')), function(param)
|
||||||
|
return vlc.strings.decode_uri(param)
|
||||||
|
end)
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
path = vlc.access .. ':' .. playlistItem.file,
|
||||||
|
title = params.title,
|
||||||
|
arturl = params.bgimage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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{})%);'));
|
||||||
|
|
||||||
log.dbg('Number of players:', #playerSetupJsons)
|
log.dbg('Number of players:', #playerSetupJsons)
|
||||||
|
|
||||||
|
@ -33,27 +61,21 @@ function parse()
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local playerUrl = vlc.access .. '://player.mediaklikk.hu/playernew/player.php?video=' .. video
|
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 '')
|
||||||
|
|
||||||
log.dbg('Loading player:', playerUrl)
|
log.dbg('Loading player:', playerUrl)
|
||||||
|
|
||||||
local playerSource = streams.readAll(vlc.stream(playerUrl))
|
|
||||||
local playerOptionsJson = playerSource:match('pl.setup%( (%b{}) %);')
|
|
||||||
local playerOptions = dkjson.decode(playerOptionsJson)
|
|
||||||
local playlistItem = tables.find(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
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path = vlc.access .. ':' .. playlistItem.file,
|
path = playerUrl,
|
||||||
title = playerSetup.title or openGraph.property(pageSource, 'title'),
|
title = title,
|
||||||
description = openGraph.property(pageSource, 'description'),
|
arturl = arturl,
|
||||||
arturl = (playerSetup.bgImage and vlc.access .. ':' .. playerSetup.bgImage) or openGraph.property(pageSource, 'image')
|
options = {
|
||||||
|
'http-referrer=' .. vlc.access .. '://' .. vlc.path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -82,7 +104,7 @@ function streams.readAll(s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(tables.collect(iterator, 1024, nil));
|
return table.concat(tables.toArray(iterator, 1024, nil));
|
||||||
end
|
end
|
||||||
|
|
||||||
function tables.find(values, predicate)
|
function tables.find(values, predicate)
|
||||||
|
@ -93,7 +115,7 @@ function tables.find(values, predicate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function tables.collect(iterator, state, initialValue)
|
function tables.toArray(iterator, state, initialValue)
|
||||||
local result = {}
|
local result = {}
|
||||||
for value in iterator, state, initialValue do
|
for value in iterator, state, initialValue do
|
||||||
table.insert(result, value)
|
table.insert(result, value)
|
||||||
|
@ -101,6 +123,14 @@ function tables.collect(iterator, state, initialValue)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function tables.toMap(iterator, state, initialValue)
|
||||||
|
local result = {}
|
||||||
|
for key, value in iterator, state, initialValue do
|
||||||
|
result[key] = value
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
function tables.map(values, transform)
|
function tables.map(values, transform)
|
||||||
local result = {}
|
local result = {}
|
||||||
for key, value in pairs(values) do
|
for key, value in pairs(values) do
|
||||||
|
|
Loading…
Reference in New Issue