-- vim:set ft=lua:
dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua')
if JKRDLOG_PATH then
dofile(mg.script_name:gsub('[^\\/]*$','')..'jkconst.lua')
end
--<0:再生画面へのリンク, 0:DLリンク, 1:トランスコード再生画面, 2~3:直接再生画面(偶数:ローカルファイル再生)
vtag=GetVarInt(mg.request_info.query_string,'vtag') or -1
ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE)
ct:Append((vtag<=0 and DOCTYPE_HTML4_STRICT or '\n')..[=[
]=]..DefaultHeadContents()..[=[
ライブラリ - EDCB
]=])
dirname=nil
dirhash={}
for v in (mg.get_var(mg.request_info.query_string,'d') or ''):gmatch('[0-9a-f]+') do
if #dirhash==0 then
--先頭はルートフォルダの番号
v=GetVarInt('i='..v,'i',1,#LIBRARY_LIST)
if not v then break end
end
dirhash[#dirhash+1]=v
end
--フォルダが1つのときはライブラリリストを省略
if #dirhash==0 and #LIBRARY_LIST==1 then
dirhash[1]=1
end
--3階層まで
if #dirhash>0 and #dirhash<=4 then
dir=DocumentToNativePath(LIBRARY_LIST[dirhash[1]])
if dir then
dirname=LIBRARY_LIST[dirhash[1]]
for i=2,#dirhash do
found=false
for j,w in ipairs(edcb.FindFile(PathAppend(dir,'*'),0) or {}) do
if w.isdir and not w.name:find('^%.') and mg.md5(dirname..'/'..w.name)==dirhash[i] then
found=true
dir=PathAppend(dir,w.name)
dirname=dirname..'/'..w.name
break
end
end
if not found then
dirname=nil
break
end
end
end
end
thumbs={''}
queryParent=''
if not dirname then
ct:Append('
ライブラリリスト
\n
\n')
edcb.htmlEscape=15
for i,v in ipairs(LIBRARY_LIST) do
ct:Append('
\n')
else
tsx=edcb.GetPrivateProfile('SET','TSExt','.ts','EpgTimerSrv.ini')
xlist={tsx,table.unpack(MEDIA_EXTENSION_LIST)}
--各階層のソート設定。空要素は既定値
sort={}
for s in ((mg.get_var(mg.request_info.query_string,'s') or '')..','):gmatch('([adns]*)[^adns]') do
sort[#sort+1]=s
if #sort>=#dirhash then break end
end
while #sort>0 and sort[#sort]=='' do
table.remove(sort)
end
hash=mg.get_var(mg.request_info.query_string,'h')
if not hash then
sortParent={}
for i=1,math.min(#sort,#dirhash-1) do
sortParent[i]=sort[i]
end
while #sortParent>0 and sortParent[#sortParent]=='' do
table.remove(sortParent)
end
queryParent=#dirhash>1 and '?d='..table.concat(dirhash,',',1,#dirhash-1)..(#sortParent>0 and '&s='..table.concat(sortParent,',') or '') or ''
--既定値は上位のソート設定かModifiedの降順
so=(sort[#dirhash] or '')=='' and (sortParent[#sortParent] or 'dd') or sort[#dirhash]
for i=#sortParent+1,#dirhash-1 do
sortParent[i]=''
end
sortParent[#sortParent+1]='#'
ct:Append('
\n')
ff={}
for i,v in ipairs(edcb.FindFile(PathAppend(dir,'*'),0) or {}) do
if not v.isdir then
for j,ext in ipairs(xlist) do
if #v.name>#ext and IsEqualPath(v.name:sub(-#ext),ext) then
v.ists=ext==tsx
ff[#ff+1]=v
break
end
end
--3階層まで
elseif #dirhash<4 and not v.name:find('^%.') then
ff[#ff+1]=v
end
end
if so=='da' then
table.sort(ff,function(a,b) return CompareTime(a.mtime,b.mtime) end)
elseif so=='dd' then
table.sort(ff,function(a,b) return CompareTime(b.mtime,a.mtime) end)
elseif so=='sa' then
table.sort(ff,function(a,b) return a.sizeb.size end)
elseif so=='na' then
table.sort(ff,function(a,b) return a.nameb.name end)
end
edcb.htmlEscape=15
ct:Append('
'
..(#LIBRARY_LIST==1 and queryParent=='' and '/'..EdcbHtmlEscape(dirname)..'/ [index]'
or 'Parent directory of /'..EdcbHtmlEscape(dirname)..'/')..'
\n')
for i,v in ipairs(ff) do
v.mtime.sec=0
ct:Append('
'..FormatTimeAndDuration(v.mtime)
..'
'..(v.isdir and '' or math.floor(v.size/1048576)..'M')
..'
\n')
info=nil
for i,v in ipairs(xlist) do
for j,w in ipairs(edcb.FindFile(PathAppend(dir,'*'..v),0) or {}) do
if not w.isdir and mg.md5(dirname..'/'..w.name)==hash then
info=w
info.ists=v==tsx
break
end
end
if info then
break
end
end
edcb.htmlEscape=15
if info then
ref=dirname..'/'..info.name
queryParent='?d='..table.concat(dirhash,',')..(#sort>0 and '&s='..table.concat(sort,',') or '')
vttKind=info.ists and 'metadata' or TestVttKind(PathAppend(dir,info.name):gsub('%.[0-9A-Za-z]+$','')..'.vtt')
if vtag==2 or vtag==3 then
if vtag%2==0 then
ct:Append('
'..(info.ists and '(filename:'..mg.md5(ref:upper()):sub(27)..')' or '')..'
')
end
ct:Append(VideoWrapperBegin()
..''..VideoWrapperEnd(JKRDLOG_PATH and GetChatStreamNameList(),true)..'\n'..VideoScriptTemplate(info.ists,LoadAttachedChapters(PathAppend(dir,info.name))))
else
ct:Append((info.ists and '' or '')
..'/'..EdcbHtmlEscape(ref)..(info.ists and '' or '')
..'\n[OpenFile]'
..'\n[DL]')
end
if info.ists then
fsec,fsize=0,0
shiftable=false
f=edcb.io.open(PathAppend(dir,info.name),'rb')
if f then
fsec,fsize=GetDurationSec(f)
if vtag<=0 then
thumbs=ThumbnailTemplate(f,fsec,fsize,EdcbHtmlEscape(ref))
end
if JKRDLOG_PATH and vtag==1 then
--終端が現在時刻よりも昔ならば実況を逐次取得する必要はないのでshiftableにする
tot=GetTotAndServiceID(f)
shiftable=tot and tot+fsec+60\n'
..''..thumbs[1])
if vtag==1 then
src='xcode.lua?fname='..mg.url_encode(ref)..ConstructTranscodeQueries(xq)
ct:Append('\n'..VideoWrapperBegin()
..(xq.tslive and '' or
'')
..VideoWrapperEnd(JKRDLOG_PATH and GetChatStreamNameList(),shiftable)..'\n'..TranscodeScriptTemplate(false,xq,{fsec=fsec}))
end
else
ct:Append((vtag~=2 and vtag~=3 and '\n[Mux-to-TS]' or '')
..' ('..math.floor(info.size/1048576)..'M) \n')
end
ct:Append([=[
]=]..(vttKind and [=[
=1 and vtag<=3 and ' data-seek-target="vid-wrap"' or info.ists and ' data-seek-target="vid-form"' or '')..[=[>
]=] or ''))
end
ct:Append('
\n')
end
end
ct:Append([=[
]=])
for i=2,#thumbs do ct:Append(thumbs[i]) end
ct:Append([=[
]=])
ct:Finish()
mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)
..'Cross-Origin-Embedder-Policy: require-corp\r\n'
..'Cross-Origin-Opener-Policy: same-origin\r\n'
..'\r\n'))