improve extractor.get_downloader()

This commit is contained in:
Mike Fährmann
2018-09-05 18:17:16 +02:00
parent eb3185d6a3
commit 41249f3ead

View File

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