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:
parent
414cb3a642
commit
098b307c89
1
octoserve/var/channels/TransponderList.json
Normal file
1
octoserve/var/channels/TransponderList.json
Normal file
File diff suppressed because one or more lines are too long
153
octoserve/var/channels/doscan.lua
Executable file
153
octoserve/var/channels/doscan.lua
Executable file
@ -0,0 +1,153 @@
|
|||||||
|
#!/usr/bin/lua
|
||||||
|
|
||||||
|
--
|
||||||
|
local newdecoder = require("lunajson.decoder")
|
||||||
|
local newencoder = require("lunajson.encoder")
|
||||||
|
|
||||||
|
|
||||||
|
function GetIPAddr()
|
||||||
|
local myip = nil
|
||||||
|
local ifconfig = io.popen("ifconfig eth0")
|
||||||
|
if ifconfig then
|
||||||
|
local eth0 = ifconfig:read("*a")
|
||||||
|
ifconfig:close()
|
||||||
|
myip = string.match(eth0,"inet addr%:(%d+%.%d+%.%d+%.%d+)")
|
||||||
|
end
|
||||||
|
return myip
|
||||||
|
end
|
||||||
|
|
||||||
|
function LoadTransponderList()
|
||||||
|
local tl = nil
|
||||||
|
local f = io.open("/config/TransponderList.json","r")
|
||||||
|
if not f then
|
||||||
|
f = io.open("/var/channels/TransponderList.json","r")
|
||||||
|
end
|
||||||
|
|
||||||
|
if f then
|
||||||
|
local t = f:read("*a")
|
||||||
|
f:close()
|
||||||
|
print(#t)
|
||||||
|
|
||||||
|
local decode = newdecoder()
|
||||||
|
tl = decode(t)
|
||||||
|
end
|
||||||
|
return tl
|
||||||
|
end
|
||||||
|
|
||||||
|
function GetGroup(ChannelList,Title)
|
||||||
|
local Group
|
||||||
|
for _,c in ipairs(ChannelList.GroupList) do
|
||||||
|
if c.Title == Title then
|
||||||
|
Group = c
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not Group then
|
||||||
|
Group = { Title=Title, ChannelList = { [0] = 0 } }
|
||||||
|
table.insert(ChannelList.GroupList,Group)
|
||||||
|
end
|
||||||
|
return Group
|
||||||
|
end
|
||||||
|
|
||||||
|
local key = arg[1]
|
||||||
|
|
||||||
|
local ipAddr = GetIPAddr()
|
||||||
|
local tl = LoadTransponderList()
|
||||||
|
|
||||||
|
local ChannelList = {}
|
||||||
|
ChannelList.GroupList = {}
|
||||||
|
|
||||||
|
local Max = 999999
|
||||||
|
local Count = 0
|
||||||
|
|
||||||
|
if arg[2] then
|
||||||
|
Max = tonumber(arg[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
if tl.SourceList then
|
||||||
|
for _,Source in ipairs(tl.SourceList) do
|
||||||
|
print(Source.Title)
|
||||||
|
if key == Source.Key then
|
||||||
|
local req = ""
|
||||||
|
if Source.Type == "S" then
|
||||||
|
req = 'src=1&'
|
||||||
|
end
|
||||||
|
for _,Transponder in ipairs(Source.TransponderList) do
|
||||||
|
Count = Count + 1
|
||||||
|
if Count > Max then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
print("--------------------------------------------------------------")
|
||||||
|
print(Transponder.Request)
|
||||||
|
local octoscan = io.popen('octoscan '..ipAddr..' "'..req..Transponder.Request..'"',"r")
|
||||||
|
if octoscan then
|
||||||
|
while true do
|
||||||
|
local line = octoscan:read("*l")
|
||||||
|
if not line then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
print(line)
|
||||||
|
local pname = "?"
|
||||||
|
local sname = "?"
|
||||||
|
local sid = 0
|
||||||
|
local pids = ""
|
||||||
|
local tracks= { [0] = 0 }
|
||||||
|
local isradio = false
|
||||||
|
if line == "BEGIN" then
|
||||||
|
while true do
|
||||||
|
line = octoscan:read("*l")
|
||||||
|
if not line then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
print(line)
|
||||||
|
if line == "END" then
|
||||||
|
local channel = { Title=sname, Service=sid, Request = req..Transponder.Request.."&pids=0,"..pids, Tracks=tracks }
|
||||||
|
local cname = pname
|
||||||
|
if isradio then
|
||||||
|
cname = "Radio - "..pname
|
||||||
|
end
|
||||||
|
local category = GetGroup(ChannelList,cname)
|
||||||
|
if category then
|
||||||
|
category.ChannelList[0] = category.ChannelList[0] + 1
|
||||||
|
table.insert(category.ChannelList,channel)
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local par,val = line:match("^ (%a+):(.*)")
|
||||||
|
if par == "RADIO" then
|
||||||
|
isradio = true
|
||||||
|
elseif par == "PNAME" then
|
||||||
|
pname = val
|
||||||
|
elseif par == "SNAME" then
|
||||||
|
sname = val
|
||||||
|
elseif par == "SID" then
|
||||||
|
sid = tonumber(value)
|
||||||
|
elseif par == "PIDS" then
|
||||||
|
pids = val
|
||||||
|
elseif par == "APIDS" then
|
||||||
|
local track
|
||||||
|
for track in val:gmatch("%d+") do
|
||||||
|
tracks[0] = tracks[0] + 1
|
||||||
|
table.insert(tracks,tonumber(track))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
octoscan:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local encode = newencoder()
|
||||||
|
cl = encode(ChannelList)
|
||||||
|
|
||||||
|
if cl then
|
||||||
|
local f = io.open("/config/ChannelList.json","w+")
|
||||||
|
if f then
|
||||||
|
f:write(cl)
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
end
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
local ContentDirectory = {}
|
local ContentDirectory = {}
|
||||||
|
|
||||||
local db = require("DataBase")
|
|
||||||
|
|
||||||
-- local dlnaprofile = 'DLNA.ORG_PN=MPEG_TS;DLNA.ORG_OP=00;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=0D100000000000000000000000000000'
|
-- local dlnaprofile = 'DLNA.ORG_PN=MPEG_TS;DLNA.ORG_OP=00;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=0D100000000000000000000000000000'
|
||||||
local dlnaprofile = 'DLNA.ORG_PN=MPEG_TS;DLNA.ORG_OP=00;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=8D100000000000000000000000000000'
|
local dlnaprofile = 'DLNA.ORG_PN=MPEG_TS;DLNA.ORG_OP=00;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=8D100000000000000000000000000000'
|
||||||
local dlnaschema = ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0"'
|
local dlnaschema = ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0"'
|
||||||
@ -51,7 +49,41 @@ AllFolders["2"].ChildFolders = Folders
|
|||||||
AllFolders["64"].ChildFolders = Folders
|
AllFolders["64"].ChildFolders = Folders
|
||||||
|
|
||||||
----
|
----
|
||||||
|
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
|
||||||
|
local f = {}
|
||||||
|
f.id = "$"..tostring(#Folders)
|
||||||
|
f.VideoItems = {}
|
||||||
|
f.AudioItems = {}
|
||||||
|
f.ChildFolders = {}
|
||||||
|
f.title = string.gsub(group.Title,'&','&')
|
||||||
|
f.title = string.gsub(f.title,'<','&lt;')
|
||||||
|
f.title = string.gsub(f.title,'>','&gt;')
|
||||||
|
table.insert(Folders,f)
|
||||||
|
-- table.insert(RootFolders,f)
|
||||||
|
AllFolders[f.id] = f
|
||||||
|
for _,channel in ipairs(group.ChannelList) do
|
||||||
|
local vi = {}
|
||||||
|
vi.id = f.id.."$"..tostring(#f.VideoItems)
|
||||||
|
vi.src = f.src
|
||||||
|
vi.parentID = f.id
|
||||||
|
vi.request = string.gsub(channel.Request,'&','&amp;')
|
||||||
|
vi.title = string.gsub(channel.Title,'&','&amp;')
|
||||||
|
vi.title = string.gsub(vi.title,'<','&lt;')
|
||||||
|
vi.title = string.gsub(vi.title,'>','&gt;')
|
||||||
|
table.insert(f.VideoItems,vi)
|
||||||
|
AllItems[vi.id] = vi
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local db = require("DataBase")
|
||||||
for _,f in ipairs(db.SourceList) do
|
for _,f in ipairs(db.SourceList) do
|
||||||
f.id = f.refid
|
f.id = f.refid
|
||||||
f.VideoItems = {}
|
f.VideoItems = {}
|
||||||
@ -74,6 +106,7 @@ for _,vi in ipairs(db.ChannelList) do
|
|||||||
table.insert(f.VideoItems,vi)
|
table.insert(f.VideoItems,vi)
|
||||||
AllItems[vi.id] = vi
|
AllItems[vi.id] = vi
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
----- Add Stream Folder
|
----- Add Stream Folder
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
local db = require("DataBase")
|
|
||||||
|
|
||||||
local host = os.getenv("HTTP_HOST")
|
local host = os.getenv("HTTP_HOST")
|
||||||
local proto = os.getenv("SERVER_PROTOCOL")
|
local proto = os.getenv("SERVER_PROTOCOL")
|
||||||
local query = os.getenv("QUERY_STRING")
|
local query = os.getenv("QUERY_STRING")
|
||||||
@ -36,10 +34,25 @@ function SendError(err,desc)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function CreateM3U(host,SourceList)
|
function CreateM3U(host)
|
||||||
local m3u = {}
|
local m3u = {}
|
||||||
table.insert(m3u,"#EXTM3U".."\n")
|
table.insert(m3u,"#EXTM3U".."\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
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local SourceList = LoadSourceList()
|
||||||
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
|
||||||
@ -49,27 +62,28 @@ function CreateM3U(host,SourceList)
|
|||||||
else
|
else
|
||||||
for _,c in ipairs(f.ChannelList) do
|
for _,c in ipairs(f.ChannelList) do
|
||||||
table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
|
table.insert(m3u,"#EXTINF:0,"..f.title.." - "..c.title.."\n")
|
||||||
table.insert(m3u,"rtsp://"..host..":554/?src="..c.request.."\n")
|
table.insert(m3u,"rtsp://"..host..":554/?"..c.request.."\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.concat(m3u)
|
return table.concat(m3u)
|
||||||
end
|
end
|
||||||
|
|
||||||
function JSONSource(host,SourceList,Name,System)
|
function JSONSource(host,SourceList,Title,System)
|
||||||
local json = {}
|
local json = {}
|
||||||
local src = ""
|
local src = ""
|
||||||
local sep1 = "\n"
|
local sep1 = "\n"
|
||||||
local sep2 = "\n"
|
local sep2 = "\n"
|
||||||
|
|
||||||
table.insert(json,' "'..Name..'": [')
|
table.insert(json,' "'..Title..'": [')
|
||||||
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 not System or f.system == System or f.system == System.."2" then
|
||||||
table.insert(json,sep1)
|
table.insert(json,sep1)
|
||||||
sep1 = ",\n"
|
sep1 = ",\n"
|
||||||
table.insert(json,' {\n')
|
table.insert(json,' {\n')
|
||||||
table.insert(json,' "name": "'..f.title..'",\n')
|
table.insert(json,' "Title": "'..f.title..'",\n')
|
||||||
table.insert(json,' "ChannelList": [')
|
table.insert(json,' "ChannelList": [')
|
||||||
|
|
||||||
if System == "dvbs" then
|
if System == "dvbs" then
|
||||||
@ -81,9 +95,9 @@ function JSONSource(host,SourceList,Name,System)
|
|||||||
table.insert(json,sep2)
|
table.insert(json,sep2)
|
||||||
sep2 = ",\n"
|
sep2 = ",\n"
|
||||||
table.insert(json,' {\n')
|
table.insert(json,' {\n')
|
||||||
table.insert(json,' "name": "'..string.gsub(c.title,'"','\\"')..'",\n')
|
table.insert(json,' "Title": "'..string.gsub(c.title,'"','\\"')..'",\n')
|
||||||
table.insert(json,' "request": "?'..src..c.request..'",\n')
|
table.insert(json,' "Request": "?'..src..c.request..'",\n')
|
||||||
table.insert(json,' "tracks": ['..c.tracks..']\n')
|
table.insert(json,' "Tracks": ['..c.tracks..']\n')
|
||||||
table.insert(json,' }')
|
table.insert(json,' }')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,19 +110,30 @@ function JSONSource(host,SourceList,Name,System)
|
|||||||
return table.concat(json)
|
return table.concat(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CreateJSON(host,SourceList)
|
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 = {}
|
local json = {}
|
||||||
table.insert(json,"{\n")
|
table.insert(json,"{\n")
|
||||||
|
|
||||||
table.insert(json,JSONSource(host,SourceList,"SourceListSat","dvbs") .. ",\n")
|
table.insert(json,JSONSource(host,SourceList,"GroupList",nil) .. ",\n")
|
||||||
table.insert(json,JSONSource(host,SourceList,"SourceListCable","dvbc") .. ",\n")
|
--~ table.insert(json,JSONSource(host,SourceList,"SourceListSat","dvbs") .. ",\n")
|
||||||
table.insert(json,JSONSource(host,SourceList,"SourceListTer","dvbt") .. "\n")
|
--~ table.insert(json,JSONSource(host,SourceList,"SourceListCable","dvbc") .. ",\n")
|
||||||
|
--~ table.insert(json,JSONSource(host,SourceList,"SourceListTer","dvbt") .. "\n")
|
||||||
|
|
||||||
table.insert(json,"}\n")
|
table.insert(json,"}\n")
|
||||||
return table.concat(json)
|
data = table.concat(json)
|
||||||
|
end
|
||||||
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function LoadSourceList()
|
||||||
|
local db = require("DataBase")
|
||||||
local SourceList = {}
|
local SourceList = {}
|
||||||
|
|
||||||
for _,f in ipairs(db.SourceList) do
|
for _,f in ipairs(db.SourceList) do
|
||||||
@ -122,6 +147,8 @@ for _,c in ipairs(db.ChannelList) do
|
|||||||
table.insert(f.ChannelList,c)
|
table.insert(f.ChannelList,c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return SourceList
|
||||||
|
end
|
||||||
|
|
||||||
if method == "GET" then
|
if method == "GET" then
|
||||||
local filename = nil
|
local filename = nil
|
||||||
@ -131,10 +158,10 @@ if method == "GET" then
|
|||||||
if string.match(query,"select=m3u") then
|
if string.match(query,"select=m3u") then
|
||||||
filename = "channellist.m3u"
|
filename = "channellist.m3u"
|
||||||
contenttype = "text/m3u; charset=utf-8"
|
contenttype = "text/m3u; charset=utf-8"
|
||||||
data = CreateM3U(host,SourceList)
|
data = CreateM3U(host)
|
||||||
elseif string.match(query,"select=json") then
|
elseif string.match(query,"select=json") then
|
||||||
contenttype = "application/json; charset=utf-8"
|
contenttype = "application/json; charset=utf-8"
|
||||||
data = CreateJSON(host,SourceList)
|
data = CreateJSON(host)
|
||||||
end
|
end
|
||||||
|
|
||||||
if data then
|
if data then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user