[downloader:http] add 'adjust-extensions' option

pull/378/head
Mike Fährmann 5 years ago
parent eb7da159e2
commit b7fb93e2b2
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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
----------------------
=========== =====

@ -155,6 +155,7 @@
"http":
{
"adjust-extensions": true,
"mtime": true,
"rate": null,
"retries": 4,

@ -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

@ -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)

Loading…
Cancel
Save