Skip to content

Commit

Permalink
[patreon] add 'format-images' option (#6569)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Dec 4, 2024
1 parent 45ce0a2 commit a526a3d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
34 changes: 31 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <extractor.patreon.files_>`__.

Possible formats:

* ``original``
* ``default``
* ``default_small``
* ``default_blurred``
* ``default_blurred_small``
* ``thumbnail``
* ``thumbnail_large``
* ``thumbnail_small``
* ``url``
* ``download_url``


extractor.pillowfort.external
Expand Down
16 changes: 15 additions & 1 deletion gallery_dl/extractor/patreon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions test/results/patreon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a526a3d

Please sign in to comment.