webif/var/mongoose/cgi-bin/browse.jim

250 lines
5.6 KiB
Plaintext
Raw Normal View History

#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/ts.class
source /mod/var/mongoose/lib/pretty_size
puts "Content-Type: text/html"
puts ""
set ignore {.nts .thm .hmt .hmi}
set include {.ts .avi .mpg .wmv .mkv}
cgi_input
#cgi_dump
#set env(REQUEST_URI) ''
#set _cgi(dir) "/media/My Video/Chuggington"
proc directory {file bfile} {
puts "<div class=va>"
puts "<a href=$::env(REQUEST_URI)?dir=[cgi_quote_url $file]>"
puts "<img border=0 class=va src=/images/711_1_09_Media_Folder.png>"
regsub -all " +" $bfile "" tbfile
puts "$bfile</a><span class=filesize id=\"$tbfile\">
</span></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 741_1_10_Video_Title.png
set pad 0
set newpad "top: -6; left: 4;"
} else {
set type gen
set ts 0
set img 743_4_10_Video_Xvid_File.png
set pad "2"
set newpad "top: -2; left: 2;"
}
puts "
<div class=\"va bf\" id=[incr i]>
<a class=bf file=\"$file\" type=$type href=#>
"
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} {
# Overlay the new image over the media one.
puts "
<span style=\"position: relative; left: 0; top 0;
padding: $pad\">
<img class=va border=0 width=45 src=/images/$img
style=\"padding: $pad;
position: relative; top: 0; left: 0\">
<img class=va border=0
src=/images/743_1_10_Video_New.png
style=\"position: absolute; $newpad
width: 18\">
</span>
"
} else {
puts "
<img class=va border=0 width=45 src=/images/$img
style=\"padding:$pad\">
"
}
puts "
$bfile
</a>
"
# Size
puts "<span class=filesize> ($sz) </span>"
# Icons
set locked 0
if {$type eq "ts"} {
# HD / SD
if {[$ts get definition] eq "HD"} {
set img "172_1_00_HD"
} else {
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} {
puts "<img class=va
src=/images/749_1_26_Video_Encryption.png
height=21>"
}
# Guidance
if {[$ts flag "Guidance"] > 0} {
puts "<img class=va
src=/images/174_1_26_GuidancePolicy.png
height=21>"
}
}
# Opt+ button
puts "
<a href=#>
<img class=\"opt va\" border=0 width=45 type=$type did=$i
locked=$locked
src=/images/181_1_00_Help5_OPT_Plus.png>
</a>
<div class=\"results blood\" style=\"margin: 0 0 0 5em\"></div>
"
puts "</div>"
}
if {[dict exists $_cgi dir]} {
set dir [dict get $_cgi dir]
} else {
set dir "/media/My Video"
}
######################################################################
# Render web page
source /mod/var/mongoose/html/lib/header.jim
puts {
<link href=/css/jquery.contextMenu.css rel=stylesheet type=text/css />
<script type="text/javascript" src="/js/jquery.contextMenu.js"></script>
<ul id=optmenu class=contextMenu>
<li><a href=#delete>Delete</a></li>
<li><a href=#lock>Toggle Lock</a></li>
<li><a href=#rename>Rename</a></li>
<li><a href=#download>Download</a></li>
</ul>
<div id=renameform title="Rename media file" style="display: none">
<form id=renameform_form>
<input type=hidden name="renameorig" id="renameorig" value="">
<input type=hidden name="titleorig" id="titleorig" value="">
<table border=0>
<tr>
<th>
<label for="rename">
<b>New Filename</b>
</label>
</th>
<td>
<input type=text name="rename" id="rename"
value="" size=70 maxlength=255
class="text ui-widget-content ui-corner-all">
</td>
</tr>
<tr style="display: none" class=tstype>
<th>
<label for="renametitle" style="padding-top: 0.5em">
<b>New EPG Title</b>
</label>
</th>
<td>
<input type=text name="renametitle" id="renametitle"
value="" size=70 maxlength=48
class="text ui-widget-content ui-corner-all">
</td>
</tr>
<tr style="display: none" class=tstype>
<td colspan=2 id=synopsis style="font-style: italic"></td>
</tr>
</table>
</form>
</div>
<div id=dialogue></div>
<div id=confirm title="Confirmation Required"></div>
<script type=text/javascript src=/cgi-bin/browse/browse.js></script>
}
puts "<span style=\"display:none\" id=dir>$dir</span>"
# Breadcrumb path
puts "
<fieldset style=\"margin: 1em\">
<legend style=\"font-size: 1.5em; padding: 0 0.5em 0.5em 0.5em;\">
"
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 src=/images/711_3_09_Media_Folder_UP.png class=va>
\[parent directory\]</a>
</div>
"
}
# Strip double slashes
regsub -all -- {\/+} "$dir/*" "/" dir
foreach file [lsort [glob -nocomplain "$dir"]] {
entry $file
}
puts "</fieldset>"
source /mod/var/mongoose/html/lib/footer.jim