mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-24 19:52:32 +01:00
add 'Headers' and 'Cookies' message
This commit is contained in:
parent
7b9fcea6bb
commit
cd4a699dd2
@ -19,7 +19,7 @@ class DownloadManager():
|
||||
def __init__(self, opts, conf):
|
||||
self.opts = opts
|
||||
self.conf = conf
|
||||
self.downloaders = {}
|
||||
self.modules = {}
|
||||
self.extractors = ExtractorFinder(conf)
|
||||
|
||||
def add(self, url):
|
||||
@ -28,10 +28,10 @@ class DownloadManager():
|
||||
|
||||
def get_downloader_module(self, scheme):
|
||||
"""Return a downloader module suitable for 'scheme'"""
|
||||
module = self.downloaders.get(scheme)
|
||||
module = self.modules.get(scheme)
|
||||
if module is None:
|
||||
module = importlib.import_module(".downloader."+scheme, __package__)
|
||||
self.downloaders[scheme] = module
|
||||
self.modules[scheme] = module
|
||||
return module
|
||||
|
||||
def get_base_directory(self):
|
||||
@ -58,6 +58,12 @@ class DownloadJob():
|
||||
if msg[0] == Message.Url:
|
||||
self.download(msg)
|
||||
|
||||
elif msg[0] == Message.Headers:
|
||||
self.get_downloader("http:").set_headers(msg[1])
|
||||
|
||||
elif msg[0] == Message.Cookies:
|
||||
self.get_downloader("http:").set_cookies(msg[1])
|
||||
|
||||
elif msg[0] == Message.Directory:
|
||||
self.set_directory(msg)
|
||||
|
||||
|
@ -40,3 +40,15 @@ class Downloader(BasicDownloader):
|
||||
for data in response.iter_content(16384):
|
||||
file.write(data)
|
||||
return tries
|
||||
|
||||
def set_headers(self, headers):
|
||||
self.set_dict(self.session.headers, headers)
|
||||
|
||||
def set_cookies(self, cookies):
|
||||
self.set_dict(self.session.cookies, cookies)
|
||||
|
||||
@staticmethod
|
||||
def set_dict(dest, src):
|
||||
dest.clear()
|
||||
dest.update(src)
|
||||
|
||||
|
@ -20,6 +20,8 @@ class Message():
|
||||
Version = 1
|
||||
Directory = 2
|
||||
Url = 3
|
||||
Headers = 4
|
||||
Cookies = 5
|
||||
|
||||
|
||||
class Extractor():
|
||||
|
Loading…
Reference in New Issue
Block a user