Add compact portrait PDF timing report
Beffroi/beffroi-tools/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-10-20 10:54:37 +02:00
parent ea0974f032
commit 8d06f87aba
3 changed files with 68 additions and 10 deletions

View File

@ -15,13 +15,25 @@ python3 tools/pptx_videos.py presentation.pptx --report all
`--report` accepts comma-separated formats and can be repeated. Markdown and
Ontime are included by default; an explicit `--report` replaces this selection.
Use `--report all` for every format, including PDF (requires Typst) and Ontime.
Use `--report all` for every format, including both PDF layouts (requires Typst)
and Ontime.
Reports are saved as `timings.*` in `<presentation-stem>_videos`, or the
directory supplied with `-o`. PDF uses the Typst CLI and retains `timings.typ`
for editing. HTML and Typst/PDF include colored summary cards and pills;
Markdown and TXT use aligned tables. JSON includes numeric durations in seconds,
sizes in bytes, and slide references.
For a compact portrait PDF with only slide numbers and duration pills:
```sh
python3 tools/pptx_videos.py presentation.pptx --timings-only --report pdf-dense
```
This creates `timings-dense.pdf` and its editable `timings-dense.typ` source.
There are no summary cards or video metadata columns. Slide numbers are plain
text; only durations use pills. The duration caveat stays in a small footnote.
Use `--report pdf,pdf-dense` to produce both layouts.
Timings require `ffprobe` (from FFmpeg); PDF additionally requires `typst` on
`PATH`. Use `--extract-only` to extract without a report. Presentations with no
embedded videos produce no output.

View File

@ -106,11 +106,12 @@ class VideoTests(unittest.TestCase):
patch.object(videos, 'probe', return_value=(1.25, '32×24', 'mpeg4')), \
patch.object(videos.subprocess, 'run', side_effect=compile_pdf) as compiler:
self.assertEqual(self.invoke(source, '--timings-only', '--report', ' ALL,md', '--report', 'pdf'), 0)
compiler.assert_called_once()
self.assertEqual(compiler.call_count, 2)
self.assertEqual(
{p.name for p in (self.root / 'sample_videos').iterdir()},
{'timings.html', 'timings.typ', 'timings.pdf', 'timings.md',
'timings.txt', 'timings.json', 'timings.ontime.json'},
'timings.txt', 'timings.json', 'timings.ontime.json',
'timings-dense.typ', 'timings-dense.pdf'},
)
def test_default_reports_include_ontime_and_explicit_choice_overrides(self):
@ -213,6 +214,26 @@ class VideoTests(unittest.TestCase):
self.assertTrue((self.root / 'timings.typ').is_file())
self.assertEqual((self.root / 'timings.pdf').read_bytes(), b'%PDF-test')
def test_dense_pdf_is_portrait_with_only_slide_and_duration_columns(self):
source = videos.render_report(self.report(), 'pdf-dense')
self.assertNotIn('flipped: true', source)
self.assertIn('columns: (1fr, auto)', source)
self.assertIn('table.header(strong("Slide(s)"), strong("Duration"))', source)
self.assertIn('"2, 12", pill("00:00:01.000"', source)
self.assertIn('"Unreferenced", pill("Unknown"', source)
for unwanted in ('metric(', 'Embedded videos', 'Total duration', 'clip.mp4', 'Resolution', 'Codec'):
self.assertNotIn(unwanted, source)
self.assertIn('text(size: 7pt', source)
self.assertIn('trimming', source)
def test_dense_pdf_compiles_its_own_source(self):
with patch.object(videos.subprocess, 'run') as compiler, contextlib.redirect_stdout(io.StringIO()):
videos.write_reports(self.report(), ['pdf-dense'], self.root)
command = compiler.call_args.args[0]
self.assertEqual(command, ['typst', 'compile', str(self.root / 'timings-dense.typ'),
str(self.root / 'timings-dense.pdf')])
self.assertFalse((self.root / 'timings.typ').exists())
def test_failed_probe_returns_unknown_metadata(self):
failure = subprocess.CalledProcessError(1, ['ffprobe'])
with patch.object(videos.subprocess, 'run', side_effect=failure):

View File

