-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel_tool.html
More file actions
447 lines (411 loc) · 17.9 KB
/
Copy pathlabel_tool.html
File metadata and controls
447 lines (411 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lego Completion Labeler</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: #1a1a1a; color: #e0e0e0; height: 100vh; display: flex; flex-direction: column; }
header {
display: flex; align-items: center; justify-content: space-between;
padding: 10px 16px; background: #111; border-bottom: 1px solid #333;
flex-shrink: 0;
}
header h1 { font-size: 1rem; font-weight: 600; color: #fff; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.main { display: flex; flex: 1; overflow: hidden; }
/* Sidebar */
.sidebar {
width: 240px; background: #111; border-right: 1px solid #333;
overflow-y: auto; flex-shrink: 0;
}
.sidebar-progress {
padding: 8px 12px; font-size: 0.75rem; color: #888;
border-bottom: 1px solid #222; background: #0d0d0d;
}
.sidebar-progress span { color: #4caf50; font-weight: 600; }
.group-label {
padding: 6px 12px; font-size: 0.7rem; text-transform: uppercase;
letter-spacing: 0.08em; color: #666; background: #0d0d0d;
border-top: 1px solid #222; position: sticky; top: 0; z-index: 1;
}
.vid-item {
padding: 7px 12px; cursor: pointer; font-size: 0.82rem;
display: flex; align-items: center; gap: 8px;
border-bottom: 1px solid #1e1e1e; transition: background 0.1s;
}
.vid-item:hover { background: #1e1e1e; }
.vid-item.active { background: #1e3a5f; color: #6ab0f5; }
.vid-item .dot {
width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
background: #333;
}
.vid-item.labeled .dot { background: #4caf50; }
.vid-item .count { margin-left: auto; font-size: 0.7rem; color: #555; }
.vid-item.labeled .count { color: #4caf50; }
/* Player area */
.player-area {
flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.video-wrap {
flex: 1; background: #000; display: flex; align-items: center;
justify-content: center; min-height: 0;
}
video {
max-width: 100%; max-height: 100%; outline: none;
}
.no-video {
color: #555; font-size: 0.9rem; text-align: center;
}
/* Controls bar */
.controls {
background: #111; border-top: 1px solid #333; padding: 10px 14px;
display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.vid-title { font-size: 0.85rem; color: #aaa; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time-display { font-size: 0.8rem; color: #666; font-variant-numeric: tabular-nums; min-width: 90px; text-align: right; }
kbd {
display: inline-block; padding: 1px 5px; border: 1px solid #444;
border-radius: 3px; font-size: 0.7rem; color: #888; background: #222;
}
/* Stamp panel */
.stamp-panel {
width: 260px; background: #111; border-left: 1px solid #333;
display: flex; flex-direction: column; flex-shrink: 0;
}
.stamp-header {
padding: 10px 14px; border-bottom: 1px solid #333;
display: flex; align-items: center; justify-content: space-between;
}
.stamp-header h2 { font-size: 0.85rem; font-weight: 600; }
.stamp-count { font-size: 0.75rem; color: #666; }
.stamp-btn {
margin: 12px; padding: 10px; background: #1a4a2a; border: 1px solid #2e7d32;
color: #81c784; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
font-weight: 600; text-align: center; transition: background 0.15s;
}
.stamp-btn:hover { background: #2e7d32; }
.stamp-btn:active { background: #1b5e20; }
.stamp-hint { text-align: center; font-size: 0.7rem; color: #555; margin-top: -8px; margin-bottom: 8px; }
.stamp-list { flex: 1; overflow-y: auto; }
.stamp-item {
display: flex; align-items: center; padding: 6px 14px;
border-bottom: 1px solid #1a1a1a; font-size: 0.82rem;
font-variant-numeric: tabular-nums;
}
.stamp-item:hover { background: #1a1a1a; }
.stamp-time {
flex: 1; cursor: pointer; color: #6ab0f5;
}
.stamp-time:hover { text-decoration: underline; }
.stamp-del {
cursor: pointer; color: #555; font-size: 1rem; line-height: 1;
padding: 0 4px; border-radius: 3px;
}
.stamp-del:hover { color: #e57373; background: #2a1a1a; }
.empty-stamps { padding: 20px 14px; font-size: 0.8rem; color: #555; text-align: center; }
/* Buttons */
button.action {
padding: 5px 11px; border-radius: 5px; font-size: 0.78rem;
cursor: pointer; border: 1px solid #444; background: #222;
color: #ccc; transition: background 0.1s;
}
button.action:hover { background: #2e2e2e; }
button.action.primary { border-color: #1565c0; background: #0d2744; color: #6ab0f5; }
button.action.primary:hover { background: #1565c0; }
button.action.danger { border-color: #5c1a1a; background: #2a0d0d; color: #e57373; }
button.action.danger:hover { background: #7f1d1d; }
.speed-control { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.speed-label { font-size: 0.75rem; color: #666; }
.speed-btns { display: flex; gap: 3px; }
.speed-btns button {
padding: 3px 7px; border-radius: 4px; font-size: 0.75rem;
cursor: pointer; border: 1px solid #383838; background: #222; color: #888;
transition: background 0.1s, color 0.1s;
}
.speed-btns button:hover { background: #2e2e2e; color: #ccc; }
.speed-btns button.active { border-color: #1565c0; background: #0d2744; color: #6ab0f5; }
.flash { animation: flash-anim 0.3s ease; }
@keyframes flash-anim {
0% { background: #1b5e20; }
100% { background: #1a4a2a; }
}
</style>
</head>
<body>
<header>
<h1>Lego Completion Labeler</h1>
<div class="header-actions">
<button class="action primary" onclick="exportLabels()">Export JSON</button>
<label class="action" style="cursor:pointer;">
Import JSON <input type="file" accept=".json" style="display:none" onchange="importLabels(event)">
</label>
<button class="action danger" onclick="clearAll()">Clear All</button>
</div>
</header>
<div class="main">
<!-- Sidebar: video list -->
<div class="sidebar" id="sidebar">
<div class="sidebar-progress" id="progress-bar">0 / 0 labeled</div>
</div>
<!-- Video player -->
<div class="player-area">
<div class="video-wrap">
<div class="no-video" id="no-video">Select a video from the list</div>
<video id="player" style="display:none" controls preload="metadata"></video>
</div>
<div class="controls">
<span class="vid-title" id="vid-title">—</span>
<span class="time-display" id="time-display">0:00.0 / 0:00</span>
<div class="speed-control">
<span class="speed-label">Speed</span>
<div class="speed-btns" id="speed-btns">
<button onclick="setSpeed(0.5)">0.5×</button>
<button onclick="setSpeed(1)">1×</button>
<button onclick="setSpeed(1.5)">1.5×</button>
<button onclick="setSpeed(2)">2×</button>
<button onclick="setSpeed(3)">3×</button>
</div>
</div>
</div>
</div>
<!-- Timestamp panel -->
<div class="stamp-panel">
<div class="stamp-header">
<h2>Lego completions</h2>
<span class="stamp-count" id="stamp-count">0</span>
</div>
<div class="stamp-btn" id="stamp-btn" onclick="stampNow()">+ Mark Lego Complete</div>
<div class="stamp-hint"><kbd>L</kbd> or <kbd>Space</kbd> to stamp</div>
<div class="stamp-list" id="stamp-list">
<div class="empty-stamps">No timestamps yet</div>
</div>
</div>
</div>
<script>
// ── Video manifest (relative paths from this file) ──────────────────────
const VIDEOS = [
{ group: 'lookahead', name: '1', path: 'vids/lookahead/1.mp4' },
{ group: 'lookahead', name: '2', path: 'vids/lookahead/2.mp4' },
{ group: 'lookahead', name: '3', path: 'vids/lookahead/3.mp4' },
{ group: 'lookahead', name: '4', path: 'vids/lookahead/4.mp4' },
{ group: 'lookahead', name: '5', path: 'vids/lookahead/5.mp4' },
{ group: 'lookahead', name: '6', path: 'vids/lookahead/6.mp4' },
{ group: 'lookahead', name: '7_dynamic', path: 'vids/lookahead/7_dynamic.mp4' },
{ group: 'lookahead', name: '8', path: 'vids/lookahead/8.mp4' },
{ group: 'lookahead', name: '9', path: 'vids/lookahead/9.mp4' },
{ group: 'lookahead', name: '10', path: 'vids/lookahead/10.mp4' },
{ group: 'maxbatch', name: '1', path: 'vids/maxbatch/1.mp4' },
{ group: 'maxbatch', name: '2', path: 'vids/maxbatch/2.mp4' },
{ group: 'maxbatch', name: '3', path: 'vids/maxbatch/3.mp4' },
{ group: 'maxbatch', name: '4', path: 'vids/maxbatch/4.mp4' },
{ group: 'maxbatch', name: '5', path: 'vids/maxbatch/5.mp4' },
{ group: 'maxbatch', name: '6', path: 'vids/maxbatch/6.mp4' },
{ group: 'maxbatch', name: '7_dynamic', path: 'vids/maxbatch/7_dynamic.mp4' },
{ group: 'maxbatch', name: '8', path: 'vids/maxbatch/8.mp4' },
{ group: 'maxbatch', name: '9', path: 'vids/maxbatch/9.mp4' },
{ group: 'maxbatch', name: '10', path: 'vids/maxbatch/10.mp4' },
{ group: 'roundrobin',name: '1', path: 'vids/roundrobin/1.mp4' },
{ group: 'roundrobin',name: '2', path: 'vids/roundrobin/2.mp4' },
{ group: 'roundrobin',name: '3', path: 'vids/roundrobin/3.mp4' },
{ group: 'roundrobin',name: '4', path: 'vids/roundrobin/4.mp4' },
{ group: 'roundrobin',name: '5', path: 'vids/roundrobin/5.mp4' },
{ group: 'roundrobin',name: '6', path: 'vids/roundrobin/6.mp4' },
{ group: 'roundrobin',name: '7_dynamic', path: 'vids/roundrobin/7_dynamic.mp4' },
{ group: 'roundrobin',name: '8', path: 'vids/roundrobin/8.mp4' },
{ group: 'roundrobin',name: '9', path: 'vids/roundrobin/9.mp4' },
{ group: 'roundrobin',name: '10', path: 'vids/roundrobin/10.mp4' },
];
const STORAGE_KEY = 'lego_labels_v1';
// ── State ────────────────────────────────────────────────────────────────
let labels = loadLabels(); // { [path]: number[] }
let currentPath = null;
let currentSpeed = 2;
// ── Persistence ──────────────────────────────────────────────────────────
function loadLabels() {
try { return JSON.parse(localStorage.getItem(STORAGE_KEY)) || {}; }
catch { return {}; }
}
function saveLabels() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(labels));
}
// ── Sidebar ───────────────────────────────────────────────────────────────
function buildSidebar() {
const sidebar = document.getElementById('sidebar');
// Remove everything except progress bar
[...sidebar.querySelectorAll('.group-label, .vid-item')].forEach(el => el.remove());
let lastGroup = null;
for (const v of VIDEOS) {
if (v.group !== lastGroup) {
const gl = document.createElement('div');
gl.className = 'group-label';
gl.textContent = v.group;
sidebar.appendChild(gl);
lastGroup = v.group;
}
const item = document.createElement('div');
item.className = 'vid-item' + (v.path === currentPath ? ' active' : '');
item.dataset.path = v.path;
const stamps = labels[v.path] || [];
if (stamps.length > 0) item.classList.add('labeled');
const dot = document.createElement('div');
dot.className = 'dot';
const name = document.createElement('span');
name.textContent = v.name;
const count = document.createElement('span');
count.className = 'count';
count.textContent = stamps.length > 0 ? stamps.length : '';
item.appendChild(dot);
item.appendChild(name);
item.appendChild(count);
item.addEventListener('click', () => loadVideo(v.path, v.name, v.group));
sidebar.appendChild(item);
}
updateProgress();
}
function updateProgress() {
const labeled = VIDEOS.filter(v => (labels[v.path] || []).length > 0).length;
const el = document.getElementById('progress-bar');
el.innerHTML = `<span>${labeled}</span> / ${VIDEOS.length} labeled`;
}
// ── Video loading ─────────────────────────────────────────────────────────
function loadVideo(path, name, group) {
currentPath = path;
const player = document.getElementById('player');
const noVid = document.getElementById('no-video');
player.src = path;
player.playbackRate = currentSpeed;
player.style.display = 'block';
noVid.style.display = 'none';
document.getElementById('vid-title').textContent = `${group} / ${name}`;
player.addEventListener('loadedmetadata', () => { player.playbackRate = currentSpeed; }, { once: true });
player.play().catch(() => {});
buildSidebar();
renderStamps();
}
// ── Time display ──────────────────────────────────────────────────────────
const player = document.getElementById('player');
player.addEventListener('timeupdate', () => {
const c = player.currentTime;
const d = player.duration || 0;
document.getElementById('time-display').textContent =
`${fmt(c, true)} / ${fmt(d, false)}`;
});
function fmt(s, tenths) {
const m = Math.floor(s / 60);
const sec = s % 60;
if (tenths) return `${m}:${String(Math.floor(sec)).padStart(2,'0')}.${Math.floor((sec % 1) * 10)}`;
return `${m}:${String(Math.floor(sec)).padStart(2,'0')}`;
}
// ── Stamping ──────────────────────────────────────────────────────────────
function stampNow() {
if (!currentPath) return;
const t = player.currentTime;
if (!labels[currentPath]) labels[currentPath] = [];
labels[currentPath].push(t);
labels[currentPath].sort((a, b) => a - b);
saveLabels();
renderStamps();
buildSidebar();
// Visual feedback
const btn = document.getElementById('stamp-btn');
btn.classList.remove('flash');
void btn.offsetWidth;
btn.classList.add('flash');
}
function deleteStamp(idx) {
if (!currentPath) return;
labels[currentPath].splice(idx, 1);
if (labels[currentPath].length === 0) delete labels[currentPath];
saveLabels();
renderStamps();
buildSidebar();
}
function seekTo(t) {
player.currentTime = t;
}
function renderStamps() {
const list = document.getElementById('stamp-list');
const stamps = (currentPath && labels[currentPath]) || [];
document.getElementById('stamp-count').textContent = stamps.length;
if (stamps.length === 0) {
list.innerHTML = '<div class="empty-stamps">No timestamps yet</div>';
return;
}
list.innerHTML = '';
stamps.forEach((t, i) => {
const row = document.createElement('div');
row.className = 'stamp-item';
const time = document.createElement('span');
time.className = 'stamp-time';
time.textContent = `#${i+1} ${fmt(t, true)}`;
time.title = 'Click to seek';
time.addEventListener('click', () => seekTo(t));
const del = document.createElement('span');
del.className = 'stamp-del';
del.textContent = '×';
del.title = 'Delete';
del.addEventListener('click', () => deleteStamp(i));
row.appendChild(time);
row.appendChild(del);
list.appendChild(row);
});
}
// ── Keyboard shortcuts ────────────────────────────────────────────────────
document.addEventListener('keydown', e => {
const tag = document.activeElement.tagName;
if (tag === 'INPUT' || tag === 'TEXTAREA') return;
if (e.key === 'l' || e.key === 'L') { e.preventDefault(); stampNow(); }
// Space handled only when video is focused (browser default plays/pauses);
// but if focus is NOT on the video, we stamp
if (e.key === ' ' && document.activeElement !== player) { e.preventDefault(); stampNow(); }
});
// ── Import / Export ───────────────────────────────────────────────────────
function exportLabels() {
const data = JSON.stringify(labels, null, 2);
const blob = new Blob([data], { type: 'application/json' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'lego_labels.json';
a.click();
}
function importLabels(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => {
try {
const imported = JSON.parse(e.target.result);
labels = imported;
saveLabels();
buildSidebar();
renderStamps();
} catch {
alert('Invalid JSON file.');
}
};
reader.readAsText(file);
event.target.value = '';
}
function clearAll() {
if (!confirm('Delete all labels? This cannot be undone.')) return;
labels = {};
saveLabels();
buildSidebar();
renderStamps();
}
// ── Speed control ─────────────────────────────────────────────────────────
function setSpeed(rate) {
currentSpeed = rate;
player.playbackRate = rate;
document.querySelectorAll('.speed-btns button').forEach(btn => {
btn.classList.toggle('active', parseFloat(btn.textContent) === rate);
});
}
// ── Init ──────────────────────────────────────────────────────────────────
buildSidebar();
renderStamps();
setSpeed(2);
</script>
</body>
</html>