--get adress

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://videopremium%.net/' ) then return end

m_simpleTV.Control.ChangeAdress='Yes'
m_simpleTV.Control.CurrentAdress = ''

---------------------------------------------------------------------------

 local session = m_simpleTV.WinInet.New("Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.9.168 Version/11.52")
 if session == nil then return end

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

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

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

 --answer = m_simpleTV.Common.string_fromUTF8(answer)

local header =  findpattern( answer,'<h2 class="title">(.-)</h2>',1,18,5)
if header==nil then header=inAdr end

 header = string.gsub(header,'&quot;','"')
 header = string.gsub(header,'&raquo;','')

if m_simpleTV.Control.CurrentTitle ~= nil then m_simpleTV.Control.CurrentTitle=header end

answer = findpattern(answer,'method="POST"(.-)</Form>',1,13,7)

local op,usr_login,fid,fname,ref,method_free
local body
local header

op = findpattern(answer,'name="op" value="(.-)"',1,17,1)
usr_login = findpattern(answer,'name="usr_login" value="(.-)"',1,24,1)
fid = findpattern(answer,'name="id" value="(.-)"',1,17,1)
fname = findpattern(answer,'name="fname" value="(.-)"',1,20,1)
ref = findpattern(answer,'name="referer" value="(.-)"',1,22,1)
method_free = findpattern(answer,'name="method_free" value="(.-)"',1,26,1)

body = 'op=' .. op .. '&' .. 'usr_login=' .. usr_login .. '&' .. 'id=' .. fid .. '&' .. 'fname=' .. fname .. '&' .. 'referer=' .. ref .. '&' .. 'method_free=' .. method_free

header = 
'Accept:	text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\n' ..
--'Accept-Encoding:	gzip, deflate\n' ..
'Referer:' .. inAdr .. '\n' ..
'Content-Type:	application/x-www-form-urlencoded\n'

 rc,answer=m_simpleTV.WinInet.Post(session,inAdr,nil,header,body)

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

fid = findpattern(answer,'name="id" value="(.-)"',1,21,4)
local rand = math.random(0,10)
local retAdr = 'rtmpe://x' .. rand .. '.videopremium.net/play/' .. fid .. 'mp4'
--debug_in_file(retAdr .. "\n\n")

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


