From cfc70a97ab960b2cd17f6e4ef3e76fb5b438ab0f Mon Sep 17 00:00:00 2001 From: Gio Date: Mon, 9 Dec 2019 00:56:27 -0600 Subject: [PATCH] Added an additional channel for downloading the metadata of an entire post or gallery. --- gallery_dl/extractor/message.py | 1 + gallery_dl/extractor/patreon.py | 4 ++++ gallery_dl/job.py | 10 ++++++++ gallery_dl/postprocessor/__init__.py | 1 + gallery_dl/postprocessor/metadata_bypost.py | 26 +++++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gallery_dl/postprocessor/metadata_bypost.py diff --git a/gallery_dl/extractor/message.py b/gallery_dl/extractor/message.py index 1831620a..088fdd67 100644 --- a/gallery_dl/extractor/message.py +++ b/gallery_dl/extractor/message.py @@ -52,3 +52,4 @@ class Message(): # Cookies = 5 Queue = 6 Urllist = 7 + Metadata = 8 diff --git a/gallery_dl/extractor/patreon.py b/gallery_dl/extractor/patreon.py index 9b13391f..60549983 100644 --- a/gallery_dl/extractor/patreon.py +++ b/gallery_dl/extractor/patreon.py @@ -69,6 +69,10 @@ class PatreonExtractor(Extractor): post["type"] = "content" yield Message.Url, url, text.nameext_from_url(url, post) + post.update({"metadata_only": True}) + url = post.get("creator").get("image_url") + yield Message.Metadata, url, text.nameext_from_url(url, post) + def posts(self): """Return all relevant post objects""" diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 7a1f1955..3241c7c4 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -97,6 +97,12 @@ class Job(): self.update_kwdict(kwds) self.handle_urllist(urls, kwds) + elif msg[0] == Message.Metadata: + _, url, kwds = msg + if self.pred_url(url, kwds): + self.update_kwdict(kwds) + self.handle_url(url, kwds) + elif msg[0] == Message.Version: if msg[1] != 1: raise "unsupported message-version ({}, {})".format( @@ -188,6 +194,10 @@ class DownloadJob(Job): for pp in postprocessors: pp.prepare(pathfmt) + if kwdict.get("metadata_only"): + self.handle_skip() + return + if pathfmt.exists(archive): self.handle_skip() return diff --git a/gallery_dl/postprocessor/__init__.py b/gallery_dl/postprocessor/__init__.py index e63d4427..dbd87709 100644 --- a/gallery_dl/postprocessor/__init__.py +++ b/gallery_dl/postprocessor/__init__.py @@ -18,6 +18,7 @@ modules = [ "mtime", "ugoira", "zip", + "metadata_bypost", ] log = logging.getLogger("postprocessor") diff --git a/gallery_dl/postprocessor/metadata_bypost.py b/gallery_dl/postprocessor/metadata_bypost.py new file mode 100644 index 00000000..35d4ef34 --- /dev/null +++ b/gallery_dl/postprocessor/metadata_bypost.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019 Mike Fährmann +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +"""Write metadata to JSON files""" + +from .metadata import __postprocessor__ as MetadataPP + + +class Metadata_BypostPP(MetadataPP): + + def __init__(self, pathfmt, options): + MetadataPP.__init__(self, pathfmt, options) + + def prepare(self, pathfmt): + if pathfmt.kwdict.get("metadata_only"): + MetadataPP.run(self, pathfmt) + + def run(self, pathfmt): + return + +__postprocessor__ = Metadata_BypostPP