diff options
| author | 2023-10-03 18:31:58 -0400 | |
|---|---|---|
| committer | 2023-10-03 18:31:58 -0400 | |
| commit | b8758ecd073910ce3220b2e68399147b425c37b8 (patch) | |
| tree | d6aee20213508c8f425cbacb3d714367eca904c5 /gallery_dl/postprocessor | |
| parent | e2f67519f8c1750a71aab3dc56b8345fff21bac5 (diff) | |
New upstream version 1.26.0.upstream/1.26.0
Diffstat (limited to 'gallery_dl/postprocessor')
| -rw-r--r-- | gallery_dl/postprocessor/__init__.py | 3 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/common.py | 2 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/compare.py | 5 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/exec.py | 12 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/python.py | 46 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/ugoira.py | 28 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/zip.py | 2 |
7 files changed, 78 insertions, 20 deletions
diff --git a/gallery_dl/postprocessor/__init__.py b/gallery_dl/postprocessor/__init__.py index ee490e7..4690554 100644 --- a/gallery_dl/postprocessor/__init__.py +++ b/gallery_dl/postprocessor/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018-2021 Mike Fährmann +# Copyright 2018-2023 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 @@ -14,6 +14,7 @@ modules = [ "exec", "metadata", "mtime", + "python", "ugoira", "zip", ] diff --git a/gallery_dl/postprocessor/common.py b/gallery_dl/postprocessor/common.py index c28d060..10d9fba 100644 --- a/gallery_dl/postprocessor/common.py +++ b/gallery_dl/postprocessor/common.py @@ -45,5 +45,7 @@ class PostProcessor(): self.name, archive, exc.__class__.__name__, exc) else: self.log.debug("Using %s archive '%s'", self.name, archive) + return True else: self.archive = None + return False diff --git a/gallery_dl/postprocessor/compare.py b/gallery_dl/postprocessor/compare.py index 910e1d7..3bb63c8 100644 --- a/gallery_dl/postprocessor/compare.py +++ b/gallery_dl/postprocessor/compare.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020-2021 Mike Fährmann +# Copyright 2020-2023 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,7 +10,6 @@ from .common import PostProcessor from .. import text, util, exception -import sys import os @@ -31,7 +30,7 @@ class ComparePP(PostProcessor): elif equal == "terminate": self._equal_exc = exception.TerminateExtraction elif equal == "exit": - self._equal_exc = sys.exit + self._equal_exc = SystemExit job.register_hooks({"file": ( self.enumerate diff --git a/gallery_dl/postprocessor/exec.py b/gallery_dl/postprocessor/exec.py index 39188f1..afa828c 100644 --- a/gallery_dl/postprocessor/exec.py +++ b/gallery_dl/postprocessor/exec.py @@ -46,10 +46,7 @@ class ExecPP(PostProcessor): self._init_archive(job, options) - def exec_list(self, pathfmt, status=None): - if status: - return - + def exec_list(self, pathfmt): archive = self.archive kwdict = pathfmt.kwdict @@ -67,15 +64,12 @@ class ExecPP(PostProcessor): if archive: archive.add(kwdict) - def exec_string(self, pathfmt, status=None): - if status: - return - + def exec_string(self, pathfmt): archive = self.archive if archive and archive.check(pathfmt.kwdict): return - if status is None and pathfmt.realpath: + if pathfmt.realpath: args = self.args.replace("{}", quote(pathfmt.realpath)) else: args = self.args.replace("{}", quote(pathfmt.realdirectory)) diff --git a/gallery_dl/postprocessor/python.py b/gallery_dl/postprocessor/python.py new file mode 100644 index 0000000..db71da2 --- /dev/null +++ b/gallery_dl/postprocessor/python.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Copyright 2023 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 +# published by the Free Software Foundation. + +"""Run Python functions""" + +from .common import PostProcessor +from .. import util + + +class PythonPP(PostProcessor): + + def __init__(self, job, options): + PostProcessor.__init__(self, job) + + spec = options["function"] + module_name, _, function_name = spec.rpartition(":") + module = util.import_file(module_name) + self.function = getattr(module, function_name) + + if self._init_archive(job, options): + self.run = self.run_archive + + events = options.get("event") + if events is None: + events = ("file",) + elif isinstance(events, str): + events = events.split(",") + job.register_hooks({event: self.run for event in events}, options) + + def run(self, pathfmt): + self.function(pathfmt.kwdict) + + def run_archive(self, pathfmt): + kwdict = pathfmt.kwdict + if self.archive.check(kwdict): + return + self.function(kwdict) + self.archive.add(kwdict) + + +__postprocessor__ = PythonPP diff --git a/gallery_dl/postprocessor/ugoira.py b/gallery_dl/postprocessor/ugoira.py index 9d2cb34..b713c6f 100644 --- a/gallery_dl/postprocessor/ugoira.py +++ b/gallery_dl/postprocessor/ugoira.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018-2022 Mike Fährmann +# Copyright 2018-2023 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 @@ -32,10 +32,11 @@ class UgoiraPP(PostProcessor): self.extension = options.get("extension") or "webm" self.args = options.get("ffmpeg-args") or () self.twopass = options.get("ffmpeg-twopass", False) - self.output = options.get("ffmpeg-output", True) + self.output = options.get("ffmpeg-output", "error") self.delete = not options.get("keep-files", False) self.repeat = options.get("repeat-last-frame", True) self.mtime = options.get("mtime", True) + self.uniform = False ffmpeg = options.get("ffmpeg-location") self.ffmpeg = util.expand_path(ffmpeg) if ffmpeg else "ffmpeg" @@ -63,7 +64,9 @@ class UgoiraPP(PostProcessor): self.log.debug("using %s demuxer", demuxer) rate = options.get("framerate", "auto") - if rate != "auto": + if rate == "uniform": + self.uniform = True + elif rate != "auto": self.calculate_framerate = lambda _: (None, rate) if options.get("libx264-prevent-odd", True): @@ -81,6 +84,12 @@ class UgoiraPP(PostProcessor): else: self.prevent_odd = False + self.args_pp = args = [] + if isinstance(self.output, str): + args += ("-hide_banner", "-loglevel", self.output) + if self.prevent_odd: + args += ("-vf", "crop=iw-mod(iw\\,2):ih-mod(ih\\,2)") + job.register_hooks( {"prepare": self.prepare, "file": self.convert}, options) @@ -120,6 +129,8 @@ class UgoiraPP(PostProcessor): pathfmt.build_path() args = self._process(pathfmt, tempdir) + if self.args_pp: + args += self.args_pp if self.args: args += self.args @@ -274,10 +285,15 @@ class UgoiraPP(PostProcessor): return timecodes def calculate_framerate(self, frames): - uniform = self._delay_is_uniform(frames) - if uniform: + if self._delay_is_uniform(frames): return ("1000/{}".format(frames[0]["delay"]), None) - return (None, "1000/{}".format(self._delay_gcd(frames))) + + if not self.uniform: + gcd = self._delay_gcd(frames) + if gcd >= 10: + return (None, "1000/{}".format(gcd)) + + return (None, None) @staticmethod def _delay_gcd(frames): diff --git a/gallery_dl/postprocessor/zip.py b/gallery_dl/postprocessor/zip.py index 4f376fe..ce36f2a 100644 --- a/gallery_dl/postprocessor/zip.py +++ b/gallery_dl/postprocessor/zip.py @@ -88,7 +88,7 @@ class ZipPP(PostProcessor): if self.delete: util.remove_file(path) - def finalize(self, pathfmt, status): + def finalize(self, pathfmt): if self.zfile: self.zfile.close() |
