function init() livelist = {} getLiveList() n = neutrino() vPlay = video.new() nMisc = misc.new() json = require "json" end function getdata(Url,Postfields,outputfile,pass_headers,httpheaders) if Url == nil then return nil end if Curl == nil then Curl = curl.new() end if Url:sub(1, 2) == '//' then Url = 'http:' .. Url end local ret, data = Curl:download{ url=Url, A="Mozilla/5.0",maxRedirs=5,followRedir=false,postfields=Postfields,header=pass_headers,o=outputfile,httpheader=httpheaders } if ret == CURL.OK then if outputfile then return 1 end return data else return nil end end function godirectkey(d) if d == nil then return d end local _dkey = "" if d == 1 then _dkey = RC.red elseif d == 2 then _dkey = RC.green elseif d == 3 then _dkey = RC.yellow elseif d == 4 then _dkey = RC.blue elseif d < 14 then _dkey = RC[""..d - 4 ..""] elseif d == 14 then _dkey = RC["0"] else -- rest _dkey = "" end return _dkey end function hideMenu(menu) if menu ~= nil then menu:hide() end end function getLiveStream(id) local url = livelist[id].url local data = getdata(url) if data then local contentUrl = data:match('"contentUrl": "(.-)"') if contentUrl then contentUrl = contentUrl:gsub('{playerId}','ngplayer_2_4') end local apiToken = data:match('"apiToken": "(.-)"') if apiToken and contentUrl then local header_opt = { 'Api-Auth: Bearer ' .. apiToken } local js_data = getdata(contentUrl,nil,nil,nil,header_opt) if js_data then local jnTab = json:decode( js_data ) local med = false if jnTab and jnTab.priorityList[1] and jnTab.priorityList[1].formitaeten[1] and jnTab.priorityList[1].formitaeten[1].qualities then for i, v in ipairs(jnTab.priorityList[1].formitaeten[1].qualities) do if v.audio and v.audio and v.audio.tracks[1] and v.audio.tracks[1].uri then if v.audio.tracks[1].uri:find("/veryhigh") then livelist[id].stream = v.audio.tracks[1].uri return livelist[id].stream else if v.audio.tracks[1].uri:find("/med") then med = true livelist[id].stream = v.audio.tracks[1].uri end if med == false and v.audio.tracks[1].uri:find("/low") then livelist[id].stream = v.audio.tracks[1].uri end if livelist[id].stream == nil and med == false and v.audio.tracks[1].uri:find("/high") then livelist[id].stream = v.audio.tracks[1].uri end end end end end end end end return livelist[id].stream end function play_live(_id) local id = tonumber(_id) if livelist[id].stream == nil then livelist[id].stream = getLiveStream(id) end if livelist[id].stream then hideMenu(live_listen_menu) vPlay:PlayFile(livelist[id].name, livelist[id].stream, "Olimpia Tokio Live","",livelist[id].audiostream or "") collectgarbage(); end end function getLiveList() local url1 = "https://www.zdf.de/sport/sport-im-zdf-livestream-live-100.html" local data = getdata(url1) if data then local ids= {} for link in data:gmatch('embed_content":%s+"(.-)"') do local channel = link:match('/([%w%-%d]+)%-%d+$') local id = channel if id and ids[id] ~= true then ids[id] = true channel = channel:gsub("%-"," ") channel = channel:gsub(" ","-") link = link:gsub('/zdf','/') link = "https://www.zdf.de" .. link .. ".html" table.insert(livelist,{name=channel, url=link, stream=nil,audiostream=nil}) end end end end function main_menu() if #livelist == 0 then return end live_listen_menu = menu.new{name="Olimpia Tokio Live", icon="streaming"} local menu = live_listen_menu menu:addItem{type="back"} menu:addItem{type="separatorline"} local d = 0 for i, v in ipairs(livelist) do d=d+1 menu:addItem{type="forwarder", name=v.name, action="play_live",enabled=true,id=i,directkey=godirectkey(d)} end menu:exec() menu:hide() return MENU_RETURN.EXIT_REPAINT end function main() init() main_menu() end main()