From 291fb789955706120a1c7b080a1105ef1fa4516d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 24 Jan 2026 17:50:10 +0100 Subject: [PATCH] [pp:mtime] fix '_mtime_meta' for invalid values (#8918) fixes regression introduced in d57dc48dcdb13019555ce11f0f5980051aefe761 also prevents previous _mtime_meta entries from affecting new files --- gallery_dl/postprocessor/mtime.py | 19 +++++++++---------- gallery_dl/version.py | 2 +- test/test_postprocessor.py | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/gallery_dl/postprocessor/mtime.py b/gallery_dl/postprocessor/mtime.py index 7d4796e7..ea0d8a99 100644 --- a/gallery_dl/postprocessor/mtime.py +++ b/gallery_dl/postprocessor/mtime.py @@ -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 diff --git a/gallery_dl/version.py b/gallery_dl/version.py index 8ec2a838..b107b8c5 100644 --- a/gallery_dl/version.py +++ b/gallery_dl/version.py @@ -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 diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index e4d01c2d..7a830a15 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -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})