[patreon] add 'format-images' option (#6569)

This commit is contained in:
Mike Fährmann
2024-12-04 21:07:34 +01:00
parent 45ce0a2797
commit a526a3d00d
3 changed files with 56 additions and 4 deletions

View File

@@ -35,6 +35,11 @@ class PatreonExtractor(Extractor):
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 @@ class PatreonExtractor(Extractor):
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: