1
0
mirror of https://github.com/DigitalDevices/octonet.git synced 2023-10-10 11:36:52 +00:00

Speedup channellist.lua

This commit is contained in:
mvoelkel 2015-12-09 13:05:26 +01:00
parent 32efebb36a
commit 26c6aee619

View File

@ -37,39 +37,40 @@ function SendError(err,desc)
end end
function CreateM3U(host,SourceList) function CreateM3U(host,SourceList)
local m3u = "#EXTM3U".."\n" local m3u = {}
table.insert(m3u,"#EXTM3U".."\n")
for _,f in pairs(SourceList) do for _,f in pairs(SourceList) do
if f.system == "dvbs" or f.system == "dvbs2" then if f.system == "dvbs" or f.system == "dvbs2" then
for _,c in ipairs(f.ChannelList) do for _,c in ipairs(f.ChannelList) do
m3u = m3u .. "#EXTINF:0,"..f.title.." - "..c.title.."\n" table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
.. "rtsp://"..host..":554/?src="..f.src.."&"..c.request.."\n" table.insert(m3u,"rtsp://"..host..":554/?src="..f.src.."&"..c.request.."\n")
end end
else else
for _,c in ipairs(f.ChannelList) do for _,c in ipairs(f.ChannelList) do
m3u = m3u .. "#EXTINF:0,"..f.title.." - "..c.title.."\n" table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
.. "rtsp://"..host..":554/?src="..c.request.."\n" table.insert(m3u,"rtsp://"..host..":554/?src="..c.request.."\n")
end end
end end
end end
return m3u return table.concat(m3u)
end end
function JSONSource(host,SourceList,Name,System) function JSONSource(host,SourceList,Name,System)
local json = "" local json = {}
local src = "" local src = ""
local sep1 = "\n" local sep1 = "\n"
local sep2 = "\n" local sep2 = "\n"
json = json .. ' "'..Name..'": [' table.insert(json,' "'..Name..'": ['
sep1 = "\n" sep1 = "\n"
for _,f in pairs(SourceList) do for _,f in pairs(SourceList) do
if f.system == System or f.system == System.."2" then if f.system == System or f.system == System.."2" then
json = json .. sep1 table.insert(json,sep1)
sep1 = ",\n" sep1 = ",\n"
json = json .. ' {\n' table.insert(json,' {\n')
json = json .. ' "name": "'..f.title..'",\n' table.insert(json,' "name": "'..f.title..'",\n')
json = json .. ' "ChannelList": [' table.insert(json,' "ChannelList": [')
if System == "dvbs" then if System == "dvbs" then
src = 'src='..f.src..'&' src = 'src='..f.src..'&'
@ -77,33 +78,34 @@ function JSONSource(host,SourceList,Name,System)
sep2 = "\n" sep2 = "\n"
for _,c in ipairs(f.ChannelList) do for _,c in ipairs(f.ChannelList) do
json = json .. sep2 table.insert(json,sep2)
sep2 = ",\n" sep2 = ",\n"
json = json .. ' {\n' table.insert(json,' {\n')
json = json .. ' "name": "'..string.gsub(c.title,'"','\\"')..'",\n' table.insert(json,' "name": "'..string.gsub(c.title,'"','\\"')..'",\n')
json = json .. ' "request": "?'..src..c.request..'",\n' table.insert(json,' "request": "?'..src..c.request..'",\n')
json = json .. ' "tracks": ['..c.tracks..']\n' table.insert(json,' "tracks": ['..c.tracks..']\n')
json = json .. ' }' table.insert(json,' }')
end end
json = json .. '\n ]\n' table.insert(json,'\n ]\n')
json = json .. ' }' table.insert(json,' }')
end end
end end
json = json .. '\n ]' table.insert(json,'\n ]')
return json return table.concat(json)
end end
function CreateJSON(host,SourceList) function CreateJSON(host,SourceList)
local json = "{\n" local json = {}
table.insert(json,"{\n")
json = json .. JSONSource(host,SourceList,"SourceListSat","dvbs") .. ",\n" table.insert(json,JSONSource(host,SourceList,"SourceListSat","dvbs") .. ",\n")
json = json .. JSONSource(host,SourceList,"SourceListCable","dvbc") .. ",\n" table.insert(json,JSONSource(host,SourceList,"SourceListCable","dvbc") .. ",\n")
json = json .. JSONSource(host,SourceList,"SourceListTer","dvbt") .. "\n" table.insert(json,JSONSource(host,SourceList,"SourceListTer","dvbt") .. "\n")
json = json .. "}\n" table.insert(json,"}\n")
return json return table.concat(json)
end end
@ -121,9 +123,6 @@ for _,c in ipairs(db.ChannelList) do
end end
end end
--~ http_print(proto.." 200" )
--~ http_print()
if method == "GET" then if method == "GET" then
local filename = nil local filename = nil
local contenttype = nil local contenttype = nil