Automatic edit point bookmarks following crop

This commit is contained in:
Matthew 2019-10-31 00:52:11 +00:00 committed by HummyPkg
parent 0c7dd2b31f
commit b42f2ed7b5
4 changed files with 108 additions and 20 deletions

View File

@ -4,8 +4,8 @@ package require cgi
source /mod/webif/lib/setup source /mod/webif/lib/setup
require ts.class pretty_size require ts.class pretty_size
jqplugin progressbar jqplugin progressbar iphone-style-checkboxes
jscss crop.js jscss crop.js style.css
header header
set rfile [cgi_get file] set rfile [cgi_get file]
@ -23,13 +23,13 @@ puts "
<tr><th>File:</th><td>$rfile</td></tr> <tr><th>File:</th><td>$rfile</td></tr>
<tr><th>Length:</th><td>[clock format $len -format \"%T\"]</td></tr> <tr><th>Length:</th><td>[clock format $len -format \"%T\"]</td></tr>
<tr><th>Size:</th><td>[pretty_size [$ts size]] ([$ts get definition])</td></tr> <tr><th>Size:</th><td>[pretty_size [$ts size]] ([$ts get definition])</td></tr>
<tr><th>Bookmarks:</th><td>[$ts get bookmarks] @ " <tr><th>Bookmarks:</th><td id=originalbookmarks>[$ts get bookmarks] @ "
puts [join [lmap i [$ts bookmarks 1] { puts [join [lmap i [$ts bookmarks 1] {
clock format $i -format "%T" clock format $i -format "%T"
}] ", "] }] ", "]
puts "</td></tr><tr><th>File</th><td>" puts "</td></tr><tr><th>&nbsp;</th><td id=cutplan>"
puts "<div style=\"position: relative; top: -10px\">" puts "<div style=\"position: relative; top: -10px\">"
@ -48,14 +48,21 @@ append bookmarks [$ts bookmarks]
set keeping 0 set keeping 0
set last 0 set last 0
set start -1 set start -1
set newbookmarks "0 "
set cur 0
foreach b $bookmarks { foreach b $bookmarks {
if {$start < 0} { if {$start < 0} {
# Start of a section to keep
set start $b set start $b
continue continue
} }
# End of a section to keep
set end $b set end $b
incr keeping $($end - $start) set l $($end - $start)
incr keeping $l
incr cur $l
append newbookmarks "[expr $cur + 3] "
set left $($start * 500 / $len) set left $($start * 500 / $len)
set right $($end * 500 / $len) set right $($end * 500 / $len)
@ -69,6 +76,7 @@ foreach b $bookmarks {
} }
if {$start > 0} { if {$start > 0} {
# Still in a keep section...
incr keeping $($len - $start) incr keeping $($len - $start)
set left $($start * 500 / $len) set left $($start * 500 / $len)
div cut $last $($left - 1) div cut $last $($left - 1)
@ -77,6 +85,10 @@ if {$start > 0} {
div cut $last 500 div cut $last 500
} }
if {$cur > $keeping - 8 && $keeping - 8 > 0} {
set newbookmarks [lreplace $newbookmarks end end $($keeping - 8)]
}
set keepperc $($keeping * 100.0 / $len) set keepperc $($keeping * 100.0 / $len)
set esttime $(int($keeping * 0.025)) set esttime $(int($keeping * 0.025))
if {[$ts get definition] eq "HD"} { set esttime $($esttime * 4) } if {[$ts get definition] eq "HD"} { set esttime $($esttime * 4) }
@ -86,7 +98,23 @@ puts "
</td></tr> </td></tr>
<tr><th>Keeping:</th><td> <tr><th>Keeping:</th><td>
[clock format $keeping -format "%T"] ([format "%.2f" $keepperc]%) [clock format $keeping -format "%T"] ([format "%.2f" $keepperc]%)
</td></tr> </td></tr>"
puts "
<tr>
<th title=\"Calculated bookmarks for edit points following crop.\">
New Bookmarks:
</th><td id=newbookmarks>
<span id=bookmarks val=\"$newbookmarks\">
$newbookmarks</span>&nbsp;&nbsp;&nbsp;&nbsp;(
"
puts [join [lmap i $newbookmarks {
clock format $i -format "%T"
}] ", "]
puts " )</td></tr>"
puts "
<tr><th>Time:</th> <tr><th>Time:</th>
<td>Cropping will take around [clock format $esttime -format "%T"]</td></tr> <td>Cropping will take around [clock format $esttime -format "%T"]</td></tr>
</table> </table>
@ -98,10 +126,19 @@ puts "
></span> ></span>
<div id=cropdiv style=\"padding: 1em\"> <div id=cropdiv style=\"padding: 1em\">
<button id=invert invert=$invert>Invert selection</button> <table><tr>
<button id=cropit>Perform crop operation</button> <td><button id=invert invert=$invert>Invert selection</button></td>
<td><button id=cropit>Perform crop operation</button></td>
<td>
Save new bookmarks?
<input id=saveit type=checkbox name=saveit checked>
<label id=saveitlabel for=saveit>&nbsp;</label>
</td>
</tr></table>
</div> </div>
<button id=back>Back to media list</button> <button id=back>Back to media list</button>
<button id=save class=\"hidden\">Save New Bookmarks</button>
<div id=results class=\"hidden blood\"></div>
<div id=progressdiv class=hidden> <div id=progressdiv class=hidden>
Cropping: <div id=progressbar></div> Cropping: <div id=progressbar></div>
@ -109,6 +146,5 @@ Cropping: <div id=progressbar></div>
<div id=output class=\"hidden pre\" style=\"margin-top: 10px\"></div> <div id=output class=\"hidden pre\" style=\"margin-top: 10px\"></div>
</fieldset> </fieldset>
" "

View File

@ -1,18 +1,29 @@
var handle = 0; var handle = 0;
function escapestring(str)
{
str = JSON.stringify(String(str));
str = str.substring(1, str.length - 1);
return str;
}
function update() function update()
{ {
var perc = $('#params').attr('perc'); $.get('progress.jim', {
var file = $('#params').attr('file'); 'perc': $('#params').attr('perc'),
'file': $('#params').attr('file')
$.get('progress.jim' + '?perc=' + perc + '&file=' + file, }, function(data) {
function(data) {
if (handle) if (handle)
$('#progressbar').reportprogress(data); $('#progressbar').reportprogress(data);
}); });
} }
$(document).ready(function() { $(function() {
$('[type="checkbox"]').iphoneStyle({
checkedLabel: 'YES',
uncheckedLabel: 'NO'
});
$('#progressbar').reportprogress(0); $('#progressbar').reportprogress(0);
@ -20,24 +31,51 @@ $('#back').button().click(function() {
window.location = '/go/browse?dir=' + $('#params').attr('dir'); window.location = '/go/browse?dir=' + $('#params').attr('dir');
}); });
$('#save').button({icons: {primary: "ui-icon-disk"}})
.on('click', function() {
$('#progressdiv,#output,#save').hide('slow');
$.post('../bookmarks/save.jim', {
'file': $('#fileparams').attr('file'),
'bookmarks': $('#bookmarks').attr('val')
}, function(data) {
$('#results').html(data)
.slideDown('slow')
.delay(6000)
.slideUp('slow');
$('#originalbookmarks')
.html($('#newbookmarks').clone());
});
});
$('#cropit').button().click(function() { $('#cropit').button().click(function() {
$('#cropdiv').hide('slow'); $('#cropdiv').hide('slow');
$('#progressdiv').show('slow'); $('#progressdiv').show('slow');
$('#back').hide(); $('#back').hide();
handle = setInterval("update()", 1000); handle = setInterval("update()", 1000);
$('#output').show().text('Please do not interrupt...') $('#output').show().text('Please do not interrupt...')
.load('execute.jim?file=' + $('#params').attr('file') + .load('execute.jim', {
'&invert=' + $('#invert').attr('invert'), 'file': $('#params').attr('file'),
function() { 'invert': $('#invert').attr('invert')
}, function() {
clearInterval(handle); clearInterval(handle);
handle = 0; handle = 0;
$('#back').show(); $('#back,#save').show();
$('#cutplan').html('File cropping complete');
$('#originalbookmarks').empty();
$('#progressbar').reportprogress(100); $('#progressbar').reportprogress(100);
if ($('#saveit').prop('checked'))
{
$('#save').trigger('click');
$('#progressdiv')
.delay(3000)
.text('Cropping complete.');
}
}); });
}); });
$('#invert').button().on('click', function() { $('#invert').button().on('click', function() {
window.location = 'crop.jim?file=' + $('#params').attr('file') + window.location = 'crop.jim?file=' +
escapestring($('#params').attr('file')) +
'&invert=' + ($(this).attr('invert') == '1' ? '0' : '1'); '&invert=' + ($(this).attr('invert') == '1' ? '0' : '1');
}); });

View File

@ -68,6 +68,7 @@ system endop $token
set newname "$shname-[clock seconds]" set newname "$shname-[clock seconds]"
puts "Renaming file group to $newname" puts "Renaming file group to $newname"
puts "<span class=hidden id=fileparams file=\"$dir/$newname.ts\"></span>"
ts renamegroup "$dir/$shname.ts" $newname ts renamegroup "$dir/$shname.ts" $newname
exec /mod/bin/hmt "+setfilename=$newname" "$dir/$newname.hmt" exec /mod/bin/hmt "+setfilename=$newname" "$dir/$newname.hmt"
# New nicesplice shrinks whilst cropping. # New nicesplice shrinks whilst cropping.

View File

@ -0,0 +1,13 @@
div.switchlabel
{
height: 27px;
line-height: 27px;
}
div.sliderlabel
{
height: 40px;
line-height: 40px;
}