You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

78 lines
2.3 KiB

#!/usr/bin/env python3
from pathlib import Path
import sys
source = Path(sys.argv[1])
source_videos = source / "videos"
out_tags = {}
out_videos = {}
for video in source_videos.iterdir():
if video.is_dir():
slug = video.name
if slug not in out_videos:
out_videos[slug] = {
"tags": [],
}
tagfile = video / "tags"
if not tagfile.is_dir():
with tagfile.open() as tags:
for tag in tags.readlines():
tag = tag.strip()
out_videos[slug]["tags"].append(tag)
if tag not in out_tags:
out_tags[tag] = {
"videos": [],
"count_videos": None,
}
out_tags[tag]["videos"].append(slug)
for tag in out_tags:
out_tags[tag]["count_videos"] = len(out_tags[tag]["videos"])
print(out_tags)
from jinja2 import Environment, FileSystemLoader, select_autoescape
env = Environment(
loader=FileSystemLoader('./templates'),
autoescape=select_autoescape(['html'])
)
from datetime import datetime
import random
# Output
# Create output dir
out_dir = Path("./out")
out_dir.mkdir(parents=True, exist_ok=True)
# Create main page
templ = env.get_template('index.html')
templ.stream(featured_tags=random.sample(list(out_tags), 6), out_tags=out_tags, out_videos=out_videos).dump(str((out_dir / "index.html").resolve()))
# Create about pages
out_dir_about = out_dir / "about"
out_dir_about.mkdir(parents=True, exist_ok=True)
# Create about page
templ = env.get_template('about.html')
templ.stream(last_update=datetime.now().strftime("%Y-%m-%d %H:%M:%S")).dump(str((out_dir_about / "index.html").resolve()))
# Create tag pages
out_dir_tag = out_dir / "tag"
out_dir_tag.mkdir(parents=True, exist_ok=True)
# Create tag page
templ = env.get_template('tags.html')
templ.stream(sorted_tags=sorted(out_tags), out_tags=out_tags, out_videos=out_videos).dump(str((out_dir_tag / "index.html").resolve()))
templ = env.get_template('tag.html')
for tag, tag_obj in out_tags.items():
out_dir_tag_this = out_dir_tag / tag
out_dir_tag_this.mkdir(parents=True, exist_ok=True)
templ.stream(tag=tag, slugs=tag_obj["videos"], out_tags=out_tags, out_videos=out_videos).dump(str((out_dir_tag_this / "index.html").resolve()))