diff --git a/gallery_dl/extractor/patreon.py b/gallery_dl/extractor/patreon.py index d36f01f1..c9d71895 100644 --- a/gallery_dl/extractor/patreon.py +++ b/gallery_dl/extractor/patreon.py @@ -35,8 +35,7 @@ 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: + if format_images := self.config("format-images"): self._images_fmt = format_images self._images_url = self._images_url_fmt @@ -73,11 +72,9 @@ class PatreonExtractor(Extractor): self.log.debug("skipping %s (%s %s)", url, fhash, kind) def _postfile(self, post): - postfile = post.get("post_file") - if postfile: + if postfile := post.get("post_file"): url = postfile["url"] - name = postfile.get("name") - if not name: + if not (name := postfile.get("name")): if url.startswith("https://stream.mux.com/"): name = url else: @@ -86,11 +83,11 @@ class PatreonExtractor(Extractor): return () def _images(self, post): - for image in post.get("images") or (): - url = self._images_url(image) - if url: - name = image.get("file_name") or self._filename(url) or url - yield "image", url, name + if images := post.get("images"): + for image in images: + if url := self._images_url(image): + 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") @@ -102,32 +99,26 @@ class PatreonExtractor(Extractor): return image.get("download_url") def _image_large(self, post): - image = post.get("image") - if image: - url = image.get("large_url") - if url: + if image := post.get("image"): + if url := image.get("large_url"): name = image.get("file_name") or self._filename(url) or url return (("image_large", url, name),) return () def _attachments(self, post): for attachment in post.get("attachments") or (): - url = self.request_location(attachment["url"], fatal=False) - if url: + if url := self.request_location(attachment["url"], fatal=False): yield "attachment", url, attachment["name"] for attachment in post.get("attachments_media") or (): - url = attachment.get("download_url") - if url: + if url := attachment.get("download_url"): yield "attachment", url, attachment["file_name"] def _content(self, post): - content = post.get("content") - if content: + if content := post.get("content"): for img in text.extract_iter( content, '