--[[
Handball-WM 2017-App
Vers.0.4 by bazi98 and micha-bbg
Lizenz GPL 2
App liest auf der Seite https://handball.dkb.de/ dem dortigen Quelltext nach der jeweils letzten dort
vorkommenden Youtube-Livstream-ID aus z.B. streamUrl":"https://www.youtube.com/embed/Vs1alvZANCo?rel=0
und übergibt die ID weiter, und wertet die aus womit am Ende der youtube-Livestreams vom neutrino-movieplayer
abgespielt werden kann.
ps.: Die youtube-Livestreams sind laut Web-Berichten immer erst kurz vor Spielbeginn aktiv.
In der webtv_usr.xml das folgende eintragen
]]
json = require "json"
if #arg < 1 then return nil end
local _url = arg[1]
local ret = {}
local Curl = nil
function getdata(Url)
if Url == nil then return nil end
if Curl == nil then
Curl = curl.new()
end
local ret, data = Curl:download{ url=Url, A="Mozilla/5.0"}
if ret == CURL.OK then
return data
else
return nil
end
end
function checkBroadcast(beginBc, endBc)
local now = os.time()
if ((now >= beginBc) and (now <= endBc)) then
return true
else
return false
end
end
function getVideoData(url)
if url == nil then return 0 end
local dkb_data = getdata(url)
if dkb_data == nil then return 0 end
local table_1 = dkb_data:match('window.matches = (.-)')
if table_1 == nil then return 0 end
-- trim
table_1 = table_1:gsub("^%s*(.-)%s*$", "%1")
table_1 = json:decode(table_1)
if table_1 == nil then return 0 end
streamUrl = ""
id = 0
for count = 1, #table_1 do
-- broadcast = table_1[count]['broadcast']
streamUrl = table_1[count]['streamUrl']
if streamUrl ~= "" then
beginBroadcast = table_1[count]['beginBroadcast']
endBroadcast = table_1[count]['endBroadcast']
-- Test, ob zur Zeit ein Stream gesendet wird
if checkBroadcast(beginBroadcast, endBroadcast) == true then
id = tonumber(table_1[count]['id'])
scheduledFor = table_1[count]['scheduledFor']
group = table_1[count]['group']
teamA = table_1[count]['teamA']
teamB = table_1[count]['teamB']
break
end
streamUrl = ""
id = 0
end
end
if id == 0 then return 0 end
local youtube_data_url_1 = streamUrl:match('https://www.youtube.com/embed/(.-)%?rel=0')
local data = getdata('https://www.youtube.com/watch?v='..youtube_data_url_1,nil)
if data then
-- local newname = data:match('
(.-)')
local streamTime = string.format("(Start: %s, Stream von %s bis %s)", os.date("%H:%M", scheduledFor), os.date("%H:%M", beginBroadcast), os.date("%H:%M", endBroadcast))
local newname = string.format("%s - %s | Gruppe %s %s", teamA, teamB, group, streamTime)
local m3u_url = data:match('hlsvp.:.(https:\\.-m3u8)')
if m3u_url == nil then return 0 end
m3u_url = m3u_url:gsub("\\", "")
local videodata = getdata(m3u_url)
local url = ""
local band = ""
local res1 = ""
local res2 = ""
local count = 0
for band, res1, res2, url in videodata:gmatch('#EXT.X.STREAM.INF.BANDWIDTH=(%d+).-RESOLUTION=(%d+)x(%d+).-(http.-)\n') do
if url ~= nil then
entry = {}
entry['url'] = url
entry['band'] = band
entry['res1'] = res1
entry['res2'] = res2
entry['name'] = ""
if newname then
entry['name'] = newname
end
count = count + 1
ret[count] = {}
ret[count] = entry
end
end
return count
end
return 0
end
if (getVideoData(_url) > 0) then
return json:encode(ret)
end
return ""