-- 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
--フォルダが1つのときはライブラリリストを省略
index=#LIBRARY_LIST==1 and 1 or GetVarInt(mg.request_info.query_string,'i',1,#LIBRARY_LIST)
if index then
dir=DocumentToNativePath(LIBRARY_LIST[index])
if dir then
dirhash={}
for s in (mg.get_var(mg.request_info.query_string,'d') or ''):gmatch('[0-9a-f]+') do
dirhash[#dirhash+1]=s
end
--3階層まで
if #dirhash<=3 then
dirname=LIBRARY_LIST[index]
for i,v in ipairs(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(w.name)==v 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
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)}
hash=mg.get_var(mg.request_info.query_string,'h')
if not hash then
sort=mg.get_var(mg.request_info.query_string,'s') or 'dd'
queryParent=#dirhash>0 and '?i='..index..(#dirhash>1 and '&d='..table.concat(dirhash,',',1,#dirhash-1) or '') or ''
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<3 and not v.name:find('^%.') then
ff[#ff+1]=v
end
end
if sort=='da' then
table.sort(ff,function(a,b) return os.time(a.mtime)os.time(b.mtime) end)
elseif sort=='sa' then
table.sort(ff,function(a,b) return a.sizeb.size end)
elseif sort=='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(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='?i='..index..(#dirhash>0 and '&d='..table.concat(dirhash,',') or '')
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))
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,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.caption,xq.jikkyo,{ofssec=fsec*(xq.offset or 0)/100,fast=xq.fast}))
if xq.tslive then
ct:Append(TsliveScriptTemplate(xq.autoCinema))
elseif ALLOW_HLS then
ct:Append(HlsScriptTemplate('xcode.lua'))
end
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([=[
]=])
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'))