2016-01-07 17:50:38 +01:00
|
|
|
#!/usr/bin/lua
|
|
|
|
|
2016-01-09 19:57:54 +01:00
|
|
|
--
|
2016-01-07 17:50:38 +01:00
|
|
|
local newdecoder = require("lunajson.decoder")
|
|
|
|
local newencoder = require("lunajson.encoder")
|
|
|
|
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
local function GetIPAddr()
|
2016-01-07 17:50:38 +01:00
|
|
|
local myip = nil
|
|
|
|
local ifconfig = io.popen("ifconfig eth0")
|
|
|
|
if ifconfig then
|
|
|
|
local eth0 = ifconfig:read("*a")
|
2016-01-09 19:57:54 +01:00
|
|
|
ifconfig:close()
|
2016-01-07 17:50:38 +01:00
|
|
|
myip = string.match(eth0,"inet addr%:(%d+%.%d+%.%d+%.%d+)")
|
|
|
|
end
|
|
|
|
return myip
|
|
|
|
end
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
local function LoadTransponderList(infile)
|
2016-01-07 17:50:38 +01:00
|
|
|
local tl = nil
|
2016-01-12 20:14:38 +01:00
|
|
|
local f = nil
|
|
|
|
if infile then
|
|
|
|
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
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
2016-01-09 19:57:54 +01:00
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
if f then
|
|
|
|
local t = f:read("*a")
|
|
|
|
f:close()
|
|
|
|
local decode = newdecoder()
|
|
|
|
tl = decode(t)
|
|
|
|
end
|
|
|
|
return tl
|
|
|
|
end
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
local function GetGroup(ChannelList,Title)
|
2016-01-07 17:50:38 +01:00
|
|
|
local Group
|
|
|
|
for _,c in ipairs(ChannelList.GroupList) do
|
|
|
|
if c.Title == Title then
|
|
|
|
Group = c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not Group then
|
2016-01-12 20:14:38 +01:00
|
|
|
Group = { Title=Title, ChannelList = { } }
|
2016-01-07 17:50:38 +01:00
|
|
|
table.insert(ChannelList.GroupList,Group)
|
|
|
|
end
|
|
|
|
return Group
|
|
|
|
end
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
local function cmp_title(a,b)
|
|
|
|
return a.Title < b.Title
|
|
|
|
end
|
2016-01-07 17:50:38 +01:00
|
|
|
|
2016-01-15 16:51:01 +01:00
|
|
|
local function Report(count,Title)
|
|
|
|
local f = io.open("/tmp/doscan.lock/doscan.tmp","w+")
|
|
|
|
if f then
|
|
|
|
f:write(count..":"..Title)
|
|
|
|
f:close()
|
|
|
|
os.execute("mv /tmp/doscan.lock/doscan.tmp /tmp/doscan.lock/doscan.msg")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
local keys = {}
|
|
|
|
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
|
2016-01-15 16:51:01 +01:00
|
|
|
local restart_dms = nil
|
2016-01-12 20:14:38 +01:00
|
|
|
|
|
|
|
local a
|
|
|
|
for _,a in ipairs(arg) do
|
|
|
|
local par,val = a:match("(%a+)=(.+)")
|
|
|
|
if par == "key" then
|
2016-01-15 16:51:01 +01:00
|
|
|
local key,src = val:match("(%w+)%.(%d+)")
|
2016-01-12 20:14:38 +01:00
|
|
|
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
|
2016-01-15 16:51:01 +01:00
|
|
|
elseif par == "restartdms" then
|
|
|
|
restart_dms = val
|
2016-01-12 20:14:38 +01:00
|
|
|
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)
|
2016-01-07 17:50:38 +01:00
|
|
|
|
|
|
|
local ChannelList = {}
|
|
|
|
ChannelList.GroupList = {}
|
|
|
|
|
|
|
|
local Max = 999999
|
|
|
|
local Count = 0
|
2016-01-15 16:51:01 +01:00
|
|
|
local ChannelCount = 0
|
|
|
|
|
|
|
|
Report(ChannelCount,"*")
|
2016-01-07 17:50:38 +01:00
|
|
|
|
2016-01-09 19:57:54 +01:00
|
|
|
if tl.SourceList then
|
2016-01-07 17:50:38 +01:00
|
|
|
for _,Source in ipairs(tl.SourceList) do
|
2016-01-12 20:14:38 +01:00
|
|
|
if keys[Source.Key] then
|
2016-01-15 16:51:01 +01:00
|
|
|
Report(ChannelCount,Source.Title)
|
2016-01-12 20:14:38 +01:00
|
|
|
print("Scanning: "..Source.Title)
|
2016-01-09 19:57:54 +01:00
|
|
|
local SourceOptions = ""
|
|
|
|
if Source.UseNIT then
|
|
|
|
SourceOptions = SourceOptions.."--use_nit "
|
|
|
|
end
|
2016-01-08 01:47:27 +01:00
|
|
|
if Source.DVBType == "S" then
|
2016-01-12 20:14:38 +01:00
|
|
|
SourceOptions = '--src='..keys[Source.Key]
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
2016-01-09 19:57:54 +01:00
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
for _,Transponder in ipairs(Source.TransponderList) do
|
|
|
|
Count = Count + 1
|
|
|
|
if Count > Max then
|
|
|
|
break
|
|
|
|
end
|
2016-01-09 19:57:54 +01:00
|
|
|
|
|
|
|
local Params = ""
|
|
|
|
local p,v
|
|
|
|
for p,v in Transponder.Request:gmatch("(%a+)=([%w%.]+)") do
|
|
|
|
if p == "freq" then
|
|
|
|
Params = Params .. " --freq="..v
|
|
|
|
elseif p == "pol" then
|
|
|
|
Params = Params .. " --pol="..v
|
|
|
|
elseif p == "msys" then
|
|
|
|
Params = Params .. " --msys="..v
|
|
|
|
elseif p == "sr" then
|
|
|
|
Params = Params .. " --sr="..v
|
|
|
|
elseif p == "mtype" then
|
|
|
|
Params = Params .. " --mtype="..v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
print("--------------------------------------------------------------")
|
2016-01-09 19:57:54 +01:00
|
|
|
print('octoscan '..SourceOptions..Params..' '..ipAddr)
|
|
|
|
local octoscan = io.popen('octoscan '..SourceOptions..' '..Params..' '..ipAddr,"r")
|
2016-01-07 17:50:38 +01:00
|
|
|
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 = ""
|
2016-01-12 20:14:38 +01:00
|
|
|
local tracks= { }
|
2016-01-07 17:50:38 +01:00
|
|
|
local isradio = false
|
2016-01-12 20:14:38 +01:00
|
|
|
local isencrypted = false
|
2016-01-07 17:50:38 +01:00
|
|
|
if line == "BEGIN" then
|
|
|
|
while true do
|
|
|
|
line = octoscan:read("*l")
|
|
|
|
if not line then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
print(line)
|
|
|
|
if line == "END" then
|
2016-01-15 16:51:01 +01:00
|
|
|
local all_pids = "0"
|
2016-01-12 20:14:38 +01:00
|
|
|
if include_sitables then
|
|
|
|
if isencrypted then
|
|
|
|
all_pids = all_pids..",1"
|
|
|
|
end
|
|
|
|
all_pids = all_pids..",16,17,18,20"
|
|
|
|
end
|
|
|
|
if #pids > 0 then
|
2016-01-15 16:51:01 +01:00
|
|
|
all_pids = all_pids..","..pids
|
2016-01-12 20:14:38 +01:00
|
|
|
end
|
2016-01-15 16:51:01 +01:00
|
|
|
local channel = { Title=sname, Service=sid, Request = '?'..Request.."&pids="..all_pids, Tracks=tracks }
|
2016-01-12 20:14:38 +01:00
|
|
|
local gname = pname
|
2016-01-07 17:50:38 +01:00
|
|
|
if isradio then
|
2016-01-12 20:14:38 +01:00
|
|
|
gname = "Radio - "..gname
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
2016-01-15 16:51:01 +01:00
|
|
|
if (not isradio or (include_radio > 0)) and (not isencrypted or (include_encrypted > 0)) then
|
2016-01-12 20:14:38 +01:00
|
|
|
local group = GetGroup(ChannelList,gname)
|
|
|
|
if group then
|
|
|
|
table.insert(group.ChannelList,channel)
|
2016-01-15 16:51:01 +01:00
|
|
|
ChannelCount = ChannelCount + 1
|
|
|
|
Report(ChannelCount,sname)
|
2016-01-12 20:14:38 +01:00
|
|
|
end
|
2016-01-07 17:50:38 +01:00
|
|
|
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
|
|
|
|
table.insert(tracks,tonumber(track))
|
|
|
|
end
|
2016-01-12 20:14:38 +01:00
|
|
|
tracks[0] = #tracks
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
|
|
|
end
|
2016-01-09 19:57:54 +01:00
|
|
|
elseif line:sub(1,5) == "TUNE:" then
|
|
|
|
Request = line:sub(6)
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
octoscan:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
for _,group in ipairs(ChannelList.GroupList) do
|
|
|
|
if sort then
|
|
|
|
table.sort(group.ChannelList,cmp_title)
|
|
|
|
end
|
|
|
|
group.ChannelList[0] = #group.ChannelList
|
|
|
|
end
|
|
|
|
if sort then
|
|
|
|
table.sort(ChannelList.GroupList,cmp_title)
|
|
|
|
end
|
|
|
|
ChannelList.GroupList[0] = #ChannelList.GroupList
|
2016-01-07 17:50:38 +01:00
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
local encode = newencoder()
|
|
|
|
cl = encode(ChannelList)
|
|
|
|
|
|
|
|
if cl then
|
|
|
|
local f = io.open(outfile,"w+")
|
|
|
|
if f then
|
|
|
|
f:write(cl)
|
|
|
|
f:close()
|
|
|
|
end
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
2016-01-12 20:14:38 +01:00
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
end
|
2016-01-12 20:14:38 +01:00
|
|
|
|
2016-01-15 16:51:01 +01:00
|
|
|
os.execute("mv /tmp/doscan.lock/doscan.msg /tmp/doscan.msg")
|
|
|
|
|
|
|
|
if restart_dms then
|
|
|
|
os.execute("/etc/init.d/S92dms restart")
|
|
|
|
end
|
|
|
|
os.execute("rm -rf /tmp/doscan.lock");
|