forked from hummypkg/webif
4d3183ea61
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@592 2a923420-c742-0410-a762-8d5b09965624
347 lines
7.5 KiB
Plaintext
Executable File
347 lines
7.5 KiB
Plaintext
Executable File
#!/mod/bin/jimsh
|
|
|
|
package require cgi
|
|
source /mod/var/mongoose/lib/setup
|
|
require ts.class pretty_size system.class settings.class escape
|
|
|
|
puts "Content-Type: text/html"
|
|
puts ""
|
|
|
|
set nicesplice [system pkginst nicesplice]
|
|
set flatten [system pkginst flatten]
|
|
|
|
set ignore {.nts .thm .hmt .hmi}
|
|
set include {.ts .avi .mpg .mpeg .wmv .mkv .mp3 .mp4 .mov}
|
|
|
|
cgi_input
|
|
#cgi_dump
|
|
|
|
if {![dict exists $env REQUEST_URI]} {
|
|
set env(REQUEST_URI) ""
|
|
set _cgi(dir) "/media/My Video/"
|
|
}
|
|
|
|
if {![dict exists $env QUERY_STRING]} { set env(QUERY_STRING) "root" }
|
|
|
|
set order [cgi_get order -]
|
|
if {$order eq "-"} {
|
|
set order [[settings new] sortorder]
|
|
} else {
|
|
[settings new] sortorder $order
|
|
}
|
|
|
|
proc directory {file bfile} {
|
|
global flatten
|
|
|
|
regsub -all " +" $bfile "" tbfile
|
|
puts "<div class=va>"
|
|
puts "<img border=0 class=va id=\"img$tbfile\"
|
|
src=/images/711_1_09_Media_Folder.png>"
|
|
puts "<input class=\"fs fsdir\" type=checkbox>"
|
|
puts "<a class=dbf
|
|
href=\"$::env(REQUEST_URI)?dir=[cgi_quote_url $file]\"
|
|
file=\"[cgi_quote_url $file]\">"
|
|
puts "$bfile</a><span class=filesize id=\"$tbfile\">
|
|
</span>"
|
|
|
|
set noflat 0
|
|
if $flatten {
|
|
if {[string match {\[*\]} [file tail $file]]} { set noflat 1 }
|
|
if {[file exists "$file/.noflatten"]} {
|
|
set noflat 1
|
|
}
|
|
|
|
if $noflat {
|
|
puts "<img alt=\"No-flatten\" title=\"No-flatten\"
|
|
class=va src=/img/flat-tyre.png height=21>"
|
|
}
|
|
}
|
|
|
|
puts -nonewline "
|
|
<a href=#>
|
|
<img class=\"dopt va\" border=0 width=45 "
|
|
if $flatten { puts -nonewline "noflat=$noflat " }
|
|
puts "
|
|
src=/images/181_1_00_Help5_OPT_Plus.png>
|
|
</a>
|
|
"
|
|
|
|
puts "
|
|
<div class=\"results blood\" style=\"margin: 0 0 0 5em\"></div>
|
|
"
|
|
puts "</div>"
|
|
}
|
|
|
|
proc entry {file} {{i 0}} {
|
|
set bfile [file tail $file]
|
|
if {[string index $bfile 0] == "\025"} {
|
|
set bfile [string range $bfile 1 end]
|
|
}
|
|
if [file isdirectory "$file"] {
|
|
directory $file $bfile
|
|
continue
|
|
}
|
|
set ext [file extension $file]
|
|
if {$ext in $::ignore || $ext ni $::include} { continue }
|
|
|
|
file stat $file st
|
|
set sz [pretty_size $st(size)]
|
|
|
|
set base [file rootname $file]
|
|
|
|
if {$ext eq ".ts" && [file exists "${base}.nts"]} {
|
|
set type ts
|
|
set ts [ts fetch $file 1]
|
|
set img Video_TS
|
|
} else {
|
|
set type gen
|
|
set ts 0
|
|
set img Video_Other
|
|
}
|
|
|
|
set new 0
|
|
if {$type eq "ts"} {
|
|
if {[$ts flag "New"] > 0} { set new 1 }
|
|
} else {
|
|
if {![file exists "[file rootname $file].hmi"]} { set new 1 }
|
|
}
|
|
|
|
if {$new} { append img _New }
|
|
|
|
set fscl "fs"
|
|
if {$type eq "ts"} {
|
|
set fscl "fs fsts"
|
|
}
|
|
|
|
puts "
|
|
<div class=\"va bf\" id=[incr i]>
|
|
<img class=va border=0 src=/img/$img.png>
|
|
<input class=\"$fscl\" type=checkbox>
|
|
<a class=bf file=\"[cgi_quote_url $file]\" type=$type href=#>
|
|
$bfile
|
|
</a>
|
|
"
|
|
|
|
# Size
|
|
puts "<span class=filesize> ($sz) </span>"
|
|
|
|
# Icons
|
|
|
|
set locked 0
|
|
set encd 0
|
|
set odencd 1
|
|
set def unknown
|
|
set bx 0
|
|
if {$type eq "ts"} {
|
|
# HD / SD
|
|
if {[$ts get definition] eq "HD"} {
|
|
set def HD
|
|
set img "172_1_00_HD"
|
|
} else {
|
|
set def SD
|
|
set img "172_1_26_SD"
|
|
}
|
|
puts "<img class=va src=/images/$img.png height=21>"
|
|
|
|
# Locked
|
|
if {[$ts flag "Locked"] > 0} {
|
|
set locked 1
|
|
puts "<img class=va src=/images/178_1_00_Icon_Lock.png
|
|
height=21>"
|
|
}
|
|
|
|
# Encrypted
|
|
if {[$ts flag "Encrypted"] > 0} {
|
|
set encd 1
|
|
puts "<img class=va
|
|
src=/images/749_1_26_Video_Encryption.png
|
|
height=21>"
|
|
}
|
|
if {![$ts flag "ODEncrypted"]} {
|
|
puts "<img class=va src=/img/Decrypted.png height=21>"
|
|
set odencd 0
|
|
}
|
|
|
|
# Guidance
|
|
if {[$ts flag "Guidance"] > 0} {
|
|
puts "<img class=va
|
|
src=/images/174_1_26_GuidancePolicy.png
|
|
height=21>"
|
|
}
|
|
|
|
set bx [$ts get bookmarks]
|
|
}
|
|
|
|
# Opt+ button
|
|
|
|
puts "
|
|
<a href=#>
|
|
<img class=\"opt va\" border=0 width=45 type=$type did=$i
|
|
locked=$locked encd=$encd def=$def new=$new bx=$bx
|
|
odencd=$odencd
|
|
src=/images/181_1_00_Help5_OPT_Plus.png>
|
|
</a>
|
|
<div class=\"results blood\" style=\"margin: 0 0 0 5em\"></div>
|
|
"
|
|
puts "</div>"
|
|
}
|
|
|
|
set dir [cgi_get dir [system mediaroot]]
|
|
|
|
######################################################################
|
|
# Render web page
|
|
|
|
header
|
|
|
|
puts {
|
|
<link href=/css/jquery.contextMenu.css rel=stylesheet type=text/css />
|
|
<script type="text/javascript" src="/js/jquery.contextMenu.js"></script>
|
|
<link href=/css/jquery.bar.css rel=stylesheet type=text/css />
|
|
<script type="text/javascript" src="/js/jquery.bar.js"></script>
|
|
<script type=text/javascript src=/cgi-bin/browse/browse.js></script>
|
|
<link type=text/css rel=stylesheet href=/cgi-bin/browse/style.css />
|
|
}
|
|
|
|
source /mod/var/mongoose/cgi-bin/browse/assets.jim
|
|
|
|
puts "
|
|
<span style=\"display:none\" id=dir>$dir</span>
|
|
<fieldset class=cleft style=\"margin: 0 1em 1em 1em\">
|
|
<legend style=\"font-size: 1.5em; padding: 0 0.5em 0.5em 0.5em;\">
|
|
"
|
|
|
|
# Breadcrumb path
|
|
set stub ""
|
|
foreach part [split $dir /] {
|
|
if {$stub eq "/"} { set name $part } else { set name "/$part" }
|
|
append stub $name
|
|
puts "<a href=$env(REQUEST_URI)?dir=[cgi_quote_url $stub]>$name</a>
|
|
}
|
|
puts "<span class=filesize id=dirsize></span>"
|
|
puts "</legend>"
|
|
|
|
# Parent directory
|
|
set parent [join [lrange [split $dir /] 0 end-1] /]
|
|
if {$parent ne ""} {
|
|
puts "
|
|
<div class=va>
|
|
<a href=$env(REQUEST_URI)?dir=[cgi_quote_url $parent]>
|
|
<img border=0 src=/images/711_3_09_Media_Folder_UP.png class=va>
|
|
\[parent directory\]</a>
|
|
</div>
|
|
"
|
|
}
|
|
|
|
# Strip double slashes
|
|
regsub -all -- {\/+} "$dir/*" "/" dir
|
|
|
|
# Escape square brackets (for glob)
|
|
regsub -all {([\\[])} $dir {\\\1} dir
|
|
|
|
proc s_time {a b} {
|
|
set ad [file isdirectory $a]
|
|
set bd [file isdirectory $b]
|
|
|
|
if {$ad && !$bd} { return -1 }
|
|
if {$bd && !$ad} { return 1 }
|
|
if {$ad && $bd} {
|
|
if {$a < $b} { return -1 }
|
|
if {$a > $b} { return 1 }
|
|
return 0
|
|
}
|
|
|
|
file stat $a l
|
|
set at $l(ctime)
|
|
file stat $b l
|
|
set bt $l(ctime)
|
|
|
|
if {$at < $bt} { return -1 }
|
|
if {$at > $bt} { return 1 }
|
|
return 0
|
|
}
|
|
|
|
set files [glob -nocomplain $dir]
|
|
switch $order {
|
|
1 { set files [lsort -command s_time $files] }
|
|
default { set files [lsort $files] }
|
|
}
|
|
|
|
foreach file $files { entry $file }
|
|
|
|
puts "<a href=# id=selectall>Select all</a> | <a href=# id=deselectall>none</a>"
|
|
|
|
# Sort icons
|
|
puts "<div id=sortdiv>"
|
|
set sortlist {{0 sort_name name} {1 sort_date date}}
|
|
foreach sl $sortlist {
|
|
lassign $sl index img descr
|
|
|
|
if {$index} { puts " | " }
|
|
|
|
set tag "Currently sorting"
|
|
if {$order != $index} {
|
|
puts "
|
|
<a href=$env(REQUEST_URI)?$env(QUERY_STRING)&order=$index>"
|
|
set tag "Sort"
|
|
}
|
|
puts "<img class=va border=0 src=/img/$img.gif> $tag by $descr"
|
|
if {$order != $index} {
|
|
puts "</a>"
|
|
}
|
|
}
|
|
puts "</div>"
|
|
|
|
puts "</fieldset>"
|
|
|
|
puts {
|
|
<fieldset class=left style="margin: 0 1em 1em 1em">
|
|
<legend style="font-size: 1.5em; padding: 0 0.5em 0.5em 0.5em; color: #1e5bbd;">
|
|
File Clipboard
|
|
</legend>
|
|
<div id=clipboard>
|
|
<img src=/img/loading.gif> <i>Loading...</i>
|
|
</div>
|
|
</fieldset>
|
|
}
|
|
|
|
puts "<div class=brow>"
|
|
|
|
puts {
|
|
<button id=copy>Copy</button>
|
|
<button id=cut>Cut</button>
|
|
<button id=paste>Paste</button>
|
|
<button id=delete>Delete</button>
|
|
<button id=newdir>New Folder</button>
|
|
<div id=deletewait class=blood style="display: none">
|
|
<img src=/img/loading.gif>Deleting may take some time, please be patient...
|
|
</div>
|
|
}
|
|
|
|
# Join
|
|
if $nicesplice {
|
|
puts { <button id=join>Join</button> }
|
|
}
|
|
|
|
puts "</div><div class=brow style=\"margin-top: 3px\">"
|
|
|
|
# De-duplicate
|
|
|
|
puts {
|
|
<button id=dedup>De-duplicate/tidy this folder</button>
|
|
}
|
|
|
|
# Streamer file
|
|
|
|
if {[file exists /mnt/hd3/Streamer_down_file]} {
|
|
puts {
|
|
<button id=save_stream file=/mnt/hd3/Streamer_down_file>
|
|
Save last streamed content (e.g. iPlayer/YouTube)
|
|
</button>
|
|
}
|
|
}
|
|
|
|
puts "</div>"
|
|
|
|
footer
|
|
|