improve extractor.get_downloader()

This commit is contained in:
Mike Fährmann 2018-09-05 18:17:16 +02:00
parent eb3185d6a3
commit 41249f3ead
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -267,15 +267,16 @@ class DownloadJob(Job):
def get_downloader(self, url):
"""Return, and possibly construct, a downloader suitable for 'url'"""
pos = url.find(":")
scheme = url[:pos] if pos != -1 else "http"
scheme = url.partition(":")[0]
if scheme == "https":
scheme = "http"
instance = self.downloaders.get(scheme)
if instance is None:
klass = downloader.find(scheme)
instance = klass(self.extractor.session, self.out)
self.downloaders[scheme] = instance
try:
return self.downloaders[scheme]
except KeyError:
pass
klass = downloader.find(scheme)
instance = klass(self.extractor.session, self.out)
self.downloaders[scheme] = instance
return instance