Compare commits
No commits in common. "master" and "v1.1.0" have entirely different histories.
11
README.md
11
README.md
|
@ -1,4 +1,4 @@
|
||||||
# vlc-mediaklikk-video
|
# vlc-mediaklikk
|
||||||
VLC playlist parser for MédiaKlikk videos and video streams
|
VLC playlist parser for MédiaKlikk videos and video streams
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
@ -22,14 +22,11 @@ Copy [mediaklikk-video.lua](mediaklikk-video.lua) to [VLC Lua playlist scripts](
|
||||||
* [mediaklikk.hu](https://www.mediaklikk.hu/)
|
* [mediaklikk.hu](https://www.mediaklikk.hu/)
|
||||||
|
|
||||||
### Video streams
|
### Video streams
|
||||||
* [M1](https://hirado.hu/elo/m1)
|
* [M1](https://www.mediaklikk.hu/m1-elo)
|
||||||
* [M2](https://www.mediaklikk.hu/m2-elo)
|
* [M2](https://www.mediaklikk.hu/m2-elo)
|
||||||
* [M4 Sport](https://m4sport.hu/elo/mtv4live)
|
* [M4](https://www.mediaklikk.hu/m4-elo)
|
||||||
* [M4 Sport +](https://m4sport.hu/elo/mtv4plus)
|
|
||||||
* [M5](https://www.mediaklikk.hu/m5-elo)
|
* [M5](https://www.mediaklikk.hu/m5-elo)
|
||||||
* [Duna](https://www.mediaklikk.hu/duna-elo)
|
* [Duna](https://www.mediaklikk.hu/duna-elo)
|
||||||
* [Duna World](https://www.mediaklikk.hu/duna-world-elo)
|
* [Duna World](https://www.mediaklikk.hu/duna-world-elo)
|
||||||
|
|
||||||
## On addons.videolan.org
|
Video streams require VLC 3.0+ (currently available from [nightly builds](https://nightlies.videolan.org/)).
|
||||||
|
|
||||||
This playlist parser is also [available on addons.videolan.org](https://addons.videolan.org/p/1190582/).
|
|
||||||
|
|
|
@ -1,155 +1,202 @@
|
||||||
local dkjson = require('dkjson')
|
local tables
|
||||||
local log = {}
|
local streams
|
||||||
local openGraph = {}
|
local urls
|
||||||
local streams = {}
|
local log
|
||||||
local tables = {}
|
|
||||||
|
|
||||||
local urlPatterns = {
|
local function noPlaylist(reason)
|
||||||
'hirado%.hu',
|
log.err('Failed to create playlist:', reason)
|
||||||
'm4sport%.hu',
|
return {}
|
||||||
'mediaklikk%.hu'
|
end
|
||||||
|
|
||||||
|
local Object = {}
|
||||||
|
|
||||||
|
function Object:new(overrides)
|
||||||
|
return setmetatable(overrides or {}, {__index = self})
|
||||||
|
end
|
||||||
|
|
||||||
|
local Parser = Object:new()
|
||||||
|
local VideoParser = Parser:new()
|
||||||
|
local LiveStreamParser = Parser:new()
|
||||||
|
|
||||||
|
local parsers = {
|
||||||
|
VideoParser:new{urlPattern = 'hirado%.hu/'},
|
||||||
|
VideoParser:new{urlPattern = 'm4sport%.hu/'},
|
||||||
|
VideoParser:new{urlPattern = 'mediaklikk%.hu/'},
|
||||||
|
LiveStreamParser:new{urlPattern = 'mediaklikk%.hu/m1%-elo'},
|
||||||
|
LiveStreamParser:new{urlPattern = 'mediaklikk%.hu/m2%-elo'},
|
||||||
|
LiveStreamParser:new{urlPattern = 'mediaklikk%.hu/m4%-elo'},
|
||||||
|
LiveStreamParser:new{urlPattern = 'mediaklikk%.hu/m5%-elo'},
|
||||||
|
LiveStreamParser:new{urlPattern = 'mediaklikk%.hu/duna%-elo'},
|
||||||
|
LiveStreamParser:new{urlPattern = 'mediaklikk%.hu/duna%-world%-elo'}
|
||||||
}
|
}
|
||||||
|
|
||||||
function probe()
|
function probe()
|
||||||
return vlc.access:match('https?') and tables.find(urlPatterns, function(pattern)
|
return tables.some(Parser.probe, parsers)
|
||||||
return vlc.path:match(pattern)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function parse()
|
function parse()
|
||||||
|
local parser = tables.find(Parser.probe, parsers)
|
||||||
|
if not parser then
|
||||||
|
return noPlaylist('could not find Parser')
|
||||||
|
end
|
||||||
|
|
||||||
|
return parser:parse()
|
||||||
|
end
|
||||||
|
|
||||||
|
local protocol = vlc.access .. '://'
|
||||||
|
|
||||||
|
function Parser:probe()
|
||||||
|
return vlc.access:match('https?') and vlc.path:match(self.urlPattern)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Parser:parse()
|
||||||
local pageSource = streams.readAll(vlc)
|
local pageSource = streams.readAll(vlc)
|
||||||
|
|
||||||
if vlc.path:match('player%.mediaklikk%.hu') then
|
log.dbg('Extracting Player URLs...')
|
||||||
log.dbg('Player loaded, finding player options json')
|
|
||||||
|
|
||||||
local playerOptionsJson = pageSource:match('pl.setup%( (%b{}) %);')
|
local playerUrls = self:playerUrls(pageSource)
|
||||||
if not playerOptionsJson then
|
if #playerUrls == 0 then
|
||||||
log.warn('Cannot find player options json')
|
return noPlaylist('could not find any Player URL')
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
log.dbg('Finding playlist items of type hls')
|
log.dbg('Player URLs:', unpack(playerUrls))
|
||||||
|
log.dbg('Extracting Paths...')
|
||||||
|
|
||||||
local playerOptions = dkjson.decode(playerOptionsJson)
|
local function findPath(playerUrl)
|
||||||
local playlistItems = tables.filter(playerOptions.playlist, function(playlistItem)
|
local path = self:path(playerUrl)
|
||||||
return playlistItem.type == 'hls'
|
if not path then
|
||||||
end)
|
log.warn('could not extract Path from', playerUrl)
|
||||||
|
|
||||||
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 = playlistItem.file:gsub('^//', vlc.access .. '://'),
|
|
||||||
title = params.title,
|
|
||||||
arturl = params.bgimage
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
log.dbg('Finding embedded players');
|
return path
|
||||||
|
|
||||||
local playerSetupJsons = tables.toArray(pageSource:gmatch('mtva_player_manager%.player%(document%.getElementById%("player_%d+_%d+"%), (%b{})%);'));
|
|
||||||
|
|
||||||
log.dbg('Number of players:', #playerSetupJsons)
|
|
||||||
|
|
||||||
return tables.map(playerSetupJsons, function(playerSetupJson)
|
|
||||||
local playerSetup = dkjson.decode(playerSetupJson)
|
|
||||||
local video = playerSetup.streamId or playerSetup.token
|
|
||||||
|
|
||||||
if not video then
|
|
||||||
log.warn('Cannot find either streamId or token in player setup json:', playerSetupJson)
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local title = playerSetup.title or openGraph.property(pageSource, 'title')
|
local paths = tables.map(findPath, playerUrls)
|
||||||
local arturl = (playerSetup.bgImage and vlc.access .. ':' .. playerSetup.bgImage) or openGraph.property(pageSource, 'image')
|
if #paths == 0 then
|
||||||
local playerUrl = vlc.access .. '://player.mediaklikk.hu/playernew/player.php?video=' .. video ..
|
return noPlaylist('could not find any Path')
|
||||||
((title and '&title=' .. vlc.strings.encode_uri_component(title)) or '') ..
|
end
|
||||||
((arturl and '&bgimage=' .. vlc.strings.encode_uri_component(arturl)) or '')
|
|
||||||
|
|
||||||
log.dbg('Loading player:', playerUrl)
|
log.dbg('Paths:', unpack(paths))
|
||||||
|
|
||||||
return {
|
local function playListItem(path)
|
||||||
path = playerUrl,
|
return self:playListItem(path, pageSource)
|
||||||
title = title,
|
end
|
||||||
arturl = arturl,
|
|
||||||
options = {
|
return tables.map(playListItem, paths)
|
||||||
'http-referrer=' .. vlc.access .. '://' .. vlc.path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Parser:path(playerUrl)
|
||||||
|
local playerPageSource = streams.readAll(vlc.stream(playerUrl))
|
||||||
|
local path = playerPageSource:match('"file": *"([^"]+)"')
|
||||||
|
if path then
|
||||||
|
return urls.normalize(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function VideoParser:playerUrls(pageSource)
|
||||||
|
local function playerUrl(token)
|
||||||
|
return protocol .. 'player.mediaklikk.hu/player/player-external-vod-full.php?hls=1&token=' .. token
|
||||||
|
end
|
||||||
|
|
||||||
|
local tokens = tables.collect(pageSource:gmatch('"token":"([^"]+)"'))
|
||||||
|
return tables.map(playerUrl, tokens)
|
||||||
|
end
|
||||||
|
|
||||||
|
function VideoParser:playListItem(path, pageSource)
|
||||||
|
local function findProperty(property)
|
||||||
|
return pageSource:match('<meta property="og:' .. property .. '" content="([^"]+)"/>')
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
path = path,
|
||||||
|
title = findProperty('title'),
|
||||||
|
description = findProperty('description'),
|
||||||
|
arturl = findProperty('image'),
|
||||||
|
url = findProperty('url')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function LiveStreamParser:playerUrls(pageSource)
|
||||||
|
local streamId = pageSource:match('"streamId":"([^"]+)"')
|
||||||
|
if not streamId then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {protocol .. 'player.mediaklikk.hu/playernew/player.php?noflash=yes&video=' .. streamId}
|
||||||
|
end
|
||||||
|
|
||||||
|
function LiveStreamParser:playListItem(path, pageSource)
|
||||||
|
return {
|
||||||
|
path = path,
|
||||||
|
title = pageSource:match('<title>(.+)</title>'),
|
||||||
|
url = protocol .. vlc.path
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
tables = {
|
||||||
|
find = function(predicate, values)
|
||||||
|
for key, value in ipairs(values) do
|
||||||
|
if predicate(value, key, values) then
|
||||||
|
return value, key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
some = function(predicate, values)
|
||||||
|
local value, key = tables.find(predicate, values)
|
||||||
|
return key
|
||||||
|
end,
|
||||||
|
|
||||||
|
collect = function(iterator, state, initialValue)
|
||||||
|
local result = {}
|
||||||
|
for value in iterator, state, initialValue do
|
||||||
|
table.insert(result, value)
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end,
|
||||||
|
|
||||||
|
map = function(transform, values)
|
||||||
|
local result = {}
|
||||||
|
for key, value in ipairs(values) do
|
||||||
|
result[key] = transform(value, i, values)
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
streams = {
|
||||||
|
lines = function(s)
|
||||||
|
return s.readline, s, nil
|
||||||
|
end,
|
||||||
|
|
||||||
|
readAll = function(s)
|
||||||
|
return table.concat(tables.collect(streams.lines(s)), '\n')
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
urls = {
|
||||||
|
normalizations = {
|
||||||
|
{pattern = '\\(.)', replacement = '%1'},
|
||||||
|
{pattern = '^//', replacement = protocol}
|
||||||
|
},
|
||||||
|
|
||||||
|
normalize = function(url)
|
||||||
|
for i, normalization in ipairs(urls.normalizations) do
|
||||||
|
url = url:gsub(normalization.pattern, normalization.replacement)
|
||||||
|
end
|
||||||
|
return url
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
local function logger(vlcLog)
|
local function logger(vlcLog)
|
||||||
return function(...)
|
return function(...)
|
||||||
vlcLog(table.concat({'mediaklikk-video:', ...}, ' '))
|
vlcLog(table.concat({'mediaklikk-video:', ...}, ' '))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
log.dbg = logger(vlc.msg.dbg)
|
log = {
|
||||||
log.warn = logger(vlc.msg.warn)
|
dbg = logger(vlc.msg.dbg),
|
||||||
log.err = logger(vlc.msg.err)
|
warn = logger(vlc.msg.warn),
|
||||||
log.info = logger(vlc.msg.info)
|
err = logger(vlc.msg.err),
|
||||||
|
info = logger(vlc.msg.info)
|
||||||
function openGraph.property(source, property)
|
}
|
||||||
return source:match('<meta property="og:' .. property .. '" content="(.-)"/>')
|
|
||||||
end
|
|
||||||
|
|
||||||
function streams.readAll(s)
|
|
||||||
local function iterator(size)
|
|
||||||
if s == vlc then
|
|
||||||
return s.read(size)
|
|
||||||
else
|
|
||||||
return s:read(size)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return table.concat(tables.toArray(iterator, 1024, nil));
|
|
||||||
end
|
|
||||||
|
|
||||||
function tables.find(values, predicate)
|
|
||||||
for key, value in pairs(values) do
|
|
||||||
if predicate(value, key, values) then
|
|
||||||
return value, key
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function tables.toArray(iterator, state, initialValue)
|
|
||||||
local result = {}
|
|
||||||
for value in iterator, state, initialValue do
|
|
||||||
table.insert(result, value)
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
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)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(values) do
|
|
||||||
result[key] = transform(value, key, values)
|
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in New Issue