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