Merge pull request #447

This commit is contained in:
Simon Conseil
2021-10-15 09:10:14 +02:00
6 changed files with 37 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ alphabetical order):
- @trapperhoney
- @tudacs
- Thomas Misilo
- Tim AtLee
- Tim Davies
- Tobias Preuss
- Toke Høiland-Jørgensen (@tohojo)

View File

@@ -12,6 +12,7 @@ Sigal now requires Python 3.7+.
- Add option ``max_img_pixels`` to allow processing huge images (sets
``PIL.Image.MAX_IMAGE_PIXELS``) [:issue:`431`].
- Add webp to the list of images formats supported by default [:issue:`433`].
- Allow specifying the file date in the Markdown metadata file [:issue:`447`].
Version 2.2
~~~~~~~~~~~

View File

@@ -6,6 +6,7 @@ Additional information on an image can be given in a file using the `markdown`_
syntax, named ``<imagename>.md`` (example: ``IMG_5206.md``)::
Title: My awesome photo
Date: 2020-01-01T09:00:00
And a description with *Markdown* syntax.
@@ -13,6 +14,8 @@ EXIF data is directly extracted, see :ref:`simple-exif-data`. Some meta-data
keys are used by Sigal to get the useful informations on the gallery:
- *Title*: the image title.
- *Date*: the file date, useful when it cannot be read from the EXIF metadata,
e.g. for videos and some image formats.
Any additional meta-data is available in the templates. For instance::

View File

@@ -4,6 +4,7 @@
# Copyright (c) 2015 - François D.
# Copyright (c) 2017 - Mate Lakat
# Copyright (c) 2018 - Edwin Steele
# Copyright (c) 2021 - Tim AtLee
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
@@ -294,7 +295,6 @@ class Video(Media):
def __init__(self, filename, path, settings):
super().__init__(filename, path, settings)
self.date = self._get_file_date()
if not settings['use_orig'] or not is_valid_html5_video(self.src_ext):
video_format = settings['video_format']
@@ -304,6 +304,20 @@ class Video(Media):
else:
self.mime = get_mime(self.src_ext)
@cached_property
def date(self):
"""The date from the Date metadata if available, or from the file date."""
if 'date' in self.meta:
try:
self.logger.debug("Reading date from image metadata : %s",
self.src_filename)
return datetime.fromisoformat(self.meta['date'][0])
except Exception:
self.logger.debug("Reading date from image metadata failed : %s",
self.src_filename)
# If no date is found in the metadata, return the file date.
return self._get_file_date()
class Album:
"""Gather all informations on an album.

View File

@@ -0,0 +1 @@
Date: 2020-01-01T09:00:00

View File

@@ -1,4 +1,5 @@
import os
from datetime import datetime
from unittest.mock import patch
import pytest
@@ -48,6 +49,21 @@ def test_process_video(tmpdir):
assert process_video(video) == Status.FAILURE
def test_metadata(tmpdir):
base, ext = os.path.splitext(TEST_VIDEO)
settings = create_settings(
video_format='ogv',
use_orig=True,
orig_link=True,
source=os.path.join(SRCDIR, 'video'),
destination=str(tmpdir),
)
video = Video(TEST_VIDEO, '.', settings)
assert video.meta == {'date': ['2020-01-01T09:00:00']}
assert video.date == datetime(2020, 1, 1, 9, 0)
@pytest.mark.parametrize("fmt", ['webm', 'mp4'])
def test_generate_video_fit_height(tmpdir, fmt):
"""largest fitting dimension is height"""