-- vim:set ft=lua: --1分あたりの番組高さ ONE_MIN_PX=2 --番組の最低表示高さ MINIMUM_PX=12 --サービスあたりの幅 SERVICE_PX=150 --時刻軸を入れる間隔 TIME_COLUMN=3 --番組を絞り込みたいときはNOTキーワードの先頭を"#EPG_CUST_1"にした自動EPG予約を作る dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua') ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE) ct:Append([=[ 番組表 - EDCB

番組表

]=]) 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() timezone=now-os.time(os.date('!*t',now)) 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) 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 minTime=minTime and os.time(mmt.minTime)>minTime and minTime or os.time(mmt.minTime) maxTime=maxTime and os.time(mmt.maxTime)minTime and minTime or os.time(mmt.minTime) maxTime=maxTime and os.time(mmt.maxTime)'..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+timezone-4*3600)/(24*3600))),math.min(baseDate+date+7,math.floor((maxTime+timezone-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') end end ct:Append('\n'..rowTail..'
\n') break end end else left=left+SERVICE_PX+2 end lastPx=0 for j,w in ipairs(v.et) do startTime=os.time(w.startTime)+timezone startPx=math.min(math.floor((startTime-baseTime-date*24*3600)/60)*ONE_MIN_PX, ONE_MIN_PX*60*25) endPx=math.min(math.floor((( w.durationSecond and startTime+w.durationSecond or (j<#v.et and os.time(v.et[j+1].startTime)+timezone or startTime) --終了時間未定 )-baseTime-date*24*3600)/60)*ONE_MIN_PX, ONE_MIN_PX*60*25) if startPx-lastPx>0 then lastPx=startPx end endPx=lastPx+math.max(endPx-lastPx, 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=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+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
\n'..(#st==0 and '' or pageNav2..pageNav)..[=[ ]=]) ct:Finish() mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len)..(ct.gzip and 'Content-Encoding: gzip\r\n' or '')..'\r\n'))