add and implement Queue message
This commit is contained in:
parent
d96f4f8299
commit
3a93faa372
@ -13,3 +13,4 @@ class Message():
|
||||
Url = 3
|
||||
Headers = 4
|
||||
Cookies = 5
|
||||
Queue = 6
|
||||
|
@ -20,6 +20,7 @@ class DownloadJob():
|
||||
return
|
||||
self.directory = self.get_base_directory()
|
||||
self.downloaders = {}
|
||||
self.queue = None
|
||||
self.filename_fmt = config.get(
|
||||
("extractor", self.extractor.category, "filename"),
|
||||
default=self.extractor.filename_fmt
|
||||
@ -48,6 +49,9 @@ class DownloadJob():
|
||||
elif msg[0] == Message.Directory:
|
||||
self.set_directory(msg)
|
||||
|
||||
elif msg[0] == Message.Queue:
|
||||
self.enqueue(msg[1])
|
||||
|
||||
elif msg[0] == Message.Version:
|
||||
if msg[1] != 1:
|
||||
raise "unsupported message-version ({}, {})".format(
|
||||
@ -55,6 +59,10 @@ class DownloadJob():
|
||||
)
|
||||
# TODO: support for multiple message versions
|
||||
|
||||
if self.queue:
|
||||
for url in self.queue:
|
||||
DownloadJob(url).run()
|
||||
|
||||
def download(self, msg):
|
||||
"""Download the resource specified in 'msg'"""
|
||||
_, url, metadata = msg
|
||||
@ -91,6 +99,13 @@ class DownloadJob():
|
||||
self.downloaders[scheme] = instance
|
||||
return instance
|
||||
|
||||
def enqueue(self, url):
|
||||
"""Add url to work-queue"""
|
||||
try:
|
||||
self.queue.append(url)
|
||||
except AttributeError:
|
||||
self.queue = [url]
|
||||
|
||||
@staticmethod
|
||||
def get_base_directory():
|
||||
"""Return the base-destination-directory for downloads"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user