[postprocessor:metadata] implement 'mtime' option (#2307)
This commit is contained in:
parent
7aa2e2cd84
commit
7958995398
@ -3119,6 +3119,17 @@ Description
|
||||
Note: Only applies for ``"mode": "custom"``.
|
||||
|
||||
|
||||
metadata.mtime
|
||||
--------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
``false``
|
||||
Description
|
||||
Set modification times for generated metadata files
|
||||
according to the accompanying downloaded file.
|
||||
|
||||
|
||||
mtime.key
|
||||
---------
|
||||
Type
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2021 Mike Fährmann
|
||||
# Copyright 2021-2022 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
|
||||
@ -10,10 +10,8 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import shutil
|
||||
import functools
|
||||
from email.utils import mktime_tz, parsedate_tz
|
||||
from . import util, formatter, exception
|
||||
|
||||
WINDOWS = util.WINDOWS
|
||||
@ -327,10 +325,4 @@ class PathFormat():
|
||||
|
||||
mtime = self.kwdict.get("_mtime")
|
||||
if mtime:
|
||||
# Set file modification time
|
||||
try:
|
||||
if isinstance(mtime, str):
|
||||
mtime = mktime_tz(parsedate_tz(mtime))
|
||||
os.utime(self.realpath, (time.time(), mtime))
|
||||
except Exception:
|
||||
pass
|
||||
util.set_mtime(self.realpath, mtime)
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2019-2021 Mike Fährmann
|
||||
# Copyright 2019-2022 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
|
||||
@ -59,6 +59,8 @@ class MetadataPP(PostProcessor):
|
||||
events = events.split(",")
|
||||
job.register_hooks({event: self.run for event in events}, options)
|
||||
|
||||
self.mtime = options.get("mtime")
|
||||
|
||||
def run(self, pathfmt):
|
||||
directory = self._directory(pathfmt)
|
||||
path = directory + self._filename(pathfmt)
|
||||
@ -71,6 +73,11 @@ class MetadataPP(PostProcessor):
|
||||
with open(path, "w", encoding="utf-8") as fp:
|
||||
self.write(fp, pathfmt.kwdict)
|
||||
|
||||
if self.mtime:
|
||||
mtime = pathfmt.kwdict.get("_mtime")
|
||||
if mtime:
|
||||
util.set_mtime(path, mtime)
|
||||
|
||||
def _directory(self, pathfmt):
|
||||
return pathfmt.realdirectory
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2017-2021 Mike Fährmann
|
||||
# Copyright 2017-2022 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
|
||||
@ -12,6 +12,7 @@ import re
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import time
|
||||
import random
|
||||
import sqlite3
|
||||
import binascii
|
||||
@ -20,6 +21,7 @@ import functools
|
||||
import itertools
|
||||
import urllib.parse
|
||||
from http.cookiejar import Cookie
|
||||
from email.utils import mktime_tz, parsedate_tz
|
||||
from . import text, exception
|
||||
|
||||
|
||||
@ -272,6 +274,15 @@ def remove_directory(path):
|
||||
pass
|
||||
|
||||
|
||||
def set_mtime(path, mtime):
|
||||
try:
|
||||
if isinstance(mtime, str):
|
||||
mtime = mktime_tz(parsedate_tz(mtime))
|
||||
os.utime(path, (time.time(), mtime))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def load_cookiestxt(fp):
|
||||
"""Parse a Netscape cookies.txt file and return a list of its Cookies"""
|
||||
cookies = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user