Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

Commit 9245e5f

Browse files
Matthewhummypkg
authored andcommitted
Automatic edit point bookmarks following crop
1 parent 0c7dd2b commit 9245e5f

File tree

4 files changed

+99
-12
lines changed

4 files changed

+99
-12
lines changed

webif/html/browse/crop/crop.jim

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package require cgi
44
source /mod/webif/lib/setup
55
require ts.class pretty_size
66

7-
jqplugin progressbar
8-
jscss crop.js
7+
jqplugin progressbar iphone-style-checkboxes
8+
jscss crop.js style.css
99
header
1010

1111
set rfile [cgi_get file]
@@ -23,13 +23,13 @@ puts "
2323
<tr><th>File:</th><td>$rfile</td></tr>
2424
<tr><th>Length:</th><td>[clock format $len -format \"%T\"]</td></tr>
2525
<tr><th>Size:</th><td>[pretty_size [$ts size]] ([$ts get definition])</td></tr>
26-
<tr><th>Bookmarks:</th><td>[$ts get bookmarks] @ "
26+
<tr><th>Bookmarks:</th><td id=originalbookmarks>[$ts get bookmarks] @ "
2727

2828
puts [join [lmap i [$ts bookmarks 1] {
2929
clock format $i -format "%T"
3030
}] ", "]
3131

32-
puts "</td></tr><tr><th>File</th><td>"
32+
puts "</td></tr><tr><th>&nbsp;</th><td id=cutplan>"
3333

3434
puts "<div style=\"position: relative; top: -10px\">"
3535

@@ -48,14 +48,21 @@ append bookmarks [$ts bookmarks]
4848
set keeping 0
4949
set last 0
5050
set start -1
51+
set newbookmarks "0 "
52+
set cur 0
5153
foreach b $bookmarks {
5254
if {$start < 0} {
55+
# Start of a section to keep
5356
set start $b
5457
continue
5558
}
59+
# End of a section to keep
5660
set end $b
5761

58-
incr keeping $($end - $start)
62+
set l $($end - $start)
63+
incr keeping $l
64+
incr cur $l
65+
append newbookmarks "[expr $cur + 3] "
5966

6067
set left $($start * 500 / $len)
6168
set right $($end * 500 / $len)
@@ -69,6 +76,7 @@ foreach b $bookmarks {
6976
}
7077

7178
if {$start > 0} {
79+
# Still in a keep section...
7280
incr keeping $($len - $start)
7381
set left $($start * 500 / $len)
7482
div cut $last $($left - 1)
@@ -77,6 +85,10 @@ if {$start > 0} {
7785
div cut $last 500
7886
}
7987

88+
if {$cur > $keeping - 8 && $keeping - 8 > 0} {
89+
set newbookmarks [lreplace $newbookmarks end end $($keeping - 8)]
90+
}
91+
8092
set keepperc $($keeping * 100.0 / $len)
8193
set esttime $(int($keeping * 0.025))
8294
if {[$ts get definition] eq "HD"} { set esttime $($esttime * 4) }
@@ -86,7 +98,23 @@ puts "
8698
</td></tr>
8799
<tr><th>Keeping:</th><td>
88100
[clock format $keeping -format "%T"] ([format "%.2f" $keepperc]%)
89-
</td></tr>
101+
</td></tr>"
102+
103+
puts "
104+
<tr>
105+
<th title=\"Calculated bookmarks for edit points following crop.\">
106+
New Bookmarks:
107+
</th><td id=newbookmarks>
108+
<span id=bookmarks val=\"$newbookmarks\">
109+
$newbookmarks</span>&nbsp;&nbsp;&nbsp;&nbsp;(
110+
"
111+
puts [join [lmap i $newbookmarks {
112+
clock format $i -format "%T"
113+
}] ", "]
114+
115+
puts " )</td></tr>"
116+
117+
puts "
90118
<tr><th>Time:</th>
91119
<td>Cropping will take around [clock format $esttime -format "%T"]</td></tr>
92120
</table>
@@ -98,17 +126,25 @@ puts "
98126
></span>
99127

100128
<div id=cropdiv style=\"padding: 1em\">
101-
<button id=invert invert=$invert>Invert selection</button>
102-
<button id=cropit>Perform crop operation</button>
129+
<table><tr>
130+
<td><button id=invert invert=$invert>Invert selection</button></td>
131+
<td><button id=cropit>Perform crop operation</button></td>
132+
<td>
133+
Save new bookmarks?
134+
<input id=saveit type=checkbox name=saveit checked>
135+
<label id=saveitlabel for=saveit>&nbsp;</label>
136+
</td>
137+
</tr></table>
103138
</div>
104139
<button id=back>Back to media list</button>
140+
<button id=save class=\"hidden\">Save New Bookmarks</button>
141+
<div id=results class=\"hidden blood\"></div>
105142

106143
<div id=progressdiv class=hidden>
107144
Cropping: <div id=progressbar></div>
108145
</div>
109146

110147
<div id=output class=\"hidden pre\" style=\"margin-top: 10px\"></div>
111148
</fieldset>
112-
113149
"
114150

webif/html/browse/crop/crop.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
var handle = 0;
22

3+
function escapestring(str)
4+
{
5+
str = JSON.stringify(String(str));
6+
str = str.substring(1, str.length - 1);
7+
return str;
8+
}
9+
310
function update()
411
{
512
var perc = $('#params').attr('perc');
6-
var file = $('#params').attr('file');
13+
var file = escapestring($('#params').attr('file'));
714

815
$.get('progress.jim' + '?perc=' + perc + '&file=' + file,
916
function(data) {
@@ -12,14 +19,35 @@ function update()
1219
});
1320
}
1421

15-
$(document).ready(function() {
22+
$(function() {
23+
24+
$('[type="checkbox"]').iphoneStyle({
25+
checkedLabel: 'YES',
26+
uncheckedLabel: 'NO'
27+
});
1628

1729
$('#progressbar').reportprogress(0);
1830

1931
$('#back').button().click(function() {
2032
window.location = '/go/browse?dir=' + $('#params').attr('dir');
2133
});
2234

35+
$('#save').button({icons: {primary: "ui-icon-disk"}})
36+
.on('click', function() {
37+
$('#progressdiv,#output,#save').hide('slow');
38+
$.post('../bookmarks/save.jim', {
39+
file: $('#fileparams').attr('file'),
40+
bookmarks: $('#bookmarks').attr('val')
41+
}, function(data) {
42+
$('#results').html(data)
43+
.slideDown('slow')
44+
.delay(6000)
45+
.slideUp('slow');
46+
$('#originalbookmarks')
47+
.html($('#newbookmarks').clone());
48+
});
49+
});
50+
2351
$('#cropit').button().click(function() {
2452
$('#cropdiv').hide('slow');
2553
$('#progressdiv').show('slow');
@@ -31,8 +59,17 @@ $('#cropit').button().click(function() {
3159
function() {
3260
clearInterval(handle);
3361
handle = 0;
34-
$('#back').show();
62+
$('#back,#save').show();
63+
$('#cutplan').html('File cropping complete');
64+
$('#originalbookmarks').empty();
3565
$('#progressbar').reportprogress(100);
66+
if ($('#saveit').prop('checked'))
67+
{
68+
$('#save').trigger('click');
69+
$('#progressdiv')
70+
.delay(3000)
71+
.text('Cropping complete.');
72+
}
3673
});
3774
});
3875

webif/html/browse/crop/execute.jim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ system endop $token
6868

6969
set newname "$shname-[clock seconds]"
7070
puts "Renaming file group to $newname"
71+
puts "<span class=hidden id=fileparams file=\"$dir/$newname.ts\"></span>"
7172
ts renamegroup "$dir/$shname.ts" $newname
7273
exec /mod/bin/hmt "+setfilename=$newname" "$dir/$newname.hmt"
7374
# New nicesplice shrinks whilst cropping.

webif/html/browse/crop/style.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
div.switchlabel
3+
{
4+
height: 27px;
5+
line-height: 27px;
6+
}
7+
8+
div.sliderlabel
9+
{
10+
height: 40px;
11+
line-height: 40px;
12+
}
13+

0 commit comments

Comments
 (0)