diff options
Diffstat (limited to 'gallery_dl/postprocessor')
| -rw-r--r-- | gallery_dl/postprocessor/compare.py | 29 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/exec.py | 4 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/metadata.py | 8 |
3 files changed, 30 insertions, 11 deletions
diff --git a/gallery_dl/postprocessor/compare.py b/gallery_dl/postprocessor/compare.py index 1bca593..a08cdc4 100644 --- a/gallery_dl/postprocessor/compare.py +++ b/gallery_dl/postprocessor/compare.py @@ -9,6 +9,8 @@ """Compare versions of the same file and replace/enumerate them on mismatch""" from .common import PostProcessor +from .. import text, util, exception +import sys import os @@ -19,16 +21,33 @@ class ComparePP(PostProcessor): if options.get("shallow"): self._compare = self._compare_size - job.register_hooks({"file": ( - self.enumerate - if options.get("action") == "enumerate" else - self.compare - )}, options) + action = options.get("action") + if action == "enumerate": + job.register_hooks({"file": self.enumerate}, options) + else: + job.register_hooks({"file": self.compare}, options) + action, _, smax = action.partition(":") + self._skipmax = text.parse_int(smax) + self._skipexc = self._skipcnt = 0 + if action == "abort": + self._skipexc = exception.StopExtraction + elif action == "terminate": + self._skipexc = exception.TerminateExtraction + elif action == "exit": + self._skipexc = sys.exit def compare(self, pathfmt): try: if self._compare(pathfmt.realpath, pathfmt.temppath): + if self._skipexc: + self._skipcnt += 1 + if self._skipcnt >= self._skipmax: + util.remove_file(pathfmt.temppath) + print() + raise self._skipexc() pathfmt.delete = True + else: + self._skipcnt = 0 except OSError: pass diff --git a/gallery_dl/postprocessor/exec.py b/gallery_dl/postprocessor/exec.py index 8fed723..cc217c3 100644 --- a/gallery_dl/postprocessor/exec.py +++ b/gallery_dl/postprocessor/exec.py @@ -9,7 +9,7 @@ """Execute processes""" from .common import PostProcessor -from .. import util +from .. import util, formatter import subprocess @@ -33,7 +33,7 @@ class ExecPP(PostProcessor): self.args = args execute = self.exec_string else: - self.args = [util.Formatter(arg) for arg in args] + self.args = [formatter.parse(arg) for arg in args] execute = self.exec_list events = options.get("event") diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py index c721612..fe65c88 100644 --- a/gallery_dl/postprocessor/metadata.py +++ b/gallery_dl/postprocessor/metadata.py @@ -9,7 +9,7 @@ """Write metadata to external files""" from .common import PostProcessor -from .. import util +from .. import util, formatter import os @@ -24,7 +24,7 @@ class MetadataPP(PostProcessor): cfmt = options.get("content-format") or options.get("format") if isinstance(cfmt, list): cfmt = "\n".join(cfmt) + "\n" - self._content_fmt = util.Formatter(cfmt).format_map + self._content_fmt = formatter.parse(cfmt).format_map ext = "txt" elif mode == "tags": self.write = self._write_tags @@ -45,10 +45,10 @@ class MetadataPP(PostProcessor): extfmt = options.get("extension-format") if filename: self._filename = self._filename_custom - self._filename_fmt = util.Formatter(filename).format_map + self._filename_fmt = formatter.parse(filename).format_map elif extfmt: self._filename = self._filename_extfmt - self._extension_fmt = util.Formatter(extfmt).format_map + self._extension_fmt = formatter.parse(extfmt).format_map else: self.extension = options.get("extension", ext) |
