#! /usr/bin/env python3 import os import subprocess SECTIONS = { 'drift': 'Drift', 'fs': 'FreeStyle', 'k': 'K projects', 'lol': 'LOL', 'pf': 'Press Forward', 'ta': 'Time Attack', 'trial': 'Trial', } def card(name, web, raw): return f'''\

{name}
''' def a(href, text, active=False): html = ['{text}') return str().join(html) def nav(sections, active): html = ['') return str().join(html) def body(sections): html = [] for _, section in sorted(sections.items()): html.append(f'
') html.append(section['content']) html.append('
') return str().join(html) def html(body): return f'''\ TrackMania vidz {body} ''' def main(): file = os.path.realpath(__file__) root = os.path.dirname(file) raw_root = os.path.join(root, 'raw') web_root = os.path.join(root, 'web') _, categories, _ = next(os.walk(raw_root)) sections = { ' ': {'id': 'home', 'label': '⋅', 'content': str()}, } for category in categories: section = { 'id': category, 'label': SECTIONS.get(category, category), } content = [] raw_category = os.path.join(raw_root, category) videos = {} for directory, directories, files in os.walk(raw_category): for file in files: relative = os.path.relpath(directory, raw_root) name, _ = os.path.splitext(file) raw_file = os.path.join('raw', relative, file) web_file = os.path.join('web', relative, f'{name}.mp4') videos[name] = [web_file, raw_file] for name, files in sorted(videos.items()): web_file, raw_file = files content.append(card(name, web_file, raw_file)) section['content'] = os.linesep.join([ '
', os.linesep.join(content), '
']) sections[category] = section for id, section in sections.items(): section['content'] = nav(sections, id) + section['content'] index = os.path.join(root, 'index.html') with open(index, 'w') as i: i.write(html(body(sections))) if __name__ == '__main__': main()