@ -26,7 +26,7 @@ VIDEO_EXTS = {'.mp4', '.m4v', '.mov', '.avi', '.wmv', '.webm', '.mpg', '.mpeg',
REL_NS = 'http://schemas.openxmlformats.org/package/2006/relationships'
R_NS = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
P_NS = 'http://schemas.openxmlformats.org/presentationml/2006/main'
REPORT_FORMATS = ('html', 'typst', 'pdf', 'md', 'txt', 'json', 'ontime')
REPORT_FORMATS = ('html', 'typst', 'pdf', 'pdf-dense', 'md', 'txt', 'json', 'ontime')
HEADERS = ('Slide(s)', 'Duration', 'Video', 'Size', 'Resolution', 'Codec')
REPORT_NOTES = (
'Duration is the original media file duration, not slide playback time '
@ -289,6 +289,28 @@ def render_report(data, format):
''.join(f'<p>{html.escape(note)}</p>' for note in notes) +
'</footer></body></html>\n'
)
if format == 'pdf-dense':
lines = [
'#set page(paper: "a4", margin: 14mm,',
' footer: context align(right, text(size: 7pt, fill: rgb("#626b80"), counter(page).display("1"))))',
'#set text(font: "DejaVu Sans", size: 9pt, fill: rgb("#172033"))',
'#set par(justify: false)',
'#let pill(body, bg, fg) = box(fill: rgb(bg), radius: 20pt,',
' inset: (x: 7pt, y: 2pt), text(size: 8pt, fill: rgb(fg), body))',
'#table(',
' columns: (1fr, auto),',
' align: (left + horizon, right + horizon),',
' inset: (x: 8pt, y: 4pt),',
' stroke: (top: none, left: none, right: none, bottom: 0.4pt + rgb("#e2e6f0")),',
' fill: (x, y) => if y == 0 { rgb("#eeeafd") } else if calc.even(y) { rgb("#f8f9fc") },',
' table.header(strong("Slide(s)"), strong("Duration")),',
]
for row, video in zip(cells, data['videos']):
bg, fg = ('#e3f4ee', '#176349') if video['duration_seconds'] is not None else ('#fff0ce', '#805300')
lines.append(f' {typst_string(row[0])}, pill({typst_string(row[1])}, "{bg}", "{fg}"),')
lines += [')', '#v(6pt)']
lines += ['#par(text(size: 7pt, fill: rgb("#626b80"), ' + typst_string(note) + '))' for note in notes]
return '\n'.join(lines) + '\n'
if format == 'typst':
lines = [
'#set page(paper: "a4", flipped: true, margin: 16mm,',
@ -344,14 +366,17 @@ def write_reports(data, formats, out):
if format == 'pdf':
continue
extension = {'typst': 'typ', 'ontime': 'ontime.json'}.get(format, format)
report = out / f'timings.{extension}'
report = out / ('timings-dense.typ' if format == 'pdf-dense' else f'timings.{extension}')
status(f'Writing report: {report}')
report.write_text(render_report(data, format), encoding='utf-8')
status(f'Report: {report}', 'success', persist=True)
if 'pdf' in formats:
report = out / 'timings.pdf'
for format in ('pdf', 'pdf-dense'):
if format not in formats:
continue
stem = 'timings-dense' if format == 'pdf-dense' else 'timings'
report = out / f'{stem}.pdf'
status(f'Compiling PDF with Typst: {report}')
subprocess.run(['typst', 'compile', str((out / 'timings.typ').resolve()),
subprocess.run(['typst', 'compile', str((out / f'{stem}.typ').resolve()),
str(report.resolve())], check=True, capture_output=True, text=True)
status(f'Report: {report}', 'success', persist=True)
@ -365,7 +390,7 @@ def main():
mode.add_argument('--timings-only', action='store_true', help='Report video timings without keeping newly extracted videos')
parser.add_argument('--overwrite', action='store_true', help='Overwrite already extracted files')
parser.add_argument('--report', type=report_formats, action='append', metavar='FORMAT[,FORMAT...]',
help='Report formats: html, typst, pdf, md, txt, json, ontime, or all. Repeatable; default: md,ontime. PDF requires typst and keeps timings.typ.')
help='Report formats: html, typst, pdf, pdf-dense, md, txt, json, ontime, or all. Repeatable; default: md,ontime. PDFs require typst and keep their .typ sources.')
args = parser.parse_args()
if args.extract_only and args.report:
parser.error('--report cannot be combined with --extract-only.')
@ -386,7 +411,7 @@ def main():
status(f'Found {len(videos)} embedded video(s), {size_fmt(sum(z.getinfo(part).file_size for part in videos))} in the presentation.')
if not args.extract_only and shutil.which('ffprobe') is None:
parser.error('ffprobe is required for timings. Install ffmpeg or use --extract-only.')
if not args.extract_only and 'pdf' in formats and shutil.which('typst') is None:
if not args.extract_only and {'pdf', 'pdf-dense'}.intersection(formats) and shutil.which('typst') is None:
parser.error('typst is required for PDF reports. Install the Typst CLI or choose --report typst to generate source only.')
mode_label = 'extraction only' if args.extract_only else 'timings only' if args.timings_only else 'extraction and timings'
status(f'Mode: {mode_label}. Output: {out}')