diff --git a/CHANGELOG.md b/CHANGELOG.md index 87dd18f1..15524b6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## Unreleased + ## 1.19.0 - 2021-10-01 ### Additions - [aryion] add `tag` extractor ([#1849](https://github.com/mikf/gallery-dl/issues/1849)) diff --git a/docs/configuration.rst b/docs/configuration.rst index 66bf2a8f..cdcc6a06 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2688,22 +2688,32 @@ Type Default ``"replace"`` Description - The action to take when files do not compare as equal. + The action to take when files do **not** compare as equal. * ``"replace"``: Replace/Overwrite the old version with the new one - * ``"abort:N"``: Same as ``"replace"`` and stop the current extractor run - after ``N`` consecutive files compared as equal. + * ``"enumerate"``: Add an enumeration index to the filename of the new + version like `skip = "enumerate" `__ + - * ``"terminate:N"``: Same as ``"replace"`` - and stop the current extractor run, including parent extractors, +compare.equal +------------- +Type + ``string`` +Default + ``"null"`` +Description + The action to take when files do compare as equal. + + * ``"abort:N"``: Stop the current extractor run after ``N`` consecutive files compared as equal. - * ``"exit:N"``: Same as ``"replace"`` and exit the program + * ``"terminate:N"``: Stop the current extractor run, + including parent extractors, after ``N`` consecutive files compared as equal. - * ``"enumerate"``: Add an enumeration index to the filename of the new - version like `skip = "enumerate" `__ + * ``"exit:N"``: Exit the program + after ``N`` consecutive files compared as equal. compare.shallow diff --git a/gallery_dl/postprocessor/compare.py b/gallery_dl/postprocessor/compare.py index a08cdc48..b3b94f7a 100644 --- a/gallery_dl/postprocessor/compare.py +++ b/gallery_dl/postprocessor/compare.py @@ -20,36 +20,32 @@ class ComparePP(PostProcessor): PostProcessor.__init__(self, job) if options.get("shallow"): self._compare = self._compare_size + self._equal_exc = self._equal_cnt = 0 - 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): + equal = options.get("equal") + if equal: + equal, _, emax = equal.partition(":") + self._equal_max = text.parse_int(emax) + if equal == "abort": + self._equal_exc = exception.StopExtraction + elif equal == "terminate": + self._equal_exc = exception.TerminateExtraction + elif equal == "exit": + self._equal_exc = sys.exit + + job.register_hooks({"file": ( + self.enumerate + if options.get("action") == "enumerate" else + self.replace + )}, options) + + def replace(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 + return self._equal(pathfmt) except OSError: pass + self._equal_cnt = 0 def enumerate(self, pathfmt): num = 1 @@ -58,9 +54,10 @@ class ComparePP(PostProcessor): pathfmt.prefix = str(num) + "." pathfmt.set_extension(pathfmt.extension, False) num += 1 - pathfmt.delete = True + return self._equal(pathfmt) except OSError: pass + self._equal_cnt = 0 def _compare(self, f1, f2): return self._compare_size(f1, f2) and self._compare_content(f1, f2) @@ -81,5 +78,14 @@ class ComparePP(PostProcessor): if not buf1: return True + def _equal(self, pathfmt): + if self._equal_exc: + self._equal_cnt += 1 + if self._equal_cnt >= self._equal_max: + util.remove_file(pathfmt.temppath) + print() + raise self._equal_exc() + pathfmt.delete = True + __postprocessor__ = ComparePP diff --git a/gallery_dl/version.py b/gallery_dl/version.py index acc3b8dc..8f47a9db 100644 --- a/gallery_dl/version.py +++ b/gallery_dl/version.py @@ -6,4 +6,4 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -__version__ = "1.19.0" +__version__ = "1.19.1-dev"