-- vim:set ft=lua: dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua') ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE) ct:Append(DOCTYPE_HTML4_STRICT..[=[

# 番組表

]=]) tab=GetVarInt(mg.request_info.query_string,'tab',0,4) or 0 cust=GetVarInt(mg.request_info.query_string,'cust',0,1) or 1 date=GetVarInt(mg.request_info.query_string,'date',-10000,1000) or 0 --dateクエリは今日(深夜4時区切り)を基準(=0)とする now=os.time() --UTC+9の今日の始まりの日付と時刻。現在時刻が深夜のときは前日の深夜4時になることに注意 baseDate=math.floor((now+(9-4)*3600)/(24*3600)) baseTime=(baseDate*24+4)*3600 rt={} for i,v in ipairs(edcb.GetReserveData()) do rt[v.onid..'-'..v.tsid..'-'..v.sid..'-'..v.eid]=true end showServices={} for i,v in ipairs(SelectChDataList(edcb.GetChDataList())) do if tab==0 and NetworkType(v.onid)=='地デジ' or tab==1 and NetworkType(v.onid)=='BS' or tab==2 and NetworkType(v.onid):find('^CS[12]') or tab==3 and NetworkType(v.onid)=='CS3' or tab==4 and NetworkType(v.onid)=='その他' then showServices[v.onid..'-'..v.tsid..'-'..v.sid]=1 end end if cust~=0 then for i,v in ipairs(edcb.EnumAutoAdd()) do if v.searchInfo.notKey:find('^#EPG_CUST_'..cust) or v.searchInfo.notKey:find('^:note:#EPG_CUST_'..cust) then key=v.searchInfo key.andKey=key.andKey:gsub('^^!{999}','') i=1 while i<=#key.serviceList do if showServices[key.serviceList[i].onid..'-'..key.serviceList[i].tsid..'-'..key.serviceList[i].sid]==1 then --サービス絞り込みにあるものは表示 showServices[key.serviceList[i].onid..'-'..key.serviceList[i].tsid..'-'..key.serviceList[i].sid]=2 i=i+1 else --表示されないので検索対象から除外 table.remove(key.serviceList,i) end end break end end end filterService={} minTime=nil maxTime=nil st={} edcb.htmlEscape=15 for i,v in ipairs(edcb.GetServiceList() or {}) do if showServices[v.onid..'-'..v.tsid..'-'..v.sid]==(key and 2 or 1) then table.insert(st, v) mmt=edcb.GetEventMinMaxTime(v.onid, v.tsid, v.sid) if mmt then maxTime=math.max(maxTime or 0,TimeWithZone(mmt.maxTime)) minTime=math.min(minTime or maxTime,TimeWithZone(mmt.minTime)) end mmt=edcb.GetEventMinMaxTimeArchive and edcb.GetEventMinMaxTimeArchive(v.onid, v.tsid, v.sid) if mmt then maxTime=math.max(maxTime or 0,TimeWithZone(mmt.maxTime)) minTime=math.min(minTime or maxTime,TimeWithZone(mmt.minTime)) end filterService[#filterService+1]={onid=v.onid, tsid=v.tsid, sid=v.sid} end end --表示範囲の番組だけ取得する range={startTime=os.date('!*t',baseTime+date*24*3600),durationSecond=25*3600} if key and edcb.SearchEpgArchive then et=edcb.SearchEpg(key,range) for i,v in ipairs(edcb.SearchEpgArchive(key,range)) do v.past=true et[#et+1]=v end else et=edcb.EnumEventInfo(filterService,range) or {} for i,v in ipairs(edcb.EnumEventInfoArchive and edcb.EnumEventInfoArchive(filterService,range) or {}) do v.past=true et[#et+1]=v end end for i,v in ipairs(st) do v.et={} for j,w in ipairs(et) do if v.onid==w.onid and v.tsid==w.tsid and v.sid==w.sid then v.et[#v.et+1]=w end end table.sort(v.et, function(a,b) return os.time(a.startTime)'..v..'')..'\n' end pageNav=pageNav..' ||\n' for i,v in ipairs({'すべて','カスタム'}) do pageNav=pageNav..' '..(cust==i-1 and v or ''..v..'')..'\n' end pageNav=pageNav..' ||\n' ..' 昼\n' ..' 夕\n' ..' 夜\n' ..'\n' pageNav2='' if minTime then for i=math.max(baseDate+date-7,math.floor((minTime-4*3600)/(24*3600))),math.min(baseDate+date+7,math.floor((maxTime-4*3600)/(24*3600))) do d=os.date('!*t', i*24*3600) pageNav2=pageNav2..' '..(i-baseDate~=date and '' or '') ..(i==baseDate and '' or '') ..(pageNav2=='' and d.month..'/' or '')..('%02d'):format(d.day)..({'日','月','火','水','木','金','土'})[d.wday] ..(i==baseDate and '' or '')..(i-baseDate~=date and '\n' or '\n') end pageNav2='
\n' end rowHead='' tcol=1 for i,v in ipairs(st) do if tcol==1 then rowHead=rowHead..'\n' end tcol=(tcol'..v.service_name..'\n' end rowTail='
\n'..rowHead..'
\n' rowHead='
\n'..rowHead..'
\n' colHead='\n' for i=4,28 do colHead=colHead..'
'..i..'
\n' end colHead=colHead..'\n' ct:Append(pageNav..pageNav2..'
\n

