update auto-expiry with new options

git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1919 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2014-05-21 22:10:22 +00:00
parent d9a284994e
commit bfd099a82e
9 changed files with 231 additions and 74 deletions

View File

@ -1,11 +1,11 @@
Package: webif
Priority: optional
Section: web
Version: 1.0.13-1
Version: 1.0.13-2
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.1.11),lighttpd(>=1.4.35-2),jim(>=0.75-1),jim-oo,jim-sqlite3(>=0.75),jim-cgi(>=0.7),jim-binary(>=0.75),service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.13),hmt(>=1.1.14),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),mongoose
Conflicts: tvdiary(<0.0.2-6)
Suggests:
Description: An evolving web interface for the Humax. [Switch web server software]
Description: An evolving web interface for the Humax. [Enhance auto-expiry options]
Tags: http://hummy.tv/forum/threads/5031/

View File

@ -2,23 +2,48 @@
package require cgi
source /mod/webif/lib/setup
httpheader
require browse.class
# dir=%2Fmedia%2FMy+Video%2FWeatherview
# aexpiry_days=13
set dir [cgi_get dir "-"]
set days [cgi_get aexpiry_days 7]
if {$dir eq "-"} exit
set act [cgi_get act "update"]
if {$act eq "fetch"} {
httpheader "application/json"
set data [{dir expiry} $dir]
puts "{"
puts " \"days\": \"$data(days)\","
puts " \"keep\": \"$data(keep)\","
puts " \"type\": \"$data(type)\","
puts " \"keepnew\": \"$data(keepnew)\""
puts "}"
exit
}
if {$act eq "remove"} {
httpheader
if {[file exists "$dir/.autoexpire"]} {
file delete "$dir/.autoexpire"
}
exit
}
httpheader
set data(days) [cgi_get aexpiry_days 0]
set data(keep) [cgi_get aexpiry_min 0]
set data(type) [cgi_get aexpiry_timetype recorded]
set data(keepnew) [cgi_get aexpiry_unwatched 0]
if {![file isdirectory $dir]} {
puts "Not a directory."
exit
}
set fd [open "$dir/.autoexpire" w]
puts $fd $days
$fd close
{dir expiry} $dir $data
puts "Ok."

View File

