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

329 lines
7.2 KiB
Plaintext
Raw Normal View History

#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/ts.class
puts "Content-Type: text/html"
puts ""
set ignore {nts thm hmt hmi}
set standard {avi mpg wmv mkv}
cgi_input
#cgi_dump
#set _cgi(tsfile) "/media/My Video/Family Guy/2.19._Excellence_in_Broadcasting.ts"
#set _cgi(action) "lock"
#set env(REQUEST_URI) ''
proc tsfile {file bfile} {{i 0}} {
set ts [ts fetch $file]
puts "
<div class=\"va tsfile\" id=[incr i]>
<a class=ts file=\"$file\" href=#>
<img class=va border=0 width=45
src=/images/741_1_10_Video_Title.png>
$bfile
</a>
"
if {[$ts get definition] eq "HD"} {
puts "<img class=va src=/images/172_1_00_HD.png height=21>"
} else {
puts "<img class=va src=/images/172_1_26_SD.png height=21>"
}
if {[$ts flag "Locked"] > 0} {
puts "<img class=va src=/images/178_1_00_Icon_Lock.png
height=21>"
}
puts "
<a class=tsopt file=\"$file\" href=#>
<img class=\"opt va\" border=0 width=45 did=$i
src=/images/181_1_00_Help5_OPT_Plus.png>
</a>
<div class=\"results blood\" style=\"margin: 0 0 0 5em\"></div>
</div>
"
}
proc genfile {file bfile} {
puts "
<div class=va>
<a href=#>
<img class=va border=0 width=45 style=\"padding: 0.3em 0\"
src=/images/743_4_10_Video_Xvid_File.png>
$bfile
</a>
</div>
"
}
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>"
puts "$bfile</a></div>"
}
proc entry {file} {
set bfile [lindex [split $file /] end]
if {[string index $bfile 0] == "\025"} {
set bfile [string range $bfile 1 end]
}
if [file isdirectory "$file"] {
directory $file $bfile
continue
}
regexp -- {\.([^.]+)$} "$file" allmatch ext
if {$ext eq "ts"} {
tsfile $file $bfile
continue
}
if {$ext in $::ignore} { continue }
if {$ext in $::standard} {
genfile $file $bfile
continue
}
}
if {[dict exists $_cgi tsfile]} {
set file [dict get $_cgi tsfile]
set ts [ts fetch $file]
if {[dict exists $_cgi action]} {
switch [dict get $_cgi action] {
entry {
entry $file
}
delete {
if {[$ts delete]} {
puts "Successfully deleted $file."
} else {
puts "Problem deleting $file, [$ts get error]"
}
}
lock {
set action lock
if {[$ts flag "Locked"]} { set action unlock }
if {[$ts $action]} {
puts "Successfully [set action]ed $file."
} else {
puts "Problem [set action]ing $file,
[$ts get error]"
}
}
}
exit
}
source /mod/var/mongoose/lib/epg.class
puts "
<table class=keyval>
<tr>
<th>Title</th>
<td>[$ts get title]</td>
</tr><tr>
<th>Synopsis</th>
<td>[$ts get synopsis]</td>
</tr><tr>
<th>Definition</th>
<td>
"
if {[$ts get definition] eq "HD"} {
puts "<img class=va src=/images/172_1_00_HD.png height=21>"
} else {
puts "<img class=va src=/images/172_1_26_SD.png height=21>"
}
puts "</td>
</tr><tr>
<th>Channel</th>
<td>[epg channelicon [$ts get channel_name] 50 "vertical-align: middle"]
[$ts get channel_num] - [$ts get channel_name]</td>
</tr><tr>
<th>Start Time</th>
<td>"
puts [clock format [$ts get start] -format "%c %Z"]
puts "</td>
</tr><tr>
<th>End Time</th>
<td>"
puts [clock format [$ts get end] -format "%c %Z"]
puts "</td>
</tr><tr>
<th>Duration</th>
<td>[$ts duration] minute(s).</td>
</tr><tr>
<th>Size</th>
<td>[$ts size] MiB</td>
</tr><tr>
<th>Flags</th>
<td>[$ts get flags]</td>
</tr>
</table>
"
exit
}
if {[dict exists $_cgi dir]} {
set dir [dict get $_cgi dir]
} else {
set dir "/media/My Video"
}
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=#title>Change Title</a></li>
</ul>
<div id=dialogue></div>
<div id=confirm title="Confirmation Required"></div>
<script type=text/javascript>
var $confirm = $('#confirm').dialog({
modal: true, autoOpen: false,
height: 160, width: 500,
show: 'fade', hide: 'fade',
draggable: false, resizable: false
});
var confirm_action = function(action, callback, ts, id) {
var bts = ts.replace(/.*\/|\.[^.]*$/g, '');
$confirm.dialog('option', 'buttons', {
'Yes': function() { $(this).dialog('close');
callback(ts, id); },
'No': function() {$(this).dialog('close');}
});
$('#confirm').empty().html(
'Are you sure you wish to ' + action + '<br>' +
'<i>' + bts + '</i> ?'
);
$confirm.dialog('open');
}
var delete_callback = function(ts, id) {
var el = 'div.tsfile#' + id;
var results = el + ' .results';
var url = window.location.pathname + '?tsfile=' +
encodeURIComponent(ts) + '&action=delete';
$(results).load(url, function() {
$(el).delay(3000).slideUp(300, function() {
$(el).remove();
});
});
}
var lock_callback = function(ts, id) {
var el = 'div.tsfile#' + id;
var results = el + ' .results';
var url = window.location.pathname + '?tsfile=' +
encodeURIComponent(ts) + '&action=';
$(results).load(url + 'lock', function() {
$(results).delay(3000).slideUp(150,
function() {
$(el).load(url + 'entry');
}
);
});
}
// Dialogue init
var $dialog = $('#dialogue').dialog({
title: "Recording Details",
modal: false, autoOpen: false,
height: 600, width: 700,
show: 'scale', hide: 'fade',
draggable: true, resizable: true,
buttons: { "Close":
function() {$(this).dialog('close');}},
close: function(e,u) { $('#dialogue').empty().html(
'<img src="/img/loading.gif" alt="loading">'); }
});
$(document).ready(function() {
$('a.ts').click(function(e) {
e.preventDefault();
var file = $(this).attr('file');
var url = window.location.pathname + '?tsfile=' +
encodeURIComponent(file);
$('#dialogue').load(url);
$dialog.dialog('open');
});
$('img.opt').contextMenu(
{
menu: 'optmenu',
leftButton: true,
},
function (action, el, pos)
{
var ts = $(el).parent().prevAll('a.ts').last().attr('file');
var did = $(el).attr('did');
switch (action)
{
case 'delete':
confirm_action('delete', delete_callback, ts, did);
break;
case 'lock':
confirm_action('change the lock on', lock_callback, ts, did);
break;
default:
alert('Unhandled action: ' + action);
break;
}
}
);
});
</script>
}
puts { <div style="border: 1px solid grey; padding: 1em"> }
# Breadcrumb path
puts "<h1>"
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 "</h1>"
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>
"
}
regsub -all -- {\/+} "$dir/*" "/" dir
foreach file [lsort [glob -nocomplain "$dir"]] {
entry $file
}
puts "</div>"
source /mod/var/mongoose/html/lib/footer.jim