Fix minor script things.

This commit is contained in:
Niels G. W. Serup 2016-08-25 01:35:03 +02:00
parent cba5b8d2ae
commit 96de50de15
1 changed files with 12 additions and 12 deletions

View File

@ -23,14 +23,14 @@ def load_settings(settings_file):
in (line.split('=', 1) for line in
f.read().strip().split('\n'))}
return settings
def load_media(media_file):
with open(media_file) as f:
c = yaml.load(f)
c['year'] = int(c['year'])
c['ident'] = ident(media_file)
return c
def ident(media_file):
return os.path.splitext(os.path.split(media_file)[1])[0]
@ -43,9 +43,8 @@ def thumbnail_url(link):
def setup_directory_structure(settings, base_dir, template_dir):
site_new_dir = os.path.join(base_dir, 'site-new')
os.mkdir(site_new_dir)
extern_dir = os.path.join(base_dir, 'extern')
extern_dir_site = os.path.join(site_new_dir, 'extern')
os.symlink(extern_dir, extern_dir_site)
os.symlink(os.path.join('..', 'extern'), extern_dir_site)
style = read(os.path.join(template_dir, 'style.css'))
style_out = style.replace('{', '{{').replace('}', '}}') \
@ -62,7 +61,7 @@ def publish_new_site(site_dir, site_new_dir):
def generate_index_page(out_dir, base_html, section_html, medias):
sections = [generate_video_section_html(section_html, media)
for media in medias]
all_sections = '\n'.join(sections)
html_out = base_html.format(content=all_sections,
style_url='style.css')
@ -83,19 +82,20 @@ def generate_video_section_html(section_html, media):
def extern_video(file_src):
url = '../extern/' + file_src
return '''\
<video src="{file_src}" controls height="427">
<video src="{url}" controls height="427">
Your browser cannot play this video. You can download it here instead:
<a href="{file_src}">{file_src}</a>
<a href="{url}">{url}</a>
</video>
'''.format(file_src=file_src)
'''.format(url=url)
def youtube_video(file_src):
yt_id = file_src
return '''\
<iframe type="text/html" width="760" height="427"
src="https://www.youtube.com/embed/{file_src}?controls=2"
src="https://www.youtube.com/embed/{yt_id}?controls=2"
allowfullscreen frameborder="0">
</iframe>
'''.format(file_src=file_src)
'''.format(yt_id=yt_id)
def generate_video_page(base_dir, out_dir, base_html, showing_html, media):
title = media['title']
@ -115,7 +115,7 @@ def generate_video_page(base_dir, out_dir, base_html, showing_html, media):
'youtube': youtube_video
}
video_html = actions[file_type](file_src)
html_inner = showing_html.format(
title=html.escape(title),
year=str(year),
@ -151,7 +151,7 @@ def main():
media)
site_dir = os.path.join(base_dir, 'site')
publish_new_site(site_dir, site_new_dir)
return 0
if __name__ == '__main__':