1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 20:22:36 +01:00

[bluesky] add 'avatar' and 'background' extractors (#4438)

This commit is contained in:
Mike Fährmann 2024-02-16 15:41:19 +01:00
parent 24c1317e0d
commit 91e5c4fdfe
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 81 additions and 4 deletions

View File

@ -1185,6 +1185,31 @@ Description
Download embedded videos hosted on https://www.blogger.com/
extractor.bluesky.include
-------------------------
Type
* ``string``
* ``list`` of ``strings``
Default
``"media"``
Example
* ``"avatar,background,posts"``
* ``["avatar", "background", "posts"]``
Description
A (comma-separated) list of subcategories to include
when processing a user profile.
Possible values are
``"avatar"``,
``"background"``,
``"posts"``,
``"replies"``,
``"media"``,
``"likes"``,
It is possible to use ``"all"`` instead of listing all values separately.
extractor.bluesky.metadata
--------------------------
Type

View File

@ -108,6 +108,36 @@ class BlueskyExtractor(Extractor):
def posts(self):
return ()
def _make_post(self, actor, kind):
did = self.api._did_from_actor(actor)
profile = self.api.get_profile(did)
if kind not in profile:
return ()
cid = profile[kind].rpartition("/")[2].partition("@")[0]
return ({
"post": {
"embed": {"images": [{
"alt": kind,
"image": {
"$type" : "blob",
"ref" : {"$link": cid},
"mimeType": "image/jpeg",
"size" : 0,
},
"aspectRatio": {
"width" : 1000,
"height": 1000,
},
}]},
"author" : profile,
"record" : (),
"createdAt": "",
"uri" : cid,
},
},)
class BlueskyUserExtractor(BlueskyExtractor):
subcategory = "user"
@ -120,8 +150,10 @@ class BlueskyUserExtractor(BlueskyExtractor):
def items(self):
base = "{}/profile/{}/".format(self.root, self.user)
return self._dispatch_extractors((
(BlueskyAvatarExtractor , base + "avatar"),
(BlueskyBackgroundExtractor, base + "banner"),
(BlueskyPostsExtractor , base + "posts"),
(BlueskyRepliesExtractor, base + "replies"),
(BlueskyRepliesExtractor , base + "replies"),
(BlueskyMediaExtractor , base + "media"),
(BlueskyLikesExtractor , base + "likes"),
), ("media",))
@ -213,6 +245,26 @@ class BlueskyPostExtractor(BlueskyExtractor):
return self.api.get_post_thread(self.user, self.post_id)
class BlueskyAvatarExtractor(BlueskyExtractor):
subcategory = "avatar"
filename_fmt = "avatar_{post_id}.{extension}"
pattern = USER_PATTERN + r"/avatar"
example = "https://bsky.app/profile/HANDLE/avatar"
def posts(self):
return self._make_post(self.user, "avatar")
class BlueskyBackgroundExtractor(BlueskyExtractor):
subcategory = "background"
filename_fmt = "background_{post_id}.{extension}"
pattern = USER_PATTERN + r"/ba(?:nner|ckground)"
example = "https://bsky.app/profile/HANDLE/banner"
def posts(self):
return self._make_post(self.user, "banner")
class BlueskyAPI():
"""Interface for the Bluesky API