diff --git a/sigal/gallery.py b/sigal/gallery.py index dc5e7f0..6023d85 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -44,7 +44,7 @@ from .compat import PY2, UnicodeMixin, strxfrm, url_quote, text_type from .image import process_image, get_exif_tags, get_exif_data from .settings import get_thumb from .utils import (Devnull, copy, check_or_create_dir, url_from_path, - read_markdown, cached_property) + read_markdown, cached_property, is_valid_html5_video) from .video import process_video from .writer import Writer @@ -176,11 +176,12 @@ class Video(Media): def __init__(self, filename, path, settings): super(Video, self).__init__(filename, path, settings) - base = splitext(filename)[0] + (base, ext) = splitext(filename) self.date = None self.src_filename = filename - self.filename = self.url = base + '.webm' - self.dst_path = join(settings['destination'], path, base + '.webm') + if not settings['use_orig'] or not is_valid_html5_video(ext): + self.filename = self.url = base + '.webm' + self.dst_path = join(settings['destination'], path, base + '.webm') class Album(UnicodeMixin): diff --git a/sigal/utils.py b/sigal/utils.py index 3e93992..62ed276 100644 --- a/sigal/utils.py +++ b/sigal/utils.py @@ -99,6 +99,9 @@ def call_subprocess(cmd): stdout = stdout.decode('utf8') return p.returncode, stdout, stderr +def is_valid_html5_video(ext): + """Checks if ext is a supported HTML5 video.""" + return ext in ('.mp4', '.webm', '.ogv') class cached_property(object): """ A property that is only computed once per instance and then replaces diff --git a/sigal/video.py b/sigal/video.py index 8d827eb..0193824 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -29,9 +29,9 @@ import re import shutil from os.path import splitext -from . import image +from . import image, utils from .settings import get_thumb, Status -from .utils import call_subprocess +from .utils import call_subprocess, is_valid_html5_video class SubprocessException(Exception): @@ -75,12 +75,12 @@ def video_size(source): return x, y -def generate_video(source, outname, size, options=None): +def generate_video(source, outname, settings, options=None): """Video processor. :param source: path to a video :param outname: path to the generated video - :param size: size of the resized video `(width, height)` + :param settings: settings dict :param options: array of options passed to ffmpeg """ @@ -89,7 +89,7 @@ def generate_video(source, outname, size, options=None): # Don't transcode if source is in the required format and # has fitting datedimensions, copy instead. w_src, h_src = video_size(source) - w_dst, h_dst = size + w_dst, h_dst = settings['video_size'] logger.debug('Video size: %i, %i -> %i, %i', w_src, h_src, w_dst, h_dst) base, src_ext = splitext(source) @@ -149,12 +149,16 @@ def process_video(filepath, outpath, settings): """Process a video: resize, create thumbnail.""" filename = os.path.split(filepath)[1] - basename = splitext(filename)[0] - outname = os.path.join(outpath, basename + '.webm') + (basename, ext) = splitext(filename) try: - generate_video(filepath, outname, settings['video_size'], - options=settings['webm_options']) + if settings['use_orig'] and is_valid_html5_video(ext): + outname = os.path.join(outpath, filename) + utils.copy(filepath, outname, symlink=settings['orig_link']) + else: + outname = os.path.join(outpath, basename + '.webm') + generate_video(filepath, outname, settings, + options=settings['webm_options']) except Exception: return Status.FAILURE diff --git a/tests/test_gallery.py b/tests/test_gallery.py index 559f0c9..759fcfa 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -114,6 +114,7 @@ def test_image(settings, tmpdir): def test_video(settings, tmpdir): settings['destination'] = str(tmpdir) + settings['use_orig'] = False m = Video('stallman software-freedom-day-low.ogv', 'video', settings) file_path = join('video', 'stallman software-freedom-day-low.webm') assert str(m) == file_path