Compare commits

..

No commits in common. "master" and "v2.0.0" have entirely different histories.

2 changed files with 32 additions and 78 deletions

View File

@ -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
@ -14,6 +14,10 @@ Copy [mediaklikk-video.lua](mediaklikk-video.lua) to [VLC Lua playlist scripts](
* Mac OS X: `~/Library/Application Support/org.videolan.vlc/lua/playlist/` * Mac OS X: `~/Library/Application Support/org.videolan.vlc/lua/playlist/`
* Windows: `%APPDATA%\vlc\lua\playlist\` * Windows: `%APPDATA%\vlc\lua\playlist\`
## From addons.videolan.org
This playlist parser is also [available on addons.videolan.org](https://addons.videolan.org/p/1190582/).
## Supported sites ## Supported sites
### Videos ### Videos
@ -22,14 +26,9 @@ 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
This playlist parser is also [available on addons.videolan.org](https://addons.videolan.org/p/1190582/).

View File

@ -11,48 +11,16 @@ local urlPatterns = {
} }
function probe() function probe()
return vlc.access:match('https?') and tables.find(urlPatterns, function(pattern) return vlc.access:match('https?')
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{})%);'));
if vlc.path:match('player%.mediaklikk%.hu') then
log.dbg('Player loaded, finding player options json')
local playerOptionsJson = pageSource:match('pl.setup%( (%b{}) %);')
if not playerOptionsJson then
log.warn('Cannot find player options json')
return nil
end
log.dbg('Finding playlist items of type hls')
local playerOptions = dkjson.decode(playerOptionsJson)
local playlistItems = tables.filter(playerOptions.playlist, function(playlistItem)
return playlistItem.type == 'hls'
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 = playlistItem.file:gsub('^//', vlc.access .. '://'),
title = params.title,
arturl = params.bgimage
}
end)
end
log.dbg('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)
@ -65,21 +33,27 @@ function parse()
return nil return nil
end end
local title = playerSetup.title or openGraph.property(pageSource, 'title') local playerUrl = vlc.access .. '://player.mediaklikk.hu/playernew/player.php?video=' .. video
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 = playerUrl, path = vlc.access .. ':' .. playlistItem.file,
title = title, title = playerSetup.title or openGraph.property(pageSource, 'title'),
arturl = arturl, description = openGraph.property(pageSource, 'description'),
options = { arturl = (playerSetup.bgImage and vlc.access .. ':' .. playerSetup.bgImage) or openGraph.property(pageSource, 'image')
'http-referrer=' .. vlc.access .. '://' .. vlc.path
}
} }
end) end)
end end
@ -108,7 +82,7 @@ function streams.readAll(s)
end end
end end
return table.concat(tables.toArray(iterator, 1024, nil)); return table.concat(tables.collect(iterator, 1024, nil));
end end
function tables.find(values, predicate) function tables.find(values, predicate)
@ -119,7 +93,7 @@ function tables.find(values, predicate)
end end
end end
function tables.toArray(iterator, state, initialValue) function tables.collect(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)
@ -127,14 +101,6 @@ function tables.toArray(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
@ -142,14 +108,3 @@ function tables.map(values, transform)
end end
return result return result
end 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