From c0b9ad678d36b84069fdd9806e61eff6c37c7b1b Mon Sep 17 00:00:00 2001 From: Gio Date: Mon, 9 Dec 2019 16:02:15 -0600 Subject: [PATCH] Separate metadata from handle_url into handle_metadata, commenting --- gallery_dl/extractor/patreon.py | 1 + gallery_dl/job.py | 24 +++++++++++++++------ gallery_dl/postprocessor/metadata_bypost.py | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/gallery_dl/extractor/patreon.py b/gallery_dl/extractor/patreon.py index 60549983..fefef48c 100644 --- a/gallery_dl/extractor/patreon.py +++ b/gallery_dl/extractor/patreon.py @@ -69,6 +69,7 @@ class PatreonExtractor(Extractor): post["type"] = "content" yield Message.Url, url, text.nameext_from_url(url, post) + # Metadata for post using dummy url for formatting post.update({"metadata_only": True}) url = post.get("creator").get("image_url") yield Message.Metadata, url, text.nameext_from_url(url, post) diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 19878db1..972174a4 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -99,9 +99,8 @@ class Job(): elif msg[0] == Message.Metadata: _, url, kwds = msg - if self.pred_url(url, kwds): - self.update_kwdict(kwds) - self.handle_url(url, kwds) + self.update_kwdict(kwds) + self.handle_metadata(url, kwds) elif msg[0] == Message.Version: if msg[1] != 1: @@ -194,9 +193,6 @@ class DownloadJob(Job): for pp in postprocessors: pp.prepare(pathfmt) - if kwdict.get("metadata_only"): - return - if pathfmt.exists(archive): self.handle_skip() return @@ -238,6 +234,19 @@ class DownloadJob(Job): pp.run_after(pathfmt) self._skipcnt = 0 + def handle_metadata(self, url, kwdict, fallback=None): + """Download the resource specified in 'url'""" + postprocessors = self.postprocessors + pathfmt = self.pathfmt + + # prepare download + pathfmt.set_filename(kwdict) + + if postprocessors: + for pp in postprocessors: + pp.prepare(pathfmt) + return + def handle_urllist(self, urls, kwdict): """Download the resource specified in 'url'""" fallback = iter(urls) @@ -510,6 +519,9 @@ class DataJob(Job): def handle_url(self, url, kwdict): self.data.append((Message.Url, url, self.filter(kwdict))) + def handle_metadata(self, url, kwdict): + self.data.append((Message.Url, url, self.filter(kwdict))) + def handle_urllist(self, urls, kwdict): self.data.append((Message.Urllist, list(urls), self.filter(kwdict))) diff --git a/gallery_dl/postprocessor/metadata_bypost.py b/gallery_dl/postprocessor/metadata_bypost.py index 05781742..cc5dc165 100644 --- a/gallery_dl/postprocessor/metadata_bypost.py +++ b/gallery_dl/postprocessor/metadata_bypost.py @@ -17,6 +17,7 @@ class Metadata_bypostPP(MetadataPP): MetadataPP.__init__(self, pathfmt, options) def prepare(self, pathfmt): + # Only run this processor on metadata messages, not individual images. if pathfmt.kwdict.get("metadata_only"): MetadataPP.run(self, pathfmt)