--script for filenuke.com (04/12/2015)
--open link http://filenuke.com/f/0rjvyn0

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://filenuke%.com' )   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,5000,0)
  --INTERNET_OPTION_RECEIVE_TIMEOUT
  m_simpleTV.WinInet.SetOptionInt(session,6,8000,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
--debug_in_file(answer .. "\n\n")

local url=findpattern(answer,'id="go%-next" href="(.-)"',1,19,1)
    if url==nil then 
       m_simpleTV.OSD.ShowMessage("filenuke.com script error ",255,10) 
       return 
    end

url = 'http://filenuke.com' .. url

            local head = 
            'Referer: ' .. inAdr .. '\n' .. 
            'User-Agent: Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.9.168 Version/11.52'
       
             rc,answer=m_simpleTV.WinInet.Get(session,url,nil,0,head)
             m_simpleTV.WinInet.Close(session)
             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 retAdr = findpattern(answer,"var lnk234 = '(.-)'",1,14,1)
    if retAdr==nil then 
       m_simpleTV.OSD.ShowMessage("filenuke.com - video not found ",255,10) 
       return 
    end
--debug_in_file(retAdr .. "\n\n")

retAdr = retAdr .. '$OPT:http-user-agent=Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.9.168 Version/11.52$OPT:http-referrer=' .. url
m_simpleTV.Control.CurrentAdress = retAdr
