diff --git a/docs/configuration.rst b/docs/configuration.rst index 304ddb4f93..a56fa42cd8 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -337,6 +337,23 @@ Description filename extension (``file.1.ext``, ``file.2.ext``, etc.) +extractor.*.skip-extension +----------------- +Type + * ``bool`` +Default + ``false`` +Description + If enabled, the file extension is ignored when checking to see if a file + already exists locally during the pre-download stage. + i.e. if downloading `./test/image_5.jpg` but `./test/image_5.png` or + `./test/image_5.avif` exists, it will behave as if `./test/image_5.jpg` exists + on disk + + * ``false``: Respects the file extension when checking if the file exists + * ``true``: Ignores the file extension when checking if the file exists and + any file with the same path & name will return True + extractor.*.sleep ----------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 9f126524e3..12d16ca1da 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -9,6 +9,7 @@ "cookies-update": true, "proxy": null, "skip": true, + "skip-extension": false, "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0", "retries": 4, diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 71927a55bb..d45d579820 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -12,6 +12,7 @@ import re import shutil import functools +import glob from . import util, formatter, exception WINDOWS = util.WINDOWS @@ -51,6 +52,7 @@ def __init__(self, extractor): raise exception.FilenameFormatError(exc) directory_fmt = config("directory") + self.skip_ext = config("skip-extension") or False try: if directory_fmt is None: directory_fmt = extractor.directory_fmt @@ -158,8 +160,17 @@ def open(self, mode="wb"): def exists(self): """Return True if the file exists on disk""" - if self.extension and os.path.exists(self.realpath): - return self.check_file() + # Search only by file name not including file extension + # This means checking if 'image_1.jpg' is on disk will + # be True if 'image_1.png' is found + if self.skip_ext: + split_real_path = self.realpath.split(".") + any_ext_path = ".".join(split_real_path[:-1]) + ".*" + if self.extension and glob.glob(any_ext_path): + return self.check_file() + else: + if self.extension and os.path.exists(self.realpath): + return self.check_file() return False @staticmethod