\n') ct:Append(rowHead..'
\n') tcol=1 for i,v in ipairs(st) do if tcol==1 then ct:Append(colHead) colHead=colHead:gsub(' id=[^ ]+', '') end tcol=(tcol#st or v.onid~=st[j].onid or v.tsid~=st[j].tsid then ct:Append('\n') break end end else left=left+EPG_SERVICE_PX+2 end lastPx=0 for j,w in ipairs(v.et) do startTime=TimeWithZone(w.startTime) startPx=math.min(math.floor((startTime-baseTime-date*24*3600)/60)*EPG_ONE_MIN_PX, EPG_ONE_MIN_PX*60*25) endPx=math.min(math.floor((( w.durationSecond and startTime+w.durationSecond or (j<#v.et and TimeWithZone(v.et[j+1].startTime) or startTime) --終了時間未定 )-baseTime-date*24*3600)/60)*EPG_ONE_MIN_PX, EPG_ONE_MIN_PX*60*25) if startPx-lastPx>0 then lastPx=startPx end endPx=lastPx+math.max(endPx-lastPx, EPG_MINIMUM_PX) if endPx-lastPx>2 then --貫かれるものでないか if not w.eventGroupInfo or #w.eventGroupInfo.eventDataList~=1 or w.eventGroupInfo.eventDataList[1].onid==w.onid and w.eventGroupInfo.eventDataList[1].tsid==w.tsid and w.eventGroupInfo.eventDataList[1].sid==w.sid and w.eventGroupInfo.eventDataList[1].eid==w.eid then --横にどれだけ貫くか width=EPG_SERVICE_PX for k=i+1,#st do span=false if v.onid==st[k].onid and v.tsid==st[k].tsid and w.eventGroupInfo then for l,x in ipairs(w.eventGroupInfo.eventDataList) do if v.onid==x.onid and v.tsid==x.tsid and st[k].sid==x.sid then width=width+EPG_SERVICE_PX+2 span=true break end end end if not span then break end end cont=w.contentInfoList and #w.contentInfoList>0 and math.floor(w.contentInfoList[1].content_nibble/256)%16 or 16 ct:Append(' ' ..(not w.past and rt[w.onid..'-'..w.tsid..'-'..w.sid..'-'..w.eid] and '予 ' or '') ..('%02d'):format(w.startTime.min)..' ' ..(w.shortInfo and w.shortInfo.event_name or ' ')..' \n') end lastPx=endPx end end if i==#st or v.onid~=st[i+1].onid or v.tsid~=st[i+1].tsid then ct:Append('\n') end end ct:Append('
\n'..rowTail..'

\n
\n'..(#st==0 and '' or pageNav2..pageNav)..[=[
]=]) ct:Finish() mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)..'\r\n'))