--script for https://trovo.live (27/06/2022) --for example open addresses such as --Live https://trovo.live/s/streamer_name/220638450 --VOD https://trovo.live/s/streamer_name/549797369237?vid=ltv-110319225_110319225_387702302364607231 ------------------------------------------------------------------------------ if m_simpleTV.Control.ChangeAddress ~= 'No' then return end local inAdr = m_simpleTV.Control.CurrentAddress if inAdr==nil then return end if not string.match( inAdr, '^https://trovo%.live/.+' ) and not string.match( inAdr, '^$trovo=' ) then return end m_simpleTV.Control.ChangeAddress='Yes' m_simpleTV.Control.CurrentAddress = 'error' ------------------------------------------------------------------------------ local userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36 Edg/101.0.1210.39" local session = m_simpleTV.Http.New(userAgent, nil, false) if session == nil then return end m_simpleTV.Http.SetTimeout(session, 3000) ------------------------------------------------------------------------------ local function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end ------------------------------------------------------ local function get_stream_table(str) local name,adr local t={} local i=1 for adr, name in string.gmatch(str, '"playUrl":"(.-)","desc":"(.-)"') do if adr~='' then --[[ adr = string.gsub(adr,'\u(%x%x%x%x)','\\u%1') adr = unescape3(adr) adr = string.gsub(adr,'\\','') ]] adr = '$trovo=' .. encode64(adr) t[i]={} t[i].Id=i t[i].Name=name t[i].Address=adr --debug_in_file(t[i].Name .. ' ' .. t[i].Address .. '\n') i=i+1 end end return t end ------------------------------------------------------ local opt = '$OPT:http-referrer=https://trovo.live/' .. '$OPT:http-user-agent=' .. userAgent if string.match(inAdr, '^$trovo=' ) then local retAdr = inAdr retAdr = string.gsub(retAdr,'$trovo=','') retAdr = decode64(retAdr) m_simpleTV.Control.CurrentAddress = retAdr .. opt return end ------------------------------------------------------------------------------------------- if string.match(inAdr, '%?vid=' ) then local vid = string.gsub(inAdr, '.-%?vid=(.+)', '%1') local rc, answer = m_simpleTV.Http.Request(session,{url = inAdr}) --m_simpleTV.Http.Close(session) if rc~=200 then return end answer = string.gsub(answer,'\u(%x%x%x%x)','\\u%1') answer = unescape3(answer) answer = string.gsub(answer,'\\','') --debug_in_file(rc .. '\n' .. answer .. '\n') local streamer = string.match(answer, 'spaceName":"(.-)"') if streamer==nil then return end local roomId = string.match(answer, 'roomID":(%d+)') local spaceId = string.match(answer, 'spaceID":(%d+)') or findpattern(answer, '/s/' .. streamer .. '/(%d+)',3000,4+#streamer,0) --debug_in_file(roomId .. ' ' .. spaceId .. '\n') --do return end local url = 'https://api-web.trovo.live/graphql' .. '?chunk=1&reqms=' .. os.time() .. '123&qid=E332DAD0CF&cli=4&client_info={%22device_info%22:%22{%22tid%22:%2216563493465345241%22}%22}&from=%2Fs%2F' .. streamer .. '%2F' .. roomId .. '&locale=RU&resolution=680*1280' local headers = 'referer: https://trovo.live/\ncontent-type: text/plain' local body = '{"operationName":"vod_VodReaderService_GetChannelLtvVideoInfos","variables":{"params":{"pageSize":99,"currPage":1,"terminalSpaceID":{"spaceID":' .. spaceId .. '},"roomID":' .. roomId .. '}}}' rc, answer = m_simpleTV.Http.Request(session, {url = url, method = 'post', headers = headers, body = body}) m_simpleTV.Http.Close(session) --debug_in_file(answer .. '\n') --do return end answer = string.gsub(answer, ':%[%]', ':""') answer = string.gsub(answer, '%[%]', ' ') require('json') local tab = json.decode(answer) if tab==nil then return end local tt={} if tab.data and tab.data.vod_VodReaderService_GetChannelLtvVideoInfos and tab.data.vod_VodReaderService_GetChannelLtvVideoInfos.vodInfos then tt = tab.data.vod_VodReaderService_GetChannelLtvVideoInfos.vodInfos local t={} local name, adr for j=1,#tt do if tt[j].vid == vid then for i=1,#tt[j].playInfos do name = tt[j].playInfos[i].desc adr = tt[j].playInfos[i].playUrl adr = string.gsub(adr,'\u(%x%x%x%x)','\\u%1') adr = unescape3(adr) adr = string.gsub(adr,'\\','') adr = '$trovo=' .. encode64(adr) t[i]={} t[i].Id=i t[i].Name=name t[i].Address=adr --debug_in_file(t[i].Name .. ' ' .. t[i].Address .. '\n') end end end --do return end local title = string.match(answer, 'title":"(.-)"') or '' title = streamer .. ' - ' .. title m_simpleTV.OSD.ShowSelect_UTF8(m_simpleTV.Common.multiByteToUTF8('Качество', 1251),0,t,9000,32+64+128) local retAdr = t[1].Address retAdr = string.gsub(retAdr,'$trovo=','') retAdr = decode64(retAdr) --debug_in_file(retAdr .. '\n') m_simpleTV.Control.SetTitle(title) m_simpleTV.Control.CurrentAddress = retAdr .. opt end return end ------------------------------------------------------------------------------- if not string.match(inAdr, '%?vid=' ) then local rc, answer = m_simpleTV.Http.Request(session,{url = inAdr}) m_simpleTV.Http.Close(session) if rc~=200 then return end answer = string.gsub(answer,'\u(%x%x%x%x)','\\u%1') answer = unescape3(answer) answer = string.gsub(answer,'\\','') --debug_in_file(answer .. '\n') local streamer = string.match(answer, 'spaceName":"(.-)"') or '' local title = string.match(answer, 'title":"(.-)"') or '' title = streamer .. ' - ' .. title local t = get_stream_table(answer) if #t==0 then return end m_simpleTV.OSD.ShowSelect_UTF8(m_simpleTV.Common.multiByteToUTF8('Качество', 1251),0,t,9000,32+64+128) local retAdr = t[1].Address retAdr = string.gsub(retAdr,'$trovo=','') retAdr = decode64(retAdr) --debug_in_file(retAdr .. '\n') m_simpleTV.Control.SetTitle(title) m_simpleTV.Control.CurrentAddress = retAdr .. opt end