diff --git a/gallery_dl/extractor/message.py b/gallery_dl/extractor/message.py index 193cd86e..538ad030 100644 --- a/gallery_dl/extractor/message.py +++ b/gallery_dl/extractor/message.py @@ -13,3 +13,4 @@ class Message(): Url = 3 Headers = 4 Cookies = 5 + Queue = 6 diff --git a/gallery_dl/jobs.py b/gallery_dl/jobs.py index 072fe561..4d87b315 100644 --- a/gallery_dl/jobs.py +++ b/gallery_dl/jobs.py @@ -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"""