[patreon] add 'format-images' option (#6569)
This commit is contained in:
@@ -3442,10 +3442,38 @@ Type
|
|||||||
Default
|
Default
|
||||||
``["images", "image_large", "attachments", "postfile", "content"]``
|
``["images", "image_large", "attachments", "postfile", "content"]``
|
||||||
Description
|
Description
|
||||||
Determines the type and order of files to be downloaded.
|
Determines types and order of files to download.
|
||||||
|
|
||||||
Available types are
|
Available types:
|
||||||
``postfile``, ``images``, ``image_large``, ``attachments``, and ``content``.
|
|
||||||
|
* ``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
|
extractor.pillowfort.external
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ class PatreonExtractor(Extractor):
|
|||||||
self.session.headers["User-Agent"] = \
|
self.session.headers["User-Agent"] = \
|
||||||
"Patreon/7.6.28 (Android; Android 11; Scale/2.10)"
|
"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):
|
def items(self):
|
||||||
generators = self._build_file_generators(self.config("files"))
|
generators = self._build_file_generators(self.config("files"))
|
||||||
|
|
||||||
@@ -79,11 +84,20 @@ class PatreonExtractor(Extractor):
|
|||||||
|
|
||||||
def _images(self, post):
|
def _images(self, post):
|
||||||
for image in post.get("images") or ():
|
for image in post.get("images") or ():
|
||||||
url = image.get("download_url")
|
url = self._images_url(image)
|
||||||
if url:
|
if url:
|
||||||
name = image.get("file_name") or self._filename(url) or url
|
name = image.get("file_name") or self._filename(url) or url
|
||||||
yield "image", url, name
|
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):
|
def _image_large(self, post):
|
||||||
image = post.get("image")
|
image = post.get("image")
|
||||||
if image:
|
if image:
|
||||||
|
|||||||
@@ -102,10 +102,20 @@ __tests__ = (
|
|||||||
"#url" : "https://www.patreon.com/posts/free-post-12497641",
|
"#url" : "https://www.patreon.com/posts/free-post-12497641",
|
||||||
"#comment" : "tags (#1539)",
|
"#comment" : "tags (#1539)",
|
||||||
"#class" : patreon.PatreonPostExtractor,
|
"#class" : patreon.PatreonPostExtractor,
|
||||||
|
"#pattern" : r"https://c10.patreonusercontent.com/4/patreon-media/p/post/12497641/3d99f5f5b635428ca237fedf0f223f1a/eyJhIjoxLCJwIjoxfQ%3D%3D/1\.JPG\?.+",
|
||||||
|
|
||||||
"tags": ["AWMedia"],
|
"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",
|
"#url" : "https://www.patreon.com/posts/m3u8-94714289",
|
||||||
"#class" : patreon.PatreonPostExtractor,
|
"#class" : patreon.PatreonPostExtractor,
|
||||||
|
|||||||
Reference in New Issue
Block a user