if m_simpleTV.Control.ChangeAdress ~= 'No' then return end

local inAdr =  m_simpleTV.Control.CurrentAdress

if inAdr==nil then return end

if not string.match( inAdr, '^http%://player%.rutv%.ru/iframe/live/id/' ) then return end

local pageid = findpattern( inAdr, '/id/(%d+)',1,4,0)

m_simpleTV.Control.ChangeAdress='Yes'
m_simpleTV.Control.CurrentAdress = ''
----------------------------------------------------------------
local session = m_simpleTV.WinInet.New("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")
if session == nil then return end

 --INTERNET_OPTION_CONNECT_TIMEOUT
 m_simpleTV.WinInet.SetOptionInt(session,2,5000,0)
 --INTERNET_OPTION_RECEIVE_TIMEOUT
 m_simpleTV.WinInet.SetOptionInt(session,6,5000,0)
---------------------------------------------------------------

local dataAdr = 'http://player.rutv.ru/iframe/datalive/id/' .. pageid

local  rc,answer=m_simpleTV.WinInet.Get(session,dataAdr)

 if rc~=200 then
	   m_simpleTV.WinInet.Close(session)
	   m_simpleTV.OSD.ShowMessage("Connection error - " .. rc ,255,10)
	   return
 end
--debug_in_file(answer .. "\n\n")

local streamid = findpattern( answer, 'cdnvideo%.ru(.-)/playlist%.m3u8',1,13,15)

if streamid == nil then
m_simpleTV.OSD.ShowMessage("m3u8 was not found - " .. rc ,255,10)
m_simpleTV.WinInet.Close(session)
m_simpleTV.Control.CurrentAdress = retAdr
return
end

local streamid = string.gsub(streamid, '%p/','/')

local utime = findpattern( answer, 'e=(%d+)',1,2,0)

if utime == nil then
local retAdr = 'http://i.vgtrk.cdnvideo.ru/' .. streamid .. '/playlist.m3u8?auth=vh&cast_id=' .. pageid
m_simpleTV.WinInet.Close(session)
m_simpleTV.Control.CurrentAdress = retAdr
return
end

local md5sum = findpattern( answer, 'md5=(.-)&',1,4,1)

local retAdr = 'http://live.hls.vgtrk.cdnvideo.ru/' .. streamid .. '/chunklist.m3u8$OPT:http-user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"$OPT:http-ext-header=Cookie: md5=' .. md5sum .. '; e=' .. utime

--debug_in_file(retAdr .. '\n\n')

m_simpleTV.WinInet.Close(session)
m_simpleTV.Control.CurrentAdress = retAdr