1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[postprocessor:mtime] add 'value' option (#2739)

This commit is contained in:
bradenhilton 2022-07-08 19:56:01 +01:00 committed by GitHub
parent 90ae48c40c
commit 117eeefda0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 8 deletions

View File

@ -3464,6 +3464,24 @@ Description
This value must either be a UNIX timestamp or a
|datetime|_ object.
Note: This option gets ignored if `mtime.value`_ is set.
mtime.value
-----------
Type
``string``
Default
``null``
Example
* ``"{status[date]}"``
* ``"{content[0:6]:R22/2022/D%Y%m%d/}"``
Description
A `format string`_ whose value should be used.
The resulting value must either be a UNIX timestamp or a
|datetime|_ object.
ugoira.extension
----------------

View File

@ -9,7 +9,7 @@
"""Use metadata as file modification time"""
from .common import PostProcessor
from .. import text, util
from .. import text, util, formatter
from datetime import datetime
@ -17,7 +17,12 @@ class MtimePP(PostProcessor):
def __init__(self, job, options):
PostProcessor.__init__(self, job)
self.key = options.get("key", "date")
value = options.get("value")
if value:
self._get = formatter.parse(value, None, util.identity).format_map
else:
key = options.get("key", "date")
self._get = lambda kwdict: kwdict.get(key)
events = options.get("event")
if events is None:
@ -27,7 +32,7 @@ class MtimePP(PostProcessor):
job.register_hooks({event: self.run for event in events}, options)
def run(self, pathfmt):
mtime = pathfmt.kwdict.get(self.key)
mtime = self._get(pathfmt.kwdict)
pathfmt.kwdict["_mtime"] = (
util.datetime_to_timestamp(mtime)
if isinstance(mtime, datetime) else

View File

@ -350,10 +350,6 @@ class MetadataTest(BasePostprocessorTest):
class MtimeTest(BasePostprocessorTest):
def test_mtime_default(self):
pp = self._create()
self.assertEqual(pp.key, "date")
def test_mtime_datetime(self):
self._create(None, {"date": datetime(1980, 1, 1)})
self._trigger()
@ -364,11 +360,16 @@ class MtimeTest(BasePostprocessorTest):
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
def test_mtime_custom(self):
def test_mtime_key(self):
self._create({"key": "foo"}, {"foo": 315532800})
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
def test_mtime_value(self):
self._create({"value": "{foo}"}, {"foo": 315532800})
self._trigger()
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
class ZipTest(BasePostprocessorTest):