diff --git a/docs/configuration.rst b/docs/configuration.rst index 00830db2..03db41c9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -131,8 +131,11 @@ extractor.*.skip =========== ===== Type ``bool`` or ``string`` Default ``true`` -Description Controls the behavior when downloading files whose filename - already exists. +Description Controls the behavior when downloading files that have been + downloaded before, i.e. a file with the same filename already + exists or its ID is in a `download archive`__. + + __ `extractor.*.archive`_ * ``true``: Skip downloads * ``false``: Overwrite already existing files @@ -144,6 +147,9 @@ Description Controls the behavior when downloading files whose filename * ``"exit"``: Exit the program altogether * ``"exit:N"``: Skip downloads and exit the program after ``N`` consecutive skips + + * ``"enumerate"``: Append a numeric suffix to the end of the + original filename (``file.ext.1``, ``file.ext.2``, etc) =========== ===== diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 637561ae..be88c4ab 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -316,7 +316,9 @@ class DownloadJob(Job): skip = self.extractor.config("skip", True) if skip: self._skipexc = None - if isinstance(skip, str): + if skip == "enumerate": + self.pathfmt.check_file = self.pathfmt._enum_file + elif isinstance(skip, str): skip, _, smax = skip.partition(":") if skip == "abort": self._skipexc = exception.StopExtraction diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 02d998d1..33c0cb76 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -529,6 +529,7 @@ class PathFormat(): self.filename = "" self.directory = self.realdirectory = "" self.path = self.realpath = self.temppath = "" + self.suffix = "" self.basedirectory = expand_path( extractor.config("base-directory", (".", "gallery-dl"))) @@ -565,9 +566,25 @@ class PathFormat(): if archive and archive.check(self.keywords): return self.fix_extension() if self.has_extension and os.path.exists(self.realpath): - return True + return self.check_file() return False + @staticmethod + def check_file(): + return True + + def _enum_file(self): + num = 1 + while True: + suffix = "." + str(num) + rpath = self.realpath + suffix + if not os.path.exists(rpath): + self.path += suffix + self.realpath = rpath + self.suffix = suffix + return False + num += 1 + def set_directory(self, keywords): """Build directory path and create it if necessary""" try: @@ -596,7 +613,7 @@ class PathFormat(): def set_keywords(self, keywords): """Set filename keywords""" self.keywords = keywords - self.temppath = "" + self.temppath = self.suffix = "" self.has_extension = bool(keywords.get("extension")) if self.has_extension: self.build_path() @@ -623,7 +640,7 @@ class PathFormat(): except Exception as exc: raise exception.FormatError(exc, "filename") - filename = os.sep + self.filename + filename = os.sep + self.filename + self.suffix self.path = self.directory + filename self.realpath = self.realdirectory + filename if not self.temppath: