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

doscan parameters added

This commit is contained in:
mvoelkel 2016-01-12 20:14:38 +01:00
parent 7b8627b7a8
commit 90e8bcc7f8

View File

@ -5,7 +5,7 @@ local newdecoder = require("lunajson.decoder")
local newencoder = require("lunajson.encoder") local newencoder = require("lunajson.encoder")
function GetIPAddr() local function GetIPAddr()
local myip = nil local myip = nil
local ifconfig = io.popen("ifconfig eth0") local ifconfig = io.popen("ifconfig eth0")
if ifconfig then if ifconfig then
@ -16,25 +16,28 @@ function GetIPAddr()
return myip return myip
end end
function LoadTransponderList() local function LoadTransponderList(infile)
local tl = nil local tl = nil
local f = io.open("/config/TransponderList.json","r") local f = nil
if not f then if infile then
f = io.open("/var/channels/TransponderList.json","r") f = io.open(infile,"r")
else
f = io.open("/config/TransponderList.json","r")
if not f then
f = io.open("/var/channels/TransponderList.json","r")
end
end end
if f then if f then
local t = f:read("*a") local t = f:read("*a")
f:close() f:close()
print(#t)
local decode = newdecoder() local decode = newdecoder()
tl = decode(t) tl = decode(t)
end end
return tl return tl
end end
function GetGroup(ChannelList,Title) local function GetGroup(ChannelList,Title)
local Group local Group
for _,c in ipairs(ChannelList.GroupList) do for _,c in ipairs(ChannelList.GroupList) do
if c.Title == Title then if c.Title == Title then
@ -42,16 +45,57 @@ function GetGroup(ChannelList,Title)
end end
end end
if not Group then if not Group then
Group = { Title=Title, ChannelList = { [0] = 0 } } Group = { Title=Title, ChannelList = { } }
table.insert(ChannelList.GroupList,Group) table.insert(ChannelList.GroupList,Group)
end end
return Group return Group
end end
local key = arg[1] local function cmp_title(a,b)
return a.Title < b.Title
end
local ipAddr = GetIPAddr() local keys = {}
local tl = LoadTransponderList() local include_radio = 1
local include_encrypted = 0
local infile = nil
local outfile = "/config/ChannelList.json"
local ipAddr = nil
local sort = nil
local include_sitables = nil
local a
for _,a in ipairs(arg) do
local par,val = a:match("(%a+)=(.+)")
if par == "key" then
local key,src = val:match("(%a+),(d+)")
if key then
keys[key] = tonumber(src)
else
keys[val] = 1
end
elseif par == "radio" then
include_radio = tonumber(val)
elseif par == "enc" then
include_encrypted = tonumber(val)
elseif par == "sort" then
sort = val
elseif par == "sitables" then
include_sitables = val
elseif par == "in" then
infile = val
elseif par == "out" then
outfile = val
elseif par == "ip" then
ipAddr = val
end
end
if not ipAddr then
ipAddr = GetIPAddr()
end
local tl = LoadTransponderList(infile)
local ChannelList = {} local ChannelList = {}
ChannelList.GroupList = {} ChannelList.GroupList = {}
@ -59,20 +103,16 @@ ChannelList.GroupList = {}
local Max = 999999 local Max = 999999
local Count = 0 local Count = 0
if arg[2] then
Max = tonumber(arg[2])
end
if tl.SourceList then if tl.SourceList then
for _,Source in ipairs(tl.SourceList) do for _,Source in ipairs(tl.SourceList) do
print(Source.Title) if keys[Source.Key] then
if key == Source.Key then print("Scanning: "..Source.Title)
local SourceOptions = "" local SourceOptions = ""
if Source.UseNIT then if Source.UseNIT then
SourceOptions = SourceOptions.."--use_nit " SourceOptions = SourceOptions.."--use_nit "
end end
if Source.DVBType == "S" then if Source.DVBType == "S" then
SourceOptions = '--src=1' SourceOptions = '--src='..keys[Source.Key]
end end
for _,Transponder in ipairs(Source.TransponderList) do for _,Transponder in ipairs(Source.TransponderList) do
@ -111,8 +151,9 @@ if tl.SourceList then
local sname = "?" local sname = "?"
local sid = 0 local sid = 0
local pids = "" local pids = ""
local tracks= { [0] = 0 } local tracks= { }
local isradio = false local isradio = false
local isencrypted = false
if line == "BEGIN" then if line == "BEGIN" then
while true do while true do
line = octoscan:read("*l") line = octoscan:read("*l")
@ -121,15 +162,26 @@ if tl.SourceList then
end end
print(line) print(line)
if line == "END" then if line == "END" then
local channel = { Title=sname, Service=sid, Request = '?'..Request.."&pids=0,"..pids, Tracks=tracks } local all_pids = ",0"
local cname = pname if include_sitables then
if isradio then if isencrypted then
cname = "Radio - "..pname all_pids = all_pids..",1"
end
all_pids = all_pids..",16,17,18,20"
end end
local category = GetGroup(ChannelList,cname) if #pids > 0 then
if category then all_pids = all_pids .. ",pids"
category.ChannelList[0] = category.ChannelList[0] + 1 end
table.insert(category.ChannelList,channel) local channel = { Title=sname, Service=sid, Request = '?'..Request.."&pids="..pids, Tracks=tracks }
local gname = pname
if isradio then
gname = "Radio - "..gname
end
if not isradio or (include_radio > 0) then
local group = GetGroup(ChannelList,gname)
if group then
table.insert(group.ChannelList,channel)
end
end end
break break
end end
@ -147,9 +199,9 @@ if tl.SourceList then
elseif par == "APIDS" then elseif par == "APIDS" then
local track local track
for track in val:gmatch("%d+") do for track in val:gmatch("%d+") do
tracks[0] = tracks[0] + 1
table.insert(tracks,tonumber(track)) table.insert(tracks,tonumber(track))
end end
tracks[0] = #tracks
end end
end end
elseif line:sub(1,5) == "TUNE:" then elseif line:sub(1,5) == "TUNE:" then
@ -161,15 +213,28 @@ if tl.SourceList then
end end
end end
end end
end
local encode = newencoder() for _,group in ipairs(ChannelList.GroupList) do
cl = encode(ChannelList) if sort then
table.sort(group.ChannelList,cmp_title)
if cl then end
local f = io.open("/config/ChannelList.json","w+") group.ChannelList[0] = #group.ChannelList
if f then
f:write(cl)
f:close()
end end
if sort then
table.sort(ChannelList.GroupList,cmp_title)
end
ChannelList.GroupList[0] = #ChannelList.GroupList
local encode = newencoder()
cl = encode(ChannelList)
if cl then
local f = io.open(outfile,"w+")
if f then
f:write(cl)
f:close()
end
end
end end