From a526a3d00d2bc4a594e2eafbe0c8d15049de1bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 4 Dec 2024 21:07:34 +0100 Subject: [PATCH] [patreon] add 'format-images' option (#6569) --- docs/configuration.rst | 34 ++++++++++++++++++++++++++++++--- gallery_dl/extractor/patreon.py | 16 +++++++++++++++- test/results/patreon.py | 10 ++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 432bc6e9fb..f191d03c21 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3442,10 +3442,38 @@ Type Default ``["images", "image_large", "attachments", "postfile", "content"]`` Description - Determines the type and order of files to be downloaded. + Determines types and order of files to download. - Available types are - ``postfile``, ``images``, ``image_large``, ``attachments``, and ``content``. + Available types: + + * ``postfile`` + * ``images`` + * ``image_large`` + * ``attachments`` + * ``content`` + + +extractor.patreon.format-images +------------------------------- +Type + ``string`` +Default + ``"download_url"`` +Description + Selects the format of ``images`` `files `__. + + Possible formats: + + * ``original`` + * ``default`` + * ``default_small`` + * ``default_blurred`` + * ``default_blurred_small`` + * ``thumbnail`` + * ``thumbnail_large`` + * ``thumbnail_small`` + * ``url`` + * ``download_url`` extractor.pillowfort.external diff --git a/gallery_dl/extractor/patreon.py b/gallery_dl/extractor/patreon.py index 57ab383a8a..e4a59857c0 100644 --- a/gallery_dl/extractor/patreon.py +++ b/gallery_dl/extractor/patreon.py @@ -35,6 +35,11 @@ def _init(self): self.session.headers["User-Agent"] = \ "Patreon/7.6.28 (Android; Android 11; Scale/2.10)" + format_images = self.config("format-images") + if format_images: + self._images_fmt = format_images + self._images_url = self._images_url_fmt + def items(self): generators = self._build_file_generators(self.config("files")) @@ -79,11 +84,20 @@ def _postfile(self, post): def _images(self, post): for image in post.get("images") or (): - url = image.get("download_url") + url = self._images_url(image) if url: name = image.get("file_name") or self._filename(url) or url yield "image", url, name + def _images_url(self, image): + return image.get("download_url") + + def _images_url_fmt(self, image): + try: + return image["image_urls"][self._images_fmt] + except Exception: + return image.get("download_url") + def _image_large(self, post): image = post.get("image") if image: diff --git a/test/results/patreon.py b/test/results/patreon.py index f8cdaf10f9..075045acea 100644 --- a/test/results/patreon.py +++ b/test/results/patreon.py @@ -102,10 +102,20 @@ "#url" : "https://www.patreon.com/posts/free-post-12497641", "#comment" : "tags (#1539)", "#class" : patreon.PatreonPostExtractor, + "#pattern" : r"https://c10.patreonusercontent.com/4/patreon-media/p/post/12497641/3d99f5f5b635428ca237fedf0f223f1a/eyJhIjoxLCJwIjoxfQ%3D%3D/1\.JPG\?.+", "tags": ["AWMedia"], }, +{ + "#url" : "https://www.patreon.com/posts/free-post-12497641", + "#comment" : "custom image format (#6569)", + "#class" : patreon.PatreonPostExtractor, + "#options" : {"format-images": "thumbnail"}, + "#pattern" : r"https://c10.patreonusercontent.com/4/patreon-media/p/post/12497641/3d99f5f5b635428ca237fedf0f223f1a/eyJoIjozNjAsInciOjM2MH0%3D/1\.JPG\?.+", + "#sha1_content": "190e249295eeca1a8ffbcf1aece788b4f69bbb64", +}, + { "#url" : "https://www.patreon.com/posts/m3u8-94714289", "#class" : patreon.PatreonPostExtractor,