#!/usr/bin/env python3 """Build the portable HTML gallery for the completed website/social delivery.""" import base64 import hashlib import html import json from pathlib import Path import re import subprocess from fractions import Fraction from urllib.parse import quote ROOT = Path(__file__).resolve().parents[2] OUT = ROOT / 'output/video-refresh-20261023/workspace/delivery' CDN = 'https://media.jotley.ai/' def title(path): name = path.stem if re.match(r'jotley-marketing-v\d+', name): return 'Marketing film' + (' · portrait' if 'portrait' in name else '') if name.startswith('jotley-tutorial-'): return 'Jotley on ' + {'iphone': 'iPhone', 'ipad': 'iPad', 'mac': 'Mac'}[name.split('-')[2]] if name.startswith('jotley-social-ui'): return 'Short social promo' + (' · portrait' if 'portrait' in name else ' · landscape') if '-Portrait-Tutorial-' in name: return name.split('-')[1] + ' · full portrait tutorial' if '-Portrait-Clip-' in name: device = name.split('-')[1] label = re.sub(r'-1080x1920-60fps$', '', name.split('-Portrait-Clip-')[1]) return device + ' · ' + re.sub(r'^\d+-', '', label).replace('-', ' ') return name.replace('-v2', '').replace('-v3', '').replace('-', ' ').replace('iphone', 'iPhone').replace('mac', 'Mac') def main(): posters = OUT / 'posters' posters.mkdir(exist_ok=True) files = [] for path in sorted(OUT.rglob('*.mp4')): if 'qc' in path.parts or not path.with_suffix('.verification.json').exists(): continue probe = json.loads(subprocess.check_output(['ffprobe', '-v', 'error', '-show_streams', '-show_format', '-of', 'json', str(path)])) stream = next(s for s in probe['streams'] if s['codec_type'] == 'video') relative = path.relative_to(OUT).as_posix() key = relative.removeprefix('website/') if relative.startswith('website/') else 'social/20261023/' + path.relative_to(OUT / 'social').as_posix() group = ('Website films' if '/films/' in relative else 'Website screen clips' if '/clips/' in relative else 'Social feature clips' if '-Portrait-Clip-' in path.name else 'Social portrait tutorials' if '-Portrait-Tutorial-' in path.name else 'Social marketing') variant = re.search(r'-(2160p|1080p|720p)$', path.stem) variant = variant[1] if variant else '1080 × 1920' if stream['height'] == 1920 else f"{stream['width']} × {stream['height']}" poster = posters / (path.stem + '.webp') if not poster.exists(): subprocess.run(['ffmpeg', '-v', 'error', '-y', '-ss', str(min(2, float(probe['format']['duration']) / 3)), '-i', str(path), '-frames:v', '1', '-vf', 'scale=640:-1', '-c:v', 'libwebp', '-quality', '85', str(poster)], check=True) files.append({'title': title(path), 'group': group, 'variant': variant, 'local': relative, 'key': key, 'url': CDN + quote(key, safe='/'), 'poster': poster.relative_to(OUT).as_posix(), 'width': stream['width'], 'height': stream['height'], 'seconds': float(probe['format']['duration']), 'fps': float(Fraction(stream['avg_frame_rate'])), 'bytes': path.stat().st_size, 'sha256': hashlib.file_digest(path.open('rb'), 'sha256').hexdigest()}) (OUT / 'videos.json').write_text(json.dumps(files, indent=2) + '\n') grouped = {} for file in files: grouped.setdefault((file['group'], file['title']), []).append(file) sections = [] for group in ['Website films', 'Social marketing', 'Social portrait tutorials', 'Social feature clips', 'Website screen clips']: cards = [] for (category, label), variants in grouped.items(): if category != group: continue selected = next((f for f in variants if f['variant'] == '1080p'), variants[0]) data = html.escape(json.dumps(variants), quote=True) seconds = round(selected['seconds']) duration = f'{seconds // 60}:{seconds % 60:02d}' options = ''.join(f'' for i, f in enumerate(variants)) links = ' · '.join(f'{html.escape(f["variant"])}' for f in variants) portrait = selected['height'] > selected['width'] marketing = bool(re.match(r'jotley-marketing-v\d+', Path(selected['local']).stem)) search = group + ' ' + label + (' six accent colors neutral gray titles tags' if marketing else '') chapter = '' if marketing else '' captions = '' if selected['local'].startswith('website/films/jotley-tutorial-'): stem = re.sub(r'-(2160p|1080p|720p)$', '', Path(selected['local']).stem) captions = f'' poster_data = 'data:image/webp;base64,' + base64.b64encode((OUT / selected['poster']).read_bytes()).decode() cards.append(f'''

{html.escape(label)}

{duration} · {selected['width']} × {selected['height']} · {selected['fps']:g} fps

{links}{chapter}
''') sections.append(f'

{group}

' + ''.join(cards) + '
') document = ''' Jotley · Website & Social Video Library
23 October 2026 · Updated app interface

Jotley video library.

All refreshed website films, tutorials and social videos, together in one place. The main marketing film keeps its established story and music, with the styling narration covering six accent colors, including neutral gray. The titles-and-tags section uses the current interface. Choose a quality to watch or use the links to download.

SECTIONS
''' nav = ''.join(f'{group}' for group in ['Website films', 'Social marketing', 'Social portrait tutorials', 'Social feature clips', 'Website screen clips']) document = document.replace('NAV', nav).replace('SECTIONS', ''.join(sections)).replace('COUNT', str(len(files))) (OUT / 'Jotley-Video-Library.html').write_text(document) print(f'Gallery: {len(files)} files, {len(grouped)} players') if __name__ == '__main__': main()