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

Initial version of channel scanning (WIP)

This commit is contained in:
mvoelkel
2016-01-07 17:50:38 +01:00
parent 414cb3a642
commit 098b307c89
4 changed files with 278 additions and 64 deletions

View File

@@ -1,7 +1,5 @@
#!/usr/bin/lua
local db = require("DataBase")
local host = os.getenv("HTTP_HOST")
local proto = os.getenv("SERVER_PROTOCOL")
local query = os.getenv("QUERY_STRING")
@@ -36,40 +34,56 @@ function SendError(err,desc)
end
end
function CreateM3U(host,SourceList)
function CreateM3U(host)
local m3u = {}
table.insert(m3u,"#EXTM3U".."\n")
for _,f in pairs(SourceList) do
if f.system == "dvbs" or f.system == "dvbs2" then
for _,c in ipairs(f.ChannelList) do
table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
table.insert(m3u,"rtsp://"..host..":554/?src="..f.src.."&"..c.request.."\n")
local file = io.open("/config/ChannelList.json")
if file then
local json = file:read("*a")
file:close()
local newdecoder = require("lunajson.decoder")
local decode = newdecoder()
local channellist = decode(json)
for _,group in ipairs(channellist.GroupList) do
for _,channel in ipairs(group.ChannelList) do
table.insert(m3u,"#EXTINF:0,"..group.Title.." - "..channel.Title.."\n")
table.insert(m3u,"rtsp://"..host..":554/?"..channel.Request.."\n")
end
else
for _,c in ipairs(f.ChannelList) do
table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
table.insert(m3u,"rtsp://"..host..":554/?src="..c.request.."\n")
end
else
local SourceList = LoadSourceList()
for _,f in pairs(SourceList) do
if f.system == "dvbs" or f.system == "dvbs2" then
for _,c in ipairs(f.ChannelList) do
table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
table.insert(m3u,"rtsp://"..host..":554/?src="..f.src.."&"..c.request.."\n")
end
else
for _,c in ipairs(f.ChannelList) do
table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
table.insert(m3u,"rtsp://"..host..":554/?"..c.request.."\n")
end
end
end
end
return table.concat(m3u)
end
function JSONSource(host,SourceList,Name,System)
function JSONSource(host,SourceList,Title,System)
local json = {}
local src = ""
local sep1 = "\n"
local sep2 = "\n"
table.insert(json,' "'..Name..'": [')
table.insert(json,' "'..Title..'": [')
sep1 = "\n"
for _,f in pairs(SourceList) do
if f.system == System or f.system == System.."2" then
if not System or f.system == System or f.system == System.."2" then
table.insert(json,sep1)
sep1 = ",\n"
table.insert(json,' {\n')
table.insert(json,' "name": "'..f.title..'",\n')
table.insert(json,' "Title": "'..f.title..'",\n')
table.insert(json,' "ChannelList": [')
if System == "dvbs" then
@@ -81,9 +95,9 @@ function JSONSource(host,SourceList,Name,System)
table.insert(json,sep2)
sep2 = ",\n"
table.insert(json,' {\n')
table.insert(json,' "name": "'..string.gsub(c.title,'"','\\"')..'",\n')
table.insert(json,' "request": "?'..src..c.request..'",\n')
table.insert(json,' "tracks": ['..c.tracks..']\n')
table.insert(json,' "Title": "'..string.gsub(c.title,'"','\\"')..'",\n')
table.insert(json,' "Request": "?'..src..c.request..'",\n')
table.insert(json,' "Tracks": ['..c.tracks..']\n')
table.insert(json,' }')
end
@@ -96,31 +110,44 @@ function JSONSource(host,SourceList,Name,System)
return table.concat(json)
end
function CreateJSON(host,SourceList)
local json = {}
table.insert(json,"{\n")
function CreateJSON(host)
local data = nil
local file = io.open("/config/ChannelList.json")
if file then
data = file:read("*a")
file:close()
else
local SourceList = LoadSourceList()
local json = {}
table.insert(json,"{\n")
table.insert(json,JSONSource(host,SourceList,"SourceListSat","dvbs") .. ",\n")
table.insert(json,JSONSource(host,SourceList,"SourceListCable","dvbc") .. ",\n")
table.insert(json,JSONSource(host,SourceList,"SourceListTer","dvbt") .. "\n")
table.insert(json,JSONSource(host,SourceList,"GroupList",nil) .. ",\n")
--~ table.insert(json,JSONSource(host,SourceList,"SourceListSat","dvbs") .. ",\n")
--~ table.insert(json,JSONSource(host,SourceList,"SourceListCable","dvbc") .. ",\n")
--~ table.insert(json,JSONSource(host,SourceList,"SourceListTer","dvbt") .. "\n")
table.insert(json,"}\n")
return table.concat(json)
table.insert(json,"}\n")
data = table.concat(json)
end
return data
end
function LoadSourceList()
local db = require("DataBase")
local SourceList = {}
local SourceList = {}
for _,f in ipairs(db.SourceList) do
f.ChannelList = {}
SourceList[f.refid] = f
end
for _,f in ipairs(db.SourceList) do
f.ChannelList = {}
SourceList[f.refid] = f
end
for _,c in ipairs(db.ChannelList) do
local f = SourceList[c.refid]
if f then
table.insert(f.ChannelList,c)
end
for _,c in ipairs(db.ChannelList) do
local f = SourceList[c.refid]
if f then
table.insert(f.ChannelList,c)
end
end
return SourceList
end
if method == "GET" then
@@ -131,10 +158,10 @@ if method == "GET" then
if string.match(query,"select=m3u") then
filename = "channellist.m3u"
contenttype = "text/m3u; charset=utf-8"
data = CreateM3U(host,SourceList)
data = CreateM3U(host)
elseif string.match(query,"select=json") then
contenttype = "application/json; charset=utf-8"
data = CreateJSON(host,SourceList)
data = CreateJSON(host)
end
if data then