@ -80,7 +80,7 @@ if $flatten {
}
puts {
<li class=clock><a href=#expire>Auto-Expire</a></li>
<li class=clock><a href=#expire>Auto-Expire Options</a></li>
}
if {[system pkginst ffmpeg]} {
@ -259,28 +259,76 @@ puts {
</form>
</div>
<div id=aexpiry title="Auto-Expiry" style="display: none">
<div id=aexpiry title="Auto-Expiry Settings"
style="display: none; line-height: 1em;">
<form id=aexpiry_form>
<input type=hidden name="dir" id="aexpiry_ldir" value="">
}
puts {
<table border=0>
<tr>
<th>
<tr><th align=right>
<label for="aexpiry_days">
<b>Expire after</b>
<span class=blood>(in days)</span>
<b>Remove recordings after</b> (in days)
<br><span class=footnote>
(Leave blank to skip age check)
</span>
</label>
</th>
<td>
</th><td>
<input name="aexpiry_days" id="aexpiry_days"
type=number value=0 size=5 maxlength=3
class="text ui-widget-content ui-corner-all">
</td>
</tr>
</td></tr>
<tr><th>
<label for="aexpiry_min">
<b>Keep at least</b>
(number of recordings)
<br>
<span class=footnote>(Oldest will be deleted first)
</span>
</label>
</th><td>
<input name="aexpiry_min" id="aexpiry_min"
type=number value=0 size=5 maxlength=3
class="text ui-widget-content ui-corner-all">
</td></tr>
<tr><th>
<label for="aexpiry_timetype">
<b>For date of recording, use</b>
</label>
</th><td>
<input name="aexpiry_timetype" id="aexpiry_timetype0"
type=radio value=0 checked
class="text ui-widget-content ui-corner-all">
Recording end time
<br>
<input name="aexpiry_timetype" id="aexpiry_timetype1"
type=radio value=1
class="text ui-widget-content ui-corner-all">
<span>
When last watched
<span class=bfootnote>(or end time if unwatched)</span>
</span>
</td></tr>
<tr><th>
<label for="aexpiry_unwatched">
<b>Never delete unwatched recordings</b>
</label>
</th><td>
<input name="aexpiry_unwatched" id="aexpiry_unwatched"
type=checkbox value=1
class="ui-widget-content ui-corner-all">
</td></tr>
</table>
<div id=aexpiry_working class=hidden>
<img src=/img/loading.gif> Applying auto-expiry...
<img src=/img/loading.gif> Applying changes...
</div>
<div id=aexpiry_loading class=hidden>
<img src=/img/loading.gif> Retrieving data...
</div>
</form>
</div>

View File

@ -220,6 +220,14 @@ function aexpiry_submit()
function() { window.location.reload(true); });
}
function aexpiry_remove()
{
$('#aexpiry_working').slideDown('slow');
var s = $('#aexpiry_form').serialize();
$.get('/browse/aexpiry.jim?act=remove&' + s,
function() { window.location.reload(true); });
}
function newdir_submit()
{
var s = $('#newdirform_form').serialize();
@ -390,7 +398,7 @@ function preparedmenu(el, menu)
fixdmenu(el, menu, 'autodecrypt', '#decrypt', 'Auto-decrypt', 1);
fixdmenu(el, menu, 'autompg', '#mpg', 'Auto-mpg', 0);
fixdmenu(el, menu, 'automp3', '#mp3', 'Auto-audio', 0);
fixdmenu(el, menu, 'autoexpire', '#expire', 'Auto-expire', 0);
//fixdmenu(el, menu, 'autoexpire', '#expire', 'Auto-expire', 0);
}
$(document).ready(function() {
@ -587,19 +595,37 @@ var dmenuclick = function(action, el, pos)
break;
case 'expire':
if ($(el).attr('autoexpire') == 1)
flagdir(file, 'autoexpire', iconset, results, el);
else
{
$('#aexpiry_ldir').val(decodeURIComponent(file));
if ($(el).attr('autoexpiredays') > 0)
$('#aexpiry_days')
.val($(el).attr('autoexpiredays'));
else
$('#aexpiry_days').val(7);
$('#aexpiry_working').hide('fast');
$('#aexpiry').dialog('open');
}
$('#aexpiry_ldir').val(decodeURIComponent(file));
// Initialise form with default values
$('#aexpiry_days').val("");
$('#aexpiry_timetype0').prop('checked', true);
$('#aexpiry_min').val("");
$('#aexpiry_unwatched').prop('checked', false);
$('#aexpiry_form input').disable();
$('#aexpiry_working').hide('fast');
$('#aexpiry_loading').show('fast');
$.getJSON('aexpiry.jim?act=fetch&dir=' + file, function(data) {
$.each(data, function(key, val) {
if (key == 'days')
$('#aexpiry_days').val(val);
else if (key == 'keep')
$('#aexpiry_min').val(val);
else if (key == 'keepnew')
$('#aexpiry_unwatched')
.prop('checked',
val == "1" ? true : false);
else if (key == 'type')
$('#aexpiry_timetype' + val)
.prop('checked', true);
});
$('#aexpiry_loading').hide('slow');
$('#aexpiry_form input').enable();
});
$('#aexpiry').dialog('open');
break;
case 'flat':
@ -772,6 +798,7 @@ var dmenuclick = function(action, el, pos)
modal: true,
buttons: {
"Update": aexpiry_submit,
"Remove Settings": aexpiry_remove,
"Close": function() {
$(this).dialog('close');
}

View File

@ -229,14 +229,18 @@ pre, .pre
background: transparent;
}
.footnote
.footnote, .bfootnote
{
color: #ff4000;
background: transparent;
font-size: 70%;
font-weight: bold;
}
.footnote
{
color: #ff4000;
}
.blueshade
{
background: #b9daff;

View File

@ -140,6 +140,7 @@ set recalc 0
proc dorecalc {dir} {
global recalc
if {!$recalc} return
log "Running unwatched recalculation for $dir" 2
ts resetnew $dir
set recalc 0
}
@ -154,30 +155,6 @@ proc dedup {dir} {
}
}
proc do_expire {ts} {
global ax_days
set file [$ts get file]
# Calculate the age of the file in days.
set age $(([clock seconds] - [$ts get start]) / 86400.0)
log " EXPIRE: $file (age = $age)" 2
if {$age > $ax_days} {
if {[$ts inuse]} {
log " EXPIRE: $file ($age > $ax_days)"
log " In use."
return
}
runplugin preexpire $ts
if {[safe_delete $file]} {
log " EXPIRE: $file ($age > $ax_days)" 0
log " Deleted." 0
runplugin postexpire $ts
incr ::recalc
}
}
}
proc do_shrink {ts} {
global tmp dustbin tsgroup
set file [$ts get file]
@ -519,11 +496,77 @@ proc mp3 {dir} {
}
proc expire {dir} {
global ax_days
log "EXPIRE: \[$dir]" 2
set ax_days [{dir expiry} $dir]
entries $dir do_expire
# type 0 keep {} days 2 keepnew 0
set ax [{dir expiry} $dir]
log " $ax" 2
if {![string is integer -strict $ax(keep)]} { set ax(keep) 0 }
if {![string is integer -strict $ax(days)]} { set ax(days) 0 }
if {!$ax(keep) && !$ax(days)} {
log "Expire error ($dir): neither keep nor days set ($ax)" 0
return
}
if {$ax(type) eq "0"} {
set getter [lambda {ts} { list [$ts get end] }]
} else {
set getter [lambda {ts} { list [$ts lastmod] }]
}
set entries [lsort \
-command [lambda {a b} {upvar getter g; expr [$g $a] - [$g $b]}]\
[lmap i [readdir -nocomplain $dir] {
if {![string match {*.ts} $i]} continue
if {[catch {set ts [ts fetch "$dir/$i"]}]} continue
if {$ts == 0} continue
list $ts
}]]
# Entries are now sorted with oldest first, according to the selected
# criterion.
set num [llength $entries]
log " Entries: $num" 2
foreach e $entries { log " [file tail [$e get file]]" 2 }
set now [clock seconds]
foreach ts $entries {
set file [$ts get file]
if {$num <= $ax(keep)} {
log " Remaining ($num) <= keep ($ax(keep))" 2
break
}
log " [file tail $file]"
if {[$ts inuse]} {
log " In use, skipping."
continue
}
if {$ax(keepnew) ne "0" && [$ts flag New]} {
log " Unwatched, skipping."
continue
}
if {$ax(days) > 0} {
# Calculate age in days
set age $(($now - [$getter $ts]) / 86400.0)
log " $age days (cf. $ax(days))"
if {$age < $ax(days)} {
log " Too new, skipping."
continue
}
}
log " Removing."
runplugin preexpire $ts
if {![safe_delete $file]} {
log "Unknown error in safe_delete, aborting." 0
break
}
log " EXPIRE: removed $file" 0
runplugin postexpire $ts
incr ::recalc
incr num -1
}
}
proc scan {dir attr {force 0} {recurse 1}} {{indent 0}} {

View File

@ -15,14 +15,21 @@ proc _addicon {img {hover ""} {class va}} {
return $icon
}
proc {dir expiry} {dir} {
if {[catch {
set fd [open "$dir/.autoexpire"]
set days $([read $fd] + 0)
proc {dir expiry} {dir {data {}}} {
if {[llength $data] > 1} {
set fd [open "$dir/.autoexpire" w]
puts $fd "$data(days):$data(type):$data(keep):$data(keepnew):"
$fd close
}]} { set days 0 }
if {!$days} { set days 7 }
return $days
return
}
set ret { days "" type 0 keep "" keepnew 0 }
catch {
set fd [open "$dir/.autoexpire"]
lassign [split [string trim [read $fd]] ":"] \
ret(days) ret(type) ret(keep) ret(keepnew)
$fd close
} msg
return $ret
}
proc {dir iconset} {dir} {
@ -34,7 +41,7 @@ proc {dir iconset} {dir} {
if {[string match {\[*\]} [file tail $dir]]} { set noflat 1 }
if {[file exists "$dir/.noflatten"]} { set noflat 1 }
if $noflat { lappend icons \
[_addicon "/img/flat-tyre.png" "No-flatten" }
[_addicon "/img/flat-tyre.png" "No-flatten"] }
lappend attrs "noflat=$noflat"
}
@ -92,11 +99,9 @@ proc {dir iconset} {dir} {
set autoexpire 0
if {[file exists "$dir/.autoexpire"]} {
set days [{dir expiry} $dir]
set autoexpire 1
lappend icons [_addicon "/img/clock.png" \
"Auto-Expire ($days day$($days == 1 ? "" : "s"))"]
lappend attrs "autoexpire=1" "autoexpiredays=$days"
lappend icons [_addicon "/img/clock.png" "Auto-Expire"]
lappend attrs "autoexpire=1"
}
return [list $icons $attrs]

View File

@ -83,6 +83,7 @@ proc {system kernelver} {} {
"May 8 14:32:30 KST 2013" { format "HDR_1.03.06(b)" }
"Dec 10 14:36:54 KST 2013" { format "HDR_1.03.11" }
"Feb 7 14:15:02 KST 2014" { format "HDR_1.03.12" }
"May 19 22:39:27 BST 2014" { format "HDR_CFW_2.30" }
# HD
"Oct 11 21:14:31 KST 2010" { format "HD_1.01.12" }

View File

@ -48,6 +48,10 @@ ts method _parse {line} {
set flags [split [string range $flags_list 0 end-1] ,]
}
ts method lastmod {} {
return [file mtime "[file rootname $file].hmt"]
}
ts method inuse {} {
if {[system inuse [file rootname $file]]} { return 1 }
return 0