--[[ XMLTV_Urls.lua - add EPG Urls to neutrino.conf Copyright (C) 2021 Jacek Jendrzej 'satbaby' License: WTFPLv2 ]] local locale = {} locale["deutsch"] = { save_xml = 'Einstellungen jetzt speichern', defXMLurl = 'Standard XmlTV Urls hinzufügen', xmlfileselect = 'Datei mit XmlTV Urls auswählen', info = 'neue Urls' } locale["english"] = { save_xml = 'Save settings now', defXMLurl = 'Add standard XmlTV urls', xmlfileselect = 'select with XmlTV Urls file', info = 'new urls' } function init() n = neutrino() Curl = nil conf = {} repaint = false repainted = 0 firstcount = 0 local V = nil local m = nil end function getdata(Url) if Url == nil then return nil end if Curl == nil then Curl = curl.new() end local ret, data = Curl:download{ url=Url, A="Mozilla/5.0"} if ret == CURL.OK then return data else return nil end end function lines_from(file) if not file_exists(file) then return {} end lines = {} for line in io.lines(file) do lines[#lines + 1] = line end return lines end function file_exists(file) local f = io.open(file, "rb") if f then f:close() end return f ~= nil end function godirectkey(d) if d == nil then return d end local _dkey = "" if d == 1 then _dkey = RC["red"] elseif d == 2 then _dkey = RC["green"] elseif d == 3 then _dkey = RC["yellow"] elseif d == 4 then _dkey = RC["blue"] elseif d < 14 then _dkey = RC[""..d - 4 ..""] elseif d == 14 then _dkey = RC["0"] else -- rest _dkey = "" end return _dkey end function sleep(a) local sec = tonumber(os.clock() + a) while (os.clock() < sec) do end end function get_confFile() local confFile = "/var/tuxbox/config/neutrino.conf" return confFile end function saveConfig() local filename = get_confFile() if conf.changed then local Nconfig = configfile.new() Nconfig:loadConfig(filename) if liste and #liste > firstcount then Nconfig:setString("xmltv_xml_count", #liste) for i, v in ipairs(liste) do Nconfig:setString("xmltv_xml_" .. tostring(i-1), v) end end Nconfig:saveConfig(filename) getdata("http://127.0.0.1/control/reloadsetup") conf.changed = false end end function loadConfig() liste = {} local filename = get_confFile() if file_exists(filename) == false then local gui = require "n_gui" gui.paintInfoBox("Not found file:\n" .. filename, 400, 160) sleep(5) return false end local Nconfig = configfile.new() Nconfig:loadConfig(filename) conf.lang = Nconfig:getString("language", "english") if locale[conf.lang] == nil then conf.lang = "english" end loc = locale[conf.lang] local xmltv_xml_count = Nconfig:getString("xmltv_xml_count", "0") if xmltv_xml_count ~= nil then for i=0,xmltv_xml_count - 1 do local xmltv_xml = Nconfig:getString("xmltv_xml_" .. tostring(i), "#") table.insert(liste,xmltv_xml) firstcount = firstcount + 1 end end return true end function have_url(tab,_url) for i, v in ipairs(tab) do if v == _url then return true end end return false end function addDefaultXmltvUrls() local myXMLurl = {} table.insert(myXMLurl, 'https://my.iptv.community/epg_temp_dl/output-epgs/austria.xml') table.insert(myXMLurl, 'https://my.iptv.community/epg_temp_dl/output-epgs/switzerland.xml') table.insert(myXMLurl, 'https://i.mjh.nz/SamsungTVPlus/de.xml') table.insert(myXMLurl, 'https://i.mjh.nz/SamsungTVPlus/ch.xml') table.insert(myXMLurl, 'https://i.mjh.nz/SamsungTVPlus/at.xml') for i=1,5 do local myUrl = myXMLurl[i] if have_url(liste, myUrl) == false then table.insert(liste,myUrl) conf.changed = true end end if conf.changed then repainted = 1 repaint = true return MENU_RETURN.EXIT end end function addXmltvUrlsFromFile(id,selectedfile) local links = lines_from(selectedfile) for i, v in ipairs(links) do v = v:gsub("[\0-\31]","") if v:sub(1,4) == "http" and have_url(liste, v) == false then table.insert(liste,v) conf.changed = true end end if conf.changed then repainted = 2 repaint = true return MENU_RETURN.EXIT end end function main_menu() if repaint then repaint = false end menu = menu.new{name="xmltv urls", icon="star-on"} menu:addItem{type="back"} menu:addItem{type="separatorline"} local d = 0 d=d+1 m1 = menu:addItem{type="forwarder", name=loc.save_xml, action="saveConfig",id=i,directkey=godirectkey(d)} d=d+1 menu:addItem{ type="filebrowser", dir_mode="0", id="nix", name=loc.xmlfileselect, action="addXmltvUrlsFromFile", enabled=true,value=conf.selectedfile,directkey=godirectkey(d) } d=d+1 m2 = menu:addItem{type="forwarder", name=loc.defXMLurl, action="addDefaultXmltvUrls",id=i,directkey=godirectkey(d)} menu:addItem{type="separatorline"} for i, v in ipairs(liste) do if i == firstcount + 1 then menu:addItem{type="subhead", name=loc.info} end d=d+1 menu:addItem{type="forwarder", name=v, action="nothing",enabled=false,id=i} end if repainted == 0 then menu:setActive{item=m1, activ=false} menu:setSelected{preselected=3} elseif repainted == 1 then menu:setActive{item=m2, activ=false} menu:setSelected{preselected=2} end menu:exec() menu:hide() end function main() init() local ok = loadConfig() if ok == false then return end repeat main_menu() until repaint == false end main()