-
Notifications
You must be signed in to change notification settings - Fork 17
/
epg.html
333 lines (290 loc) · 15.3 KB
/
epg.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
-- vim:set ft=lua:
dofile(mg.script_name:gsub('[^\\/]*$','')..'epg.lua')
show=mg.get_var(mg.request_info.query_string,'show')
tab=GetVarInt(mg.request_info.query_string,'tab',0,#NetworkIndex()) or 0
date=GetVarInt(mg.request_info.query_string,'date',-10000,1000) or 0
hour=GetVarInt(mg.request_info.query_string,'hour',-1,27) or -1
--hour=-1で現在時刻-MARGIN_HOUR時間を基準
interval=GetVarInt(mg.request_info.query_string,'interval',0,100) or DEF_INTERVAL
CH_COUNT=GetVarInt(mg.request_info.query_string,'chcount') or DEF_CH_COUNT
pageIndex=GetVarInt(mg.request_info.query_string,'page',0,100000) or 0
--UTC+9の今日の始まりの日付。現在時刻が深夜4時までは前日になることに注意
baseDate=math.floor((utc9Now-4*3600)/24/3600)
if date==0 then
m={(mg.get_var(mg.request_info.query_string,'date') or ''):match('^(%d%d%d%d)%-(%d?%d)%-(%d?%d)$')}
if #m==3 then
date=math.floor(TimeWithZone({year=m[1],month=m[2],day=m[3]})/24/3600)-baseDate
end
end
Hour=hour<0 and math.floor(((utc9Now%(24*3600))/3600)-MARGIN_HOUR)%24 or hour
if Hour<4-(hour<0 and MARGIN_HOUR or 0) then Hour=Hour+24 end
pageDate=baseDate+date
pageTime=(pageDate*24+Hour)*3600
Date=os.date('!*t', pageDate*24*3600)
NOW=pageTime<utc9Now and utc9Now<pageTime+interval*3600
function hrefGene(href)
href=href or {}
if type(href)=='number' then
href={
date=math.floor((href-4*3600)/24/3600)-baseDate,
hour=math.floor(href%(24*3600)/3600)
}
end
local s='?tab='..(href.tab or tab)
..'&date='..(href.date or date)
..((hour>=0 or href.hour and href.hour>=0) and '&hour='..(href.hour or hour) or '')
..((href.chpage~=0 and (pageIndex~=0 or href.chpage)) and '&page='..(href.chpage or pageIndex) or '')
..(CH_COUNT~=DEF_CH_COUNT and '&chcount='..CH_COUNT or '')
..(interval~=DEF_INTERVAL and '&interval='..interval or '')
return s
end
edcb.htmlEscape=15
rt={}
for i,v in ipairs(edcb.GetReserveData()) do
rt[v.onid..'-'..v.tsid..'-'..v.sid..'-'..v.eid]=v.reserveID
end
minTime=nil
maxTime=nil
st,NetworkList={},{}
for i,v in ipairs(NetworkIndex()) do
NetworkList[i]=false
end
for i,v in ipairs(CustomServiceList()) do
if ONESEG or not v.partialReceptionFlag then
NetworkList[NetworkIndex(v)]=true
end
if tab==NetworkIndex(v)-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))
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
--表示範囲の番組だけ取得する
st[#st].et=edcb.EnumEventInfo({{onid=v.onid, tsid=v.tsid, sid=v.sid}}, {startTime=os.date('!*t',pageTime-24*3600), durationSecond=(interval+24)*3600}) or {}
for j,w in ipairs(edcb.EnumEventInfoArchive and
edcb.EnumEventInfoArchive({{onid=v.onid, tsid=v.tsid, sid=v.sid}}, {startTime=os.date('!*t',pageTime-24*3600), durationSecond=(interval+24)*3600}) or {}) do
w.past=true
table.insert(st[#st].et, w)
end
table.sort(st[#st].et, function(a,b) return os.time(a.startTime)<os.time(b.startTime) end)
end
end
ct={
title='番組表',
css=EpgCssTemplate(),
js=EpgJsTemplate(pageTime-9*3600,NOW,date==0,(NOW and pageTime+(interval-9)*3600 or false)),
menu=EpgMenuTemplate(true),
progres=true,
macro=sidePanel,
searchlinks=true
}
ct.subheader='<div id="subheader">\n'
..'<nav class="mdl-navigation">\n'
..'<div class="mdl-layout-spacer"></div>\n'
..'<div class="dividers navigation__item navigation__icon"><a class="mdl-button mdl-js-button mdl-button--icon mdl-button--colored" '
..(NOW and 'id="now' or 'href="epg.html'..hrefGene({date=0,hour=-1})..'"')
..'"><i class="material-icons">radio_button_checked</i></a></div>\n'
..'<div id="onid" class="pulldown dividers navigation__item mdl-color-text--primary">'..(NetworkIndex()[tab+1] or '')..'</div>\n'
main={'<div class="menu"><ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu" for="onid">\n'} --メニューはサブヘッダーに入れたらダメゼッタイ
for i,v in ipairs(NetworkList) do
if v then
table.insert(main, '<li><a class="mdl-menu__item'..(tab==i-1 and ' mdl-color-text--accent' or '" href="epg.html'..hrefGene({tab=i-1,chpage=0}))..'">'..NetworkIndex()[i]..'</a></li>\n')
end
end
table.insert(main, '</ul>')
if 0<CH_COUNT then
n=0
for i,v in ipairs(st) do
if not v.subCh then
n=n+1
end
end
if CH_COUNT<n then
ct.subheader=ct.subheader..'<div id="page" class="pulldown dividers navigation__item mdl-color-text--primary">ページ '..(pageIndex+1)..'</div>\n'
table.insert(main, '<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu" for="page">\n')
for i=0, math.ceil(n/CH_COUNT-1) do
table.insert(main, '<li><a class="mdl-menu__item'..(pageIndex==i and ' mdl-color-text--accent' or '" href="epg.html'..hrefGene({chpage=i}))..'">ページ '..(i+1)..'</a></li>\n')
end
table.insert(main, '</ul>\n')
end
end
if minTime then
if minTime>=pageTime then
prev='disabled'
else
prev='href="epg.html'..hrefGene(pageTime-(interval==25 and 24-(hour<0 and MARGIN_HOUR or 0) or interval)*3600)..'"'
end
if maxTime<pageTime+interval*3600 then
next='disabled'
else
next='href="epg.html'..hrefGene(pageTime+(interval==25 and 24+(hour<0 and MARGIN_HOUR or 0) or interval)*3600)..'"'
end
ct.subheader=ct.subheader..'<div class="navigation__item navigation__icon right_no_pad"><a class="mdl-button mdl-js-button mdl-button--icon mdl-button--colored" '..prev..'><i class="material-icons">chevron_left</i></a></div>\n'
..'<div id="date" class="pulldown navigation__item mdl-color-text--primary">'..Date.month..'/'..Date.day..'('..({'日','月','火','水','木','金','土'})[Date.wday]..')'..'</div>\n'
..'<div class="dividers navigation__item navigation__icon left_no_pad"><a class="mdl-button mdl-js-button mdl-button--icon mdl-button--colored" '..next..'><i class="material-icons">chevron_right</i></a></div>\n'
table.insert(main, '<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu" for="date">\n'
..(UserAgentSP() and '<li><div id ="forSP" class="mdl-menu__item">日付指定</div></li>\n<li style="opacity:0;position:absolute;">' or '<li>') --無理やりだがスマホで動くように応急処置
..'<div class="mdl-menu__item"><form id="date_input" action="epg.html">'
..(tab~=0 and '<input type="hidden" name="tab" value="'..tab..'">' or '')
..'<div class="has-icon mdl-textfield mdl-js-textfield"><i class="material-icons">calendar_today</i><input class="mdl-textfield__input" id="dateFormat" type="date" name="date" value="'..os.date('%Y-%m-%d', pageDate*24*3600)..'" min="'..os.date('%Y-%m-%d', minTime)..'" max="'..os.date('%Y-%m-%d', maxTime)..'"><label class="mdl-textfield__label" for="dateFormat"></label></div>'
..'<input type="hidden" name="hour" value="4">'
..(pageIndex~=0 and '<input type="hidden" name="page" value="'..pageIndex..'">' or '')
..(CH_COUNT~=DEF_CH_COUNT and '<input type="hidden" name="chcount" value="'..CH_COUNT..'">' or '')
..(interval~=DEF_INTERVAL and '<input type="hidden" name="interval" value="'..interval..'">' or '')
..'</form></div></li>\n')
minTime=math.max(minTime, pageTime-2*24*3600)
maxTime=math.min(maxTime, minTime+9*24*3600) -- 10日間
for i=math.floor((minTime-4*3600)/24/3600),math.floor((maxTime-4*3600)/24/3600) do
d=os.date('!*t', i*24*3600)
table.insert(main, '<li><a class="mdl-menu__item'..(i*24*3600<minTime_ and ' past' or '')
..(i-baseDate==date and ' mdl-color-text--accent' or '" href="epg.html'..hrefGene({date=i-baseDate,hour=4}))
..'">'..d.month..'/'..d.day..'('..({'日','月','火','水','木','金','土'})[d.wday]..')'..'</a></li>\n')
end
ct.subheader=ct.subheader..'<div id="time" class="pulldown navigation__item mdl-color-text--primary">時間</div>\n'
table.insert(main, '</ul>\n<ul class="widemenu text-right mdl-menu mdl-menu--bottom-right mdl-js-menu" for="time">\n')
n=interval>=25 and Hour or 4
for i=n, n+math.max(interval-2, 23) ,2 do
j=i%24
if j<4 then j=j+24 end
if Hour<=i and i<Hour+interval then
d=os.date('!*t', (pageDate*24+i)*3600)
table.insert(main, '<li><a class="scroller mdl-menu__item'..(interval<25 and ' mdl-color-text--accent' or '')..'" href="#H'..i..'">'..(d.day~=Date.day and (j==4 or j==5) and d.day..'日('..({'日','月','火','水','木','金','土'})[d.wday]..') ' or '')..j..'時</a></li>\n')
else
table.insert(main, '<li><a class="mdl-menu__item" href="epg.html'..hrefGene({hour=i})..'">'..j..'時</a></li>\n')
end
end
table.insert(main, '</ul>\n')
end
ct.subheader=ct.subheader
..'<div class="space navigation__item"></div>\n'
..'</nav>\n</div>\n'
ct.side='<input type="checkbox" class="hidden" id="a">\n'
..'<label class="drop-down mdl-navigation__link" for="a">サービス</label>\n'
..'<ul>\n'
WIDE={
--少し拡幅する
['32391-32391-23608']=true, --MX
}
ctt,Head={},{}
n=0
pagemin=pageIndex*CH_COUNT+1
pagemax=(pageIndex+1)*CH_COUNT
SubChConcat=tonumber(edcb.GetPrivateProfile('GUIDE','subChConcat',true,INI))~=0
for i,v in ipairs(st) do
if not v.subCh then
n=n+1
end
if CH_COUNT==0 or pagemin<=n and n<=pagemax then
op={service_name=v.service_name}
if not v.subCh then
left=0
for j=i,#st+1 do
if j>#st or j>i and not st[j].subCh then
column=j-i
id=v.onid..'-'..v.tsid..'-'..v.sid
ct.side=ct.side..'<li><label class="mdl-switch mdl-js-switch" for="c-'..id..'"><input type="checkbox" id="c-'..id..'" class="stationToggle mdl-switch__input" value="'..id..'"'..(v.hide and '' or ' checked')..'><span class="mdl-switch__label">'..v.service_name..'</span></label></li>\n'
table.insert(Head, '<a class="station id-'..id..(SubChConcat and WIDE[id] and ' wide' or '')..' mdl-typography--body-2 mdl-color-text--primary-contrast"'..(v.hide and ' style="display:none;"' or '')..' href="epgweek.html?id='..v.onid..'-'..v.tsid..'-'..v.sid..(interval~=25 and '&interval='..interval or '')..'"><img src="'..PathToRoot()..'api/logo?onid='..v.onid..'&sid='..v.sid..'">'..v.service_name..'</a>\n')
table.insert(ctt, '<div class="station id-'..id..(SubChConcat and WIDE[id] and ' wide' or '')..'"'..(v.hide and ' style="display:none;"' or '')..' data-service_id="'..id..'" data-service="'..v.service_name..'">\n')
break
end
end
else
left=left+1
end
lastPx=0
total=0
table.insert(ctt, '<div id="sid-'..v.sid..'">')
for j,w in ipairs(v.et) do
startTime=TimeWithZone(w.startTime)
startPx=math.min(math.floor((startTime-pageTime)/60)*ONE_MIN_PX, ONE_MIN_PX*60*interval)
endTime=w.durationSecond and startTime+w.durationSecond or (j<#v.et and TimeWithZone(v.et[j+1].startTime) or startTime) --終了時間未定
endPx=math.min(math.floor((endTime-pageTime)/60)*ONE_MIN_PX, ONE_MIN_PX*60*interval)
if startPx-lastPx>0 then
if not v.subCh then
table.insert(ctt, '<div class="cell" data-endtime="'..(startTime-9*3600)..'" style="height:'..(startPx-lastPx)..'px;"><div class="content-wrap nothing"><div class="content'..(NOW and date==0 and startTime<=utc9Now and ' end' or '')..'"></div></div></div>\n')
end
total=total+startPx-lastPx
lastPx=startPx
end
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=1
for k=i+1,#st do
span=false
if st[k].subCh 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+1
span=true
break
end
end
end
if not span then
break
end
end
op.url='epginfo.html'..hrefGene()..'&id='..w.onid..'-'..w.tsid..'-'..w.sid..'-'..(w.past and startTime or w.eid)
table.insert(ctt, CellTemplate(w, op))
total=total+endPx-lastPx
lastPx=endPx
end
end
end
if not v.subCh and total<interval*60*ONE_MIN_PX then
table.insert(ctt, '<div class="cell" style="height:'..(interval*60*ONE_MIN_PX-total)..'px;top:'..total..'px;"><div class="content-wrap nothing"><div class="content"></div></div></div>\n')
end
table.insert(ctt, '</div>')
if i==#st or not st[i+1].subCh then
table.insert(ctt, '</div>\n')
end
elseif n>pagemax then
break
end
end
ct.side=ct.side..'</ul>\n'
..'<input type="checkbox" class="hidden" id="b">\n'
..'<label class="drop-down mdl-navigation__link" for="b">ジャンル</label>\n'
..'<ul>\n<li><label class="mdl-radio mdl-js-radio" for="g-all"><input type="radio" id="g-all" class="genreToggle mdl-radio__button" name="genreToggle" value="all" checked><span class="mdl-radio__label">すべて</span></label></li>\n'
for i=0,15 do
nibble1=edcb.GetGenreName(i*256+255)
if nibble1~='' then
ct.side=ct.side..'<li><label class="mdl-radio mdl-js-radio" for="g-'..(i*256+255)..'"><input type="radio" id="g-'..(i*256+255)..'" class="genreToggle mdl-radio__button" name="genreToggle" value=".'..CATEGORY[i+1]..'"><span class="mdl-radio__label">'..nibble1..'</span></label></li>\n'
end
end
ct.side=ct.side..'</ul>\n<div class="drawer-separator"></div>\n'
table.insert(main, '</div><main class="sidePanel-container mdl-layout__content">\n'
.. SidePanelTemplate()
..'<div id="tv-guide-container"><div id="tv-guide">'
..'<div id="tv-guide-header" class="mdl-color--primary mdl-shadow--4dp">\n<div class="hour-container"></div>\n'..table.concat(Head)..'</div>\n'
..'<div id="tv-guide-main">\n'
..'<div class="hour-container mdl-color-text--white mdl-shadow--2dp">\n')
for i=Hour,Hour+interval-1 do
j=i%24
d=os.date('!*t', ((pageDate*24)+i)*3600)
table.insert(main, '<div id="H'..i..'" class="hour t'..j..'"><tt>'..(j==4 and Date.day~=d.day and d.day..'日' or '')..(j<4 and j+24 or j)..'時</tt></div>\n')
end
ct.main=table.concat(main)..(NOW and '<div id="line"><span></span></div>' or '')
..'</div>\n'
..table.concat(ctt)
..'</div>\n</div></div>\n'
..'<form id="autoepg" method="POST" action="autoaddepginfo.html?epg=&tab='..tab..'&date='..date..(hour>=0 and '&hour='..hour or '')..(interval~=25 and '&interval='..interval or '')..(pageIndex~=0 and '&chpage='..pageIndex or '')..(CH_COUNT~=DEF_CH_COUNT and '&chcount='..CH_COUNT or '')..'">\n'
..'<input type="hidden" name="ctok" value="'..CsrfToken('autoaddepginfo.html')..'">\n'
..'<input type="hidden" name="andKey">\n'
..'<input type="hidden" name="serviceList">\n'
..'</form>\n'
ct=Template(ct)
mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)..'\r\n'))