-- плейлист http://iptv.sat-elit.net

 local session = m_simpleTV.WinInet.New("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.53 Safari/537.36 OPR/28.0.1750.31 (Edition beta)")
 if session == nil then return end

  --INTERNET_OPTION_CONNECT_TIMEOUT
  m_simpleTV.WinInet.SetOptionInt(session,2,8000,0)
  --INTERNET_OPTION_RECEIVE_TIMEOUT
  m_simpleTV.WinInet.SetOptionInt(session,6,8000,0)
-----------------------------------------------------------------
function trim(s)
  return (s:gsub("^%s*(.-)%s*$", "%1"))
end
-----------------------------------------------------------------

 m_simpleTV.OSD.ShowMessage("SatElit - начало обновления" ,0xFF00,10)

local url = 'http://iptv.sat-elit.net/myPlaylistS.php'

  local rc,answer=m_simpleTV.WinInet.Get(session,url)
  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
answer=m_simpleTV.Common.string_fromUTF8(answer) 

if not string.match(answer,'<item>') then 
  m_simpleTV.OSD.ShowMessage("Sat-Elit - ошибка обновления",255,10)
 return 
end

local m3ustr = '#EXTM3U\n'

 local  tmpName = m_simpleTV.Common.GetTmpName()
 if tmpName==nil then 
		return 
 end 
 
 local tfile = io.open(tmpName,'w+')
 if tfile==nil then 
	os.remove(tmpName)
	return
 end
  
 tfile:write(m3ustr)
 tfile:close() 

for w in string.gmatch(answer,'<item>(.-)</item>') do 
 local url = string.match(w,'file="(.-)"')
 local name = string.match(w,'<title>(.-)</title>')
 if name == nil or url == nil then break end
 m3ustr = '#EXTINF:-1,SatElit:' .. trim(name) .. '\n' .. trim(url) .. '\n'
 tfile = io.open(tmpName,'a+')
 tfile:write(m3ustr)
 tfile:close()
 end

  --опции  для загрузки плейлиста 
local p={}
p.TypeSourse = 1
p.DeleteBeforeLoad = 0
p.TypeSkip   = 1
p.TypeFind =   0
p.AutoSearch = 1
p.NumberM3U =  1
p.Find_Group = 1
p.TypeCoding = 0  --  -1-auto  0 - plane text  1- UTF8  2- unicode
p.BorpasFileFormat=0
p.ExtFilter = 'SatElit'
p.AutoNumber = 0

local err,add,ref,names = m_simpleTV.Common.LoadPlayList (tmpName,p,0,true,false)
os.remove(tmpName)

if err==true then
     local mess = "SatElit - каналы обновлены"	 
	 m_simpleTV.OSD.ShowMessage(mess,0xFF00,5)
end
 
