[fansly] add 'previews' option (#8686)

This commit is contained in:
Mike Fährmann
2025-12-25 20:25:47 +01:00
parent 01fe6870a3
commit c384cd06c2
4 changed files with 55 additions and 3 deletions

View File

@@ -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

View File

@@ -354,7 +354,8 @@
{
"token": "",
"formats": null
"formats" : null,
"previews": true
},
"flickr":
{

View File

@@ -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"]),

View File

@@ -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,