Separate extracted videos and reports into subfolders
This commit is contained in:
parent
b7792f6bf4
commit
c707bd99d8
|
|
@ -10,6 +10,8 @@ with quick-start examples and links to detailed documentation in `docs/`.
|
|||
slides, probes metadata with FFmpeg's `ffprobe`, and generates timing reports
|
||||
in Markdown, plain text, JSON, HTML, Typst, PDF, and Ontime 4 JSON. Markdown
|
||||
and Ontime are the defaults. PDF reports compile through the Typst CLI.
|
||||
Its output root contains `videos/` for media and `reports/` for reports and
|
||||
Typst sources; report media links are relative to `reports/`.
|
||||
- `tools/ontime.py` maps video references into an importable Ontime rundown.
|
||||
- `tools/progress.py` provides shared transient terminal progress and plain logs
|
||||
for redirected output; `tests/test_progress.py` checks display cleanup.
|
||||
|
|
|
|||
|
|
@ -17,8 +17,26 @@ python3 tools/pptx_videos.py presentation.pptx --report all
|
|||
Ontime are included by default; an explicit `--report` replaces this selection.
|
||||
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`
|
||||
The output root is `<presentation-stem>_videos`, or the directory supplied with
|
||||
`-o`. Extracted media goes in `videos/`; all reports and Typst sources go in
|
||||
`reports/`:
|
||||
|
||||
```text
|
||||
presentation_videos/
|
||||
├── videos/
|
||||
│ └── media1.mp4
|
||||
└── reports/
|
||||
├── timings.md
|
||||
└── timings.ontime.json
|
||||
```
|
||||
|
||||
Markdown and HTML links point to `../videos/`; JSON `extracted_file` paths are
|
||||
relative to the report directory too. `--timings-only` reuses media in `videos/`
|
||||
when available, otherwise probes temporary copies without creating that folder.
|
||||
`--extract-only` creates no report folder. Existing files from the old flat
|
||||
layout are not moved automatically.
|
||||
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -79,21 +79,43 @@ class VideoTests(unittest.TestCase):
|
|||
with patch.object(videos.shutil, 'which', return_value='/ffprobe'), patch.object(videos, 'probe', side_effect=probe):
|
||||
self.assertEqual(self.invoke(source, '--timings-only', '--report', 'json,md'), 0)
|
||||
output = self.root / 'sample_videos'
|
||||
self.assertFalse((output / 'clip.mp4').exists())
|
||||
self.assertFalse((output / 'videos').exists())
|
||||
self.assertEqual(len(probed), 1)
|
||||
self.assertFalse(probed[0].exists())
|
||||
data = json.loads((output / 'timings.json').read_text())
|
||||
data = json.loads((output / 'reports' / 'timings.json').read_text())
|
||||
self.assertEqual(data['videos'][0]['duration_seconds'], 1.25)
|
||||
self.assertIsNone(data['videos'][0]['extracted_file'])
|
||||
self.assertNotIn('[clip.mp4]', (output / 'timings.md').read_text())
|
||||
self.assertNotIn('[clip.mp4]', (output / 'reports' / 'timings.md').read_text())
|
||||
|
||||
def test_extract_only_does_not_probe_or_write_reports(self):
|
||||
source = self.deck()
|
||||
with patch.object(videos, 'probe', side_effect=AssertionError('No probing')):
|
||||
self.assertEqual(self.invoke(source, '--extract-only'), 0)
|
||||
output = self.root / 'sample_videos'
|
||||
self.assertEqual([p.name for p in output.iterdir()], ['clip.mp4'])
|
||||
self.assertEqual((output / 'clip.mp4').read_bytes(), b'video fixture')
|
||||
self.assertEqual([p.name for p in output.iterdir()], ['videos'])
|
||||
self.assertEqual((output / 'videos' / 'clip.mp4').read_bytes(), b'video fixture')
|
||||
|
||||
def test_separate_folders_and_relative_media_links(self):
|
||||
source = self.root / 'linked.pptx'
|
||||
with zipfile.ZipFile(source, 'w') as archive:
|
||||
archive.writestr('ppt/media/clip #1.mp4', b'video fixture')
|
||||
output = self.root / 'custom output'
|
||||
media = output / 'videos' / 'clip #1.mp4'
|
||||
reports = output / 'reports'
|
||||
with patch.object(videos.shutil, 'which', return_value='/ffprobe'), \
|
||||
patch.object(videos, 'probe', return_value=(1.25, '32×24', 'mpeg4')) as probe:
|
||||
self.assertEqual(self.invoke(source, '-o', str(output), '--report', 'md,html,json'), 0)
|
||||
probe.assert_called_once_with(media)
|
||||
probe.reset_mock()
|
||||
self.assertEqual(self.invoke(source, '-o', str(output), '--timings-only', '--report', 'json'), 0)
|
||||
probe.assert_called_once_with(media)
|
||||
self.assertEqual({p.name for p in output.iterdir()}, {'videos', 'reports'})
|
||||
self.assertEqual(media.read_bytes(), b'video fixture')
|
||||
self.assertIn('](../videos/clip%20%231.mp4)', (reports / 'timings.md').read_text())
|
||||
self.assertIn('href="../videos/clip%20%231.mp4"', (reports / 'timings.html').read_text())
|
||||
data = json.loads((reports / 'timings.json').read_text())
|
||||
self.assertEqual(data['videos'][0]['extracted_file'], '../videos/clip #1.mp4')
|
||||
self.assertEqual((reports / data['videos'][0]['extracted_file']).resolve(), media.resolve())
|
||||
|
||||
def test_all_reports_generate_every_format_once(self):
|
||||
source = self.deck()
|
||||
|
|
@ -108,7 +130,7 @@ class VideoTests(unittest.TestCase):
|
|||
self.assertEqual(self.invoke(source, '--timings-only', '--report', ' ALL,md', '--report', 'pdf'), 0)
|
||||
self.assertEqual(compiler.call_count, 2)
|
||||
self.assertEqual(
|
||||
{p.name for p in (self.root / 'sample_videos').iterdir()},
|
||||
{p.name for p in (self.root / 'sample_videos' / 'reports').iterdir()},
|
||||
{'timings.html', 'timings.typ', 'timings.pdf', 'timings.md',
|
||||
'timings.txt', 'timings.json', 'timings.ontime.json',
|
||||
'timings-dense.typ', 'timings-dense.pdf'},
|
||||
|
|
@ -119,15 +141,15 @@ class VideoTests(unittest.TestCase):
|
|||
with patch.object(videos.shutil, 'which', return_value='/ffprobe'), \
|
||||
patch.object(videos, 'probe', return_value=(1.25, '32×24', 'mpeg4')):
|
||||
self.assertEqual(self.invoke(source, '--timings-only'), 0)
|
||||
output = self.root / 'sample_videos'
|
||||
output = self.root / 'sample_videos' / 'reports'
|
||||
self.assertEqual({p.name for p in output.iterdir()}, {'timings.md', 'timings.ontime.json'})
|
||||
other = self.deck(name='explicit.pptx')
|
||||
self.assertEqual(self.invoke(other, '--timings-only', '--report', 'json,ontime'), 0)
|
||||
output = self.root / 'explicit_videos'
|
||||
output = self.root / 'explicit_videos' / 'reports'
|
||||
self.assertEqual({p.name for p in output.iterdir()}, {'timings.json', 'timings.ontime.json'})
|
||||
other = self.deck(name='markdown.pptx')
|
||||
self.assertEqual(self.invoke(other, '--timings-only', '--report', 'md'), 0)
|
||||
self.assertEqual({p.name for p in (self.root / 'markdown_videos').iterdir()}, {'timings.md'})
|
||||
self.assertEqual({p.name for p in (self.root / 'markdown_videos' / 'reports').iterdir()}, {'timings.md'})
|
||||
|
||||
def test_ontime_expands_shared_videos_in_slide_order(self):
|
||||
project = json.loads(videos.render_report(self.report(), 'ontime'))
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ def report_data(source, rows, uses, external, out):
|
|||
'slides': sorted(uses[part]), 'duration_seconds': duration,
|
||||
'name': name, 'size_bytes': size, 'resolution': resolution,
|
||||
'codec': codec, 'archive_path': part,
|
||||
'extracted_file': name if (out / name).is_file() else None,
|
||||
'extracted_file': f'../videos/{name}' if (out / 'videos' / name).is_file() else None,
|
||||
})
|
||||
return {
|
||||
'presentation': source.name,
|
||||
|
|
@ -401,6 +401,8 @@ def main():
|
|||
if not source.is_file():
|
||||
parser.error(f'Not a file: {source}')
|
||||
out = args.output or source.with_name(source.stem + '_videos')
|
||||
video_dir = out / 'videos'
|
||||
report_dir = out / 'reports'
|
||||
try:
|
||||
with Progress() as progress, zipfile.ZipFile(source) as z:
|
||||
status(f'Scanning presentation: {source}')
|
||||
|
|
@ -417,7 +419,8 @@ def main():
|
|||
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}')
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
if not args.timings_only:
|
||||
video_dir.mkdir(parents=True, exist_ok=True)
|
||||
rows = []
|
||||
total_bytes = 0
|
||||
total_seconds = 0.0
|
||||
|
|
@ -425,7 +428,7 @@ def main():
|
|||
progress.set(0, len(videos))
|
||||
for index, part in enumerate(videos, 1):
|
||||
name = posixpath.basename(part)
|
||||
dest = out / name
|
||||
dest = video_dir / name
|
||||
slides = ', '.join(map(str, sorted(uses[part]))) or 'unreferenced'
|
||||
status(f'[{index}/{len(videos)}] {name} — {size_fmt(z.getinfo(part).file_size)} — slide(s): {slides}')
|
||||
if not args.timings_only:
|
||||
|
|
@ -466,9 +469,10 @@ def main():
|
|||
rows.append((part, name, size, duration, resolution, codec))
|
||||
progress.set(index)
|
||||
if args.extract_only:
|
||||
status(f'Done: {len(videos)} video(s) processed. Output: {out}', 'success', persist=True)
|
||||
status(f'Done: {len(videos)} video(s) processed. Output: {video_dir}', 'success', persist=True)
|
||||
return 0
|
||||
write_reports(report_data(source, rows, uses, external, out), formats, out)
|
||||
report_dir.mkdir(parents=True, exist_ok=True)
|
||||
write_reports(report_data(source, rows, uses, external, out), formats, report_dir)
|
||||
status(f'Done: {known}/{len(videos)} durations available, {time_fmt(total_seconds)} total, {size_fmt(total_bytes)}.', 'success', persist=True)
|
||||
return 0
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
|
|
|||
Loading…
Reference in New Issue