diff --git a/docs/configuration.rst b/docs/configuration.rst index 1d8bd58e..00830db2 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1107,6 +1107,16 @@ Description Certificate validation during file downloads. =========== ===== +downloader.http.adjust-extensions +--------------------------------- +=========== ===== +Type ``bool`` +Default ``true`` +Description Check the file headers of ``jpg``, ``png``, and ``gif`` files + and adjust their filename extensions if they do not match. +=========== ===== + + downloader.ytdl.format ---------------------- =========== ===== diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index c75bfd27..2f7c58ea 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -155,6 +155,7 @@ "http": { + "adjust-extensions": true, "mtime": true, "rate": null, "retries": 4, diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 7a951916..bf8b3cbd 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -26,6 +26,7 @@ class HttpDownloader(DownloaderBase): def __init__(self, extractor, output): DownloaderBase.__init__(self, extractor, output) + self.adjust_extension = self.config("adjust-extensions", True) self.retries = self.config("retries", extractor._retries) self.timeout = self.config("timeout", extractor._timeout) self.verify = self.config("verify", extractor._verify) @@ -59,7 +60,6 @@ class HttpDownloader(DownloaderBase): def _download_impl(self, url, pathfmt): response = None - adj_ext = None tries = 0 msg = "" @@ -152,13 +152,14 @@ class HttpDownloader(DownloaderBase): continue # check filename extension - adj_ext = self.check_extension(file, pathfmt) + if self.adjust_extension: + adj_ext = self.check_extension(file, pathfmt) + if adj_ext: + pathfmt.set_extension(adj_ext) break self.downloading = False - if adj_ext: - pathfmt.set_extension(adj_ext) if self.mtime: pathfmt.keywords["_mtime"] = response.headers.get("Last-Modified") return True diff --git a/test/test_results.py b/test/test_results.py index dffc5e84..fe346c15 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -166,7 +166,6 @@ class ResultJob(job.DownloadJob): if content: self.fileobj = TestPathfmt(self.hash_content) - self.get_downloader("http").check_extension = lambda a, b: None self.format_directory = TestFormatter( "".join(self.extractor.directory_fmt)) @@ -278,6 +277,7 @@ def setup_test_config(): config.clear() config.set(("cache", "file"), ":memory:") config.set(("downloader", "part"), False) + config.set(("downloader", "adjust-extensions"), False) config.set(("extractor", "timeout"), 60) config.set(("extractor", "username"), name) config.set(("extractor", "password"), name)