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-24 12:58:42 +01:00
|
|
|
local function CompareTitle(a,b)
|
|
|
|
if a.Order then
|
|
|
|
if b.Order then
|
|
|
|
if a.Order == b.Order then
|
|
|
|
return a.Title < b.Title
|
|
|
|
else
|
|
|
|
return a.Order < b.Order
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
elseif b.Order then
|
|
|
|
return false
|
|
|
|
end
|
2016-01-12 20:14:38 +01:00
|
|
|
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
|
|
|
|
2016-01-24 12:58:42 +01:00
|
|
|
local CIMappings = {}
|
|
|
|
|
|
|
|
if tl.CIMapList then
|
|
|
|
local CIMap
|
|
|
|
local ID
|
|
|
|
for _,CIMap in ipairs(tl.CIMapList) do
|
|
|
|
for _,ID in ipairs(CIMap.CIMappings) do
|
|
|
|
CIMappings[ID] = CIMap
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local ChannelOverwrites = {}
|
|
|
|
if tl.ChannelOverwriteList then
|
|
|
|
local ChannelOverwrite
|
|
|
|
for _,ChannelOverwrite in ipairs(tl.ChannelOverwriteList) do
|
|
|
|
ChannelOverwrites[ChannelOverwrite.ID] = ChannelOverwrite
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
local ChannelList = {}
|
|
|
|
ChannelList.GroupList = {}
|
|
|
|
|
2016-01-24 12:58:42 +01:00
|
|
|
if tl.GroupList then
|
|
|
|
local Group
|
|
|
|
local Order
|
|
|
|
for _,Group in ipairs(tl.GroupList) do
|
|
|
|
local g = GetGroup(ChannelList,Group.Title)
|
|
|
|
if Group.Order then
|
|
|
|
g.Order = Group.Order
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
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-24 12:58:42 +01:00
|
|
|
local Source
|
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 = ""
|
2016-01-08 01:47:27 +01:00
|
|
|
if Source.DVBType == "S" then
|
2016-01-24 12:58:42 +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-24 12:58:42 +01:00
|
|
|
local Options = SourceOptions
|
|
|
|
if Transponder.UseNIT then
|
|
|
|
Options = SourceOptions.."--use_nit "
|
|
|
|
end
|
|
|
|
|
2016-01-07 17:50:38 +01:00
|
|
|
print("--------------------------------------------------------------")
|
2016-01-24 12:58:42 +01:00
|
|
|
print('octoscan '..Options..Params..' '..ipAddr)
|
|
|
|
local octoscan = io.popen('octoscan '..Options..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 = "?"
|
2016-01-20 14:28:34 +01:00
|
|
|
local onid = 0
|
|
|
|
local tsid = 0
|
2016-01-07 17:50:38 +01:00
|
|
|
local sid = 0
|
|
|
|
local pids = ""
|
2016-01-12 20:14:38 +01:00
|
|
|
local tracks= { }
|
2016-02-01 18:50:50 +01:00
|
|
|
local isradio = nil
|
2016-01-12 20:14:38 +01:00
|
|
|
local isencrypted = false
|
2016-02-01 18:50:50 +01:00
|
|
|
local hasepg = nil
|
2016-01-30 16:41:58 +01:00
|
|
|
if line == "SERVICE" then
|
2016-01-07 17:50:38 +01:00
|
|
|
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
|
2016-01-24 12:58:42 +01:00
|
|
|
--~ if isencrypted then
|
|
|
|
--~ all_pids = all_pids..",1"
|
|
|
|
--~ end
|
2016-01-12 20:14:38 +01:00
|
|
|
all_pids = all_pids..",16,17,18,20"
|
|
|
|
end
|
2016-01-24 12:58:42 +01:00
|
|
|
local cireq = ""
|
|
|
|
local ID = string.format("%s:%d:%d:%d",Source.Key,onid,tsid,sid)
|
|
|
|
if isencrypted then
|
|
|
|
local CIMap = CIMappings[ID]
|
|
|
|
if CIMap then
|
|
|
|
local pmt = pids:match("(%d+),?")
|
|
|
|
if pmt then
|
|
|
|
cireq = "&x_ci="..CIMap.Slot.."&x_pmt="..pmt.."."..sid
|
|
|
|
isencrypted = false
|
|
|
|
end
|
|
|
|
end
|
2016-01-12 20:14:38 +01:00
|
|
|
end
|
2016-01-24 12:58:42 +01:00
|
|
|
|
2016-01-20 14:28:34 +01:00
|
|
|
if pname == "" then
|
|
|
|
pname = Source.Title
|
|
|
|
end
|
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-24 12:58:42 +01:00
|
|
|
|
|
|
|
local Order = none
|
|
|
|
local ChannelOverwrite = ChannelOverwrites[ID]
|
|
|
|
if ChannelOverwrite then
|
|
|
|
Order = ChannelOverwrite.Order
|
|
|
|
if ChannelOverwrite.Group then
|
|
|
|
gname = ChannelOverwrite.Group
|
|
|
|
end
|
2016-01-30 16:41:58 +01:00
|
|
|
if ChannelOverwrite.Pids then
|
2016-01-31 23:10:40 +01:00
|
|
|
pids = ChannelOverwrite.Pids
|
2016-01-24 12:58:42 +01:00
|
|
|
end
|
|
|
|
if ChannelOverwrite.Title then
|
|
|
|
sname = ChannelOverwrite.Title
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #pids > 0 then
|
|
|
|
all_pids = all_pids..","..pids
|
|
|
|
end
|
|
|
|
local channel = { Title=sname,
|
|
|
|
Request = '?'..Request..cireq.."&pids="..all_pids,
|
|
|
|
Tracks=tracks,
|
2016-02-01 18:50:50 +01:00
|
|
|
ID=ID, Order=Order, Radio=isradio }
|
|
|
|
if not hasepg then
|
|
|
|
channel.NoEPG = true
|
|
|
|
end
|
2016-01-20 14:28:34 +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
|
2016-02-01 18:50:50 +01:00
|
|
|
elseif par == "EIT" then
|
|
|
|
if val:sub(2,2) == "1" then
|
|
|
|
hasepg = true
|
|
|
|
end
|
2016-01-07 17:50:38 +01:00
|
|
|
elseif par == "PNAME" then
|
|
|
|
pname = val
|
|
|
|
elseif par == "SNAME" then
|
|
|
|
sname = val
|
2016-01-20 14:28:34 +01:00
|
|
|
elseif par == "ONID" then
|
|
|
|
onid = tonumber(val)
|
|
|
|
elseif par == "TSID" then
|
|
|
|
tsid = tonumber(val)
|
2016-01-07 17:50:38 +01:00
|
|
|
elseif par == "SID" then
|
2016-01-20 14:28:34 +01:00
|
|
|
sid = tonumber(val)
|
2016-01-07 17:50:38 +01:00
|
|
|
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-20 14:28:34 +01:00
|
|
|
elseif par == "ENC" then
|
|
|
|
isencrypted = true
|
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
|
2016-01-24 12:58:42 +01:00
|
|
|
table.sort(group.ChannelList,CompareTitle)
|
|
|
|
end
|
|
|
|
for _,channel in ipairs(group.ChannelList) do
|
|
|
|
channel.Order = nil
|
2016-01-12 20:14:38 +01:00
|
|
|
end
|
|
|
|
group.ChannelList[0] = #group.ChannelList
|
|
|
|
end
|
|
|
|
if sort then
|
2016-01-24 12:58:42 +01:00
|
|
|
table.sort(ChannelList.GroupList,CompareTitle)
|
2016-01-12 20:14:38 +01:00
|
|
|
end
|
2016-01-24 12:58:42 +01:00
|
|
|
for _,group in ipairs(ChannelList.GroupList) do
|
|
|
|
group.Order = nil
|
|
|
|
end
|
|
|
|
|
2016-01-12 20:14:38 +01:00
|
|
|
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)
|
|
|
|
|
2016-01-20 14:28:34 +01:00
|
|
|
if outfile == "/config/ChannelList.json" then
|
|
|
|
os.execute("mv /config/ChannelList.json /config/ChannelList.bak")
|
|
|
|
end
|
2016-01-12 20:14:38 +01:00
|
|
|
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-30 16:41:58 +01:00
|
|
|
Report(ChannelCount,"Channels found")
|
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");
|