fix Last-Modified mtime overwriting post processor mtime (#7529)

https://github.com/mikf/gallery-dl/issues/7529#issuecomment-2989955455

- split '_mtime' into '_mtime_http' and '_mtime_meta'
- add PathFormat.set_mtime() method
This commit is contained in:
Mike Fährmann
2025-06-20 16:19:37 +02:00
parent 74c9356442
commit 9e56d81292
6 changed files with 18 additions and 19 deletions

View File

@@ -349,11 +349,11 @@ class HttpDownloader(DownloaderBase):
self.downloading = False
if self.mtime:
if "_http_lastmodified" in kwdict:
kwdict["_mtime"] = kwdict["_http_lastmodified"]
kwdict["_mtime_http"] = kwdict["_http_lastmodified"]
else:
kwdict["_mtime"] = response.headers.get("Last-Modified")
kwdict["_mtime_http"] = response.headers.get("Last-Modified")
else:
kwdict["_mtime"] = None
kwdict["_mtime_http"] = None
return True

View File

@@ -348,6 +348,11 @@ class PathFormat():
pass
return 0
def set_mtime(self, path=None):
if (mtime := (self.kwdict.get("_mtime_meta") or
self.kwdict.get("_mtime_http"))):
util.set_mtime(self.realpath if path is None else path, mtime)
def finalize(self):
"""Move tempfile to its target location"""
if self.delete:
@@ -381,6 +386,4 @@ class PathFormat():
os.unlink(self.temppath)
break
mtime = self.kwdict.get("_mtime")
if mtime:
util.set_mtime(self.realpath, mtime)
self.set_mtime()

View File

@@ -139,9 +139,7 @@ class MetadataPP(PostProcessor):
archive.add(pathfmt.kwdict)
if self.mtime:
mtime = pathfmt.kwdict.get("_mtime")
if mtime:
util.set_mtime(path, mtime)
pathfmt.set_mtime(path)
def _run_stdout(self, pathfmt):
self.write(sys.stdout, pathfmt.kwdict)

View File

@@ -36,7 +36,7 @@ class MtimePP(PostProcessor):
if mtime is None:
return
pathfmt.kwdict["_mtime"] = (
pathfmt.kwdict["_mtime_meta"] = (
util.datetime_to_timestamp(mtime)
if isinstance(mtime, datetime) else
text.parse_int(mtime)

View File

@@ -236,9 +236,7 @@ class UgoiraPP(PostProcessor):
pathfmt.realpath = pathfmt.temppath
else:
if self.mtime:
mtime = pathfmt.kwdict.get("_mtime")
if mtime:
util.set_mtime(pathfmt.realpath, mtime)
pathfmt.set_mtime()
return True
def convert_to_archive(self, pathfmt, tempdir):