--get adress

require('json')
require('uppod')

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

local inAdr =  m_simpleTV.Control.CurrentAdress

if inAdr==nill then return end

if  not string.match( inAdr, 'http://uletno.info' ) then return end

local fhandle

local tmpName = m_simpleTV.Common.DownloadFileInTmp (inAdr,'uletno',false)

if tmpName==nil then return end

fhandle = io.open (tmpName , "r")
if fhandle==nil then return end

fhandle:seek ("set",0)

local StrFile = fhandle:read("*a")

fhandle:close()
local retadr= findpattern( StrFile,'var flashvars = %b{}',1,15,0)

if retadr==nill then
   m_simpleTV.OSD.ShowMessage("Error uletno.info - can't find address"  ,255,10)
return
end


local t = json.decode(retadr)

if t == nil or (t.file == nil and t.pl==null ) then
  m_simpleTV.OSD.ShowMessage("Error uletno.info - can't find stream address"  ,255,10)
return
end

 if t.pl~=null then
  m_simpleTV.OSD.ShowMessage("Error uletno.info - playlist not avail now"  ,255,10)
  return
 else
  retadr=t.file
 end


local hash11 = {"Q", "W", "X", "B", "M", "I", "5", "2", "c", "x", "p", "s", "6", "R", "k", "0", "H", "z", "l", "b", "4", "3", "1", "t", "8", "="}
local hash22 = {"y", "a", "V", "9", "L", "w", "n", "i", "u", "v", "Z", "7", "G", "Y", "m", "J", "D", "d", "T", "g", "f", "o", "N", "U", "e", "q"}


retadr = uppod.DecodeUppod(retadr,hash11,hash22)


m_simpleTV.OSD.ShowMessage(retadr ,255,10)
m_simpleTV.Control.ChangeAdress='Yes'
m_simpleTV.Control.CurrentAdress = retadr



