[fansly] fix posts with more than 5 files (#4401)
use an additional API request to '/v1/account/media' to fetch remaining media files not included in the initial API response
This commit is contained in:
@@ -45,6 +45,19 @@ class FanslyExtractor(Extractor):
|
||||
|
||||
def _extract_files(self, post):
|
||||
files = []
|
||||
|
||||
if "_extra" in post:
|
||||
extra = post.pop("_extra", ())
|
||||
media = {
|
||||
media["id"]: media
|
||||
for media in self.api.account_media(extra)
|
||||
}
|
||||
post["attachments"].extend(
|
||||
media[mid]
|
||||
for mid in extra
|
||||
if mid in media
|
||||
)
|
||||
|
||||
for attachment in post.pop("attachments"):
|
||||
try:
|
||||
self._extract_attachment(files, post, attachment)
|
||||
@@ -219,6 +232,11 @@ class FanslyAPI():
|
||||
params = {"ids": ",".join(map(str, account_ids))}
|
||||
return self._call(endpoint, params)
|
||||
|
||||
def account_media(self, media_ids):
|
||||
endpoint = "/v1/account/media"
|
||||
params = {"ids": ",".join(map(str, media_ids))}
|
||||
return self._call(endpoint, params)
|
||||
|
||||
def lists_account(self):
|
||||
endpoint = "/v1/lists/account"
|
||||
params = {"itemId": ""}
|
||||
@@ -276,6 +294,7 @@ class FanslyAPI():
|
||||
for post in posts:
|
||||
post["account"] = accounts[post.pop("accountId")]
|
||||
|
||||
extra = None
|
||||
attachments = []
|
||||
for attachment in post["attachments"]:
|
||||
cid = attachment["contentId"]
|
||||
@@ -284,16 +303,20 @@ class FanslyAPI():
|
||||
elif cid in bundles:
|
||||
bundle = bundles[cid]["bundleContent"]
|
||||
bundle.sort(key=lambda c: c["pos"])
|
||||
attachments.extend(
|
||||
media[m["accountMediaId"]]
|
||||
for m in bundle
|
||||
if m["accountMediaId"] in media
|
||||
)
|
||||
for c in bundle:
|
||||
mid = c["accountMediaId"]
|
||||
if mid in media:
|
||||
attachments.append(media[mid])
|
||||
else:
|
||||
if extra is None:
|
||||
post["_extra"] = extra = []
|
||||
extra.append(mid)
|
||||
else:
|
||||
self.extractor.log.warning(
|
||||
"%s: Unhandled 'contentId' %s",
|
||||
post["id"], cid)
|
||||
post["attachments"] = attachments
|
||||
|
||||
return posts
|
||||
|
||||
def _update_items(self, items):
|
||||
|
||||
@@ -10,16 +10,24 @@ from gallery_dl.extractor import fansly
|
||||
__tests__ = (
|
||||
{
|
||||
"#url" : "https://fansly.com/post/819035448046268416",
|
||||
"#comment" : "video",
|
||||
"#comment" : "1 video",
|
||||
"#class" : fansly.FanslyPostExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://fansly.com/post/815337432600821760",
|
||||
"#comment" : "images",
|
||||
"#comment" : "4 images",
|
||||
"#class" : fansly.FanslyPostExtractor,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://fansly.com/post/800553913467023361",
|
||||
"#comment" : "more than 5 files in an 'accountMediaBundles' entry",
|
||||
"#class" : fansly.FanslyPostExtractor,
|
||||
"#auth" : True,
|
||||
"#count" : 6,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://fansly.com/post/545313467469410305",
|
||||
"#comment" : "'This post does not exist or has been deleted.'",
|
||||
@@ -36,7 +44,7 @@ __tests__ = (
|
||||
"#auth" : False,
|
||||
"#log" : (
|
||||
"No 'token' provided",
|
||||
"543835794918354944/542560754868432896: Requested format not available",
|
||||
"543835794918354944/542560754868432896: No format available",
|
||||
),
|
||||
},
|
||||
|
||||
@@ -48,9 +56,9 @@ __tests__ = (
|
||||
"#auth" : False,
|
||||
"#log" : (
|
||||
"No 'token' provided",
|
||||
"451349524175138816/451349523013316609: Requested format not available",
|
||||
"451349524175138816/451349523000729600: Requested format not available",
|
||||
"451349524175138816/451349523025899520: Requested format not available",
|
||||
"451349524175138816/451349523013316609: No format available",
|
||||
"451349524175138816/451349523000729600: No format available",
|
||||
"451349524175138816/451349523025899520: No format available",
|
||||
),
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user