--[[ Handball-WM 2017-App Vers.0.6 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 file_exists(file) local f = io.open(file, "rb") if f then f:close() end return f ~= nil end function getdata(Url,outputfile) 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;",followRedir=true,o=outputfile } 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 checkBroadcastNext(beginBc, endBc) local now = os.time() if beginBc >= now 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%s+=%s+(%[{.-}%])') 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 local streamUrl = nil local streamUrlNext = nil id = false for count = 1, #table_1 do -- broadcast = table_1[count]['broadcast'] streamUrl = table_1[count]['u'] -- streamUrl if streamUrl ~= nil then streamUrl = 'https://www.youtube.com/embed' .. streamUrl beginBroadcast = table_1[count]['bb'] -- beginBroadcast endBroadcast = table_1[count]['eb'] -- endBroadcast -- Test, ob zur Zeit ein Stream gesendet wird if endBroadcast and endBroadcast and checkBroadcast(beginBroadcast, endBroadcast) == true then id = true scheduledFor = table_1[count]['sf'] -- scheduledFor group = table_1[count]['g'] -- group teamA = table_1[count]['ta'] -- teamA teamB = table_1[count]['tb'] -- teamB break elseif streamUrlNext == nil and beginBroadcast and checkBroadcastNext(beginBroadcast) == true then streamUrlNext = streamUrl end streamUrl = nil id = false end end if id == false then if streamUrlNext then local youtube_data_url_0 = streamUrlNext:match('https://www.youtube.com/embed/(.-)%?rel=0') local dataNext = getdata('https://www.youtube.com/watch?v='..youtube_data_url_0,nil) if dataNext then local imageUrl = dataNext:match('image"%s+content="(.-%.jpg)">') if imageUrl then local image = os.tmpname() getdata(imageUrl,image) if file_exists(image) then local V = video.new() V:zapitStopPlayBack() V:ShowPicture(image) os.execute("rm " .. image) end end end end 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 = {} url = url:gsub("/keepalive/yes","")--fix for new ffmpeg 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 ""