-- 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 --プログラム予約は表示範囲のみ v.startTime=TimeWithZone(v.startTime) if v.eid~=65535 or (baseTime+date*24*3600<=v.startTime and v.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 programReservedStart=BinarySearchBound(rt,{onid=v.onid,tsid=v.tsid,sid=v.sid,eid=65535},rtComp) programReservedEnd=BinarySearchBound(rt,{onid=v.onid,tsid=v.tsid,sid=v.sid,eid=65535},rtComp,true) 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(' ') if not w.past then --範囲内のプログラム予約 rangeStart=j>1 and startTime rangeEnd=j<#v.et and TimeWithZone(v.et[j+1].startTime) for k=programReservedStart,programReservedEnd-1 do if (not rangeStart or rangeStart<=rt[k].startTime) and (not rangeEnd or rt[k].startTimeプ予 ') end end end --通常予約 reservedIndex=not w.past and BinarySearchBound(rt,w,rtComp) if not reservedIndex or reservedIndex>=programReservedStart or rt[reservedIndex].eid~=w.eid then reservedIndex=nil else --最後以外は「重予」(重複予約) while reservedIndex+1重予 ') reservedIndex=reservedIndex+1 end end ct:Append((reservedIndex 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'))