[pp:mtime] fix '_mtime_meta' for invalid values (#8918)

fixes regression introduced in d57dc48dcd
also prevents previous _mtime_meta entries from affecting new files
This commit is contained in:
Mike Fährmann
2026-01-24 17:50:10 +01:00
parent 3836c2a99f
commit 291fb78995
3 changed files with 23 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2019-2022 Mike Fährmann
# Copyright 2019-2026 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -30,15 +30,14 @@ class MtimePP(PostProcessor):
job.register_hooks({event: self.run for event in events}, options)
def run(self, pathfmt):
mtime = self._get(pathfmt.kwdict)
if mtime is None:
return
pathfmt.kwdict["_mtime_meta"] = (
dt.to_ts(mtime)
if isinstance(mtime, dt.datetime) else
text.parse_int(mtime)
)
if mtime := self._get(pathfmt.kwdict):
if isinstance(mtime, dt.datetime):
mtime = dt.to_ts(mtime)
else:
mtime = text.parse_int(mtime)
else:
mtime = None
pathfmt.kwdict["_mtime_meta"] = mtime
__postprocessor__ = MtimePP

View File

@@ -6,5 +6,5 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
__version__ = "1.31.4"
__version__ = "1.31.5-dev"
__variant__ = None

View File

@@ -21,7 +21,7 @@ from datetime import datetime
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from gallery_dl import extractor, output, path, util, exception # noqa E402
from gallery_dl import postprocessor, config, archive # noqa E402
from gallery_dl import postprocessor, config, archive, dt # noqa E402
from gallery_dl.postprocessor.common import PostProcessor # noqa E402
@@ -931,12 +931,22 @@ class MtimeTest(BasePostprocessorTest):
def test_mtime_none(self):
self._create(None, {"date": None})
self._trigger()
self.assertNotIn("_mtime_meta", self.pathfmt.kwdict)
self.assertFalse(self.pathfmt.kwdict["_mtime_meta"])
def test_mtime_none_dt(self):
self._create(None, {"date": dt.NONE})
self._trigger()
self.assertFalse(self.pathfmt.kwdict["_mtime_meta"])
def test_mtime_undefined(self):
self._create(None, {})
self._trigger()
self.assertNotIn("_mtime_meta", self.pathfmt.kwdict)
self.assertFalse(self.pathfmt.kwdict["_mtime_meta"])
def test_mtime_invalid(self):
self._create(None, {"date": "foobar"})
self._trigger()
self.assertFalse(self.pathfmt.kwdict["_mtime_meta"])
def test_mtime_key(self):
self._create({"key": "foo"}, {"foo": 315532800})