From c384cd06c237f3ca195fe9099c2b0520d22c28ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 25 Dec 2025 20:25:47 +0100 Subject: [PATCH] [fansly] add 'previews' option (#8686) --- docs/configuration.rst | 10 ++++++++++ docs/gallery-dl.conf | 3 ++- gallery_dl/extractor/fansly.py | 10 ++++++++-- test/results/fansly.py | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index c818f963..de6308ba 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3137,6 +3137,16 @@ Description List of file formats to consider during format selection. +extractor.fansly.previews +------------------------- +Type + ``bool`` +Default + ``true`` +Description + Download `previews` if no other format is available. + + extractor.fansly.token ---------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 02730704..d9fc08a2 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -354,7 +354,8 @@ { "token": "", - "formats": null + "formats" : null, + "previews": true }, "flickr": { diff --git a/gallery_dl/extractor/fansly.py b/gallery_dl/extractor/fansly.py index 8f892e1d..8848501d 100644 --- a/gallery_dl/extractor/fansly.py +++ b/gallery_dl/extractor/fansly.py @@ -25,6 +25,7 @@ class FanslyExtractor(Extractor): def _init(self): self.api = FanslyAPI(self) + self.previews = self.config("previews", True) if fmts := self.config("formats"): self.formats = set(fmts) @@ -88,8 +89,8 @@ class FanslyExtractor(Extractor): exc.__class__.__name__, exc) return files - def _extract_attachment(self, files, post, attachment): - media = attachment["media"] + def _extract_attachment(self, files, post, attachment, preview=False): + media = attachment["preview" if preview else "media"] variants = media.pop("variants") or [] if media.get("locations"): @@ -107,6 +108,10 @@ class FanslyExtractor(Extractor): try: variant = max(formats)[-1] except Exception: + if self.previews and "preview" in attachment and not preview: + self.log.info("%s/%s: Downloading Preview", + post["id"], attachment["id"]) + return self._extract_attachment(files, post, attachment, True) return self.log.warning("%s/%s: No format available", post["id"], attachment["id"]) @@ -120,6 +125,7 @@ class FanslyExtractor(Extractor): file = { **variant, + "preview": preview, "format": variant["type"], "date": self.parse_timestamp(media["createdAt"]), "date_updated": self.parse_timestamp(media["updatedAt"]), diff --git a/test/results/fansly.py b/test/results/fansly.py index 68775d27..572ab394 100644 --- a/test/results/fansly.py +++ b/test/results/fansly.py @@ -89,6 +89,7 @@ __tests__ = ( "mimetype" : "video/mp4", "originalHeight": 590, "originalWidth" : 786, + "preview" : False, "resolutionMode": 1, "status" : 1, "type" : "video", @@ -98,6 +99,40 @@ __tests__ = ( }, }, +{ + "#url" : "https://fansly.com/post/527804734266941440", + "#comment" : "preview image (#8686)", + "#class" : fansly.FanslyPostExtractor, + "#auth" : "token", + "#pattern" : r"https://cdn3.fansly.com/509388488890658816/527804380229935104.jpeg\?ngsw-bypass=true&Expires=\d+.+", + + "createdAt" : 1687332814, + "date" : "dt:2023-06-21 07:33:34", + "extension" : "jpeg", + "filename" : "527804380229935104", + "fypFlags" : 2, + "id" : "527804734266941440", + "file" : { + "accountId" : "509388488890658816", + "createdAt" : 1687332730, + "date" : "dt:2023-06-21 07:32:10", + "date_updated" : "dt:2023-06-21 07:32:13", + "flags" : 394, + "format" : 1, + "height" : 1464, + "id" : "527804380229935104", + "location" : "/509388488890658816/527804380229935104.jpeg", + "mimetype" : "image/jpeg", + "preview" : True, + "resolutionMode": 2, + "status" : 1, + "type" : "image", + "updatedAt" : 1687332733, + "variantHash" : {}, + "width" : 1349, + }, +}, + { "#url" : "https://fansly.com/Oliviaus/posts", "#class" : fansly.FanslyCreatorPostsExtractor,