[bluesky] add 'avatar' and 'background' extractors (#4438)
This commit is contained in:
@@ -1185,6 +1185,31 @@ Description
|
|||||||
Download embedded videos hosted on https://www.blogger.com/
|
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
|
extractor.bluesky.metadata
|
||||||
--------------------------
|
--------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -108,6 +108,36 @@ class BlueskyExtractor(Extractor):
|
|||||||
def posts(self):
|
def posts(self):
|
||||||
return ()
|
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):
|
class BlueskyUserExtractor(BlueskyExtractor):
|
||||||
subcategory = "user"
|
subcategory = "user"
|
||||||
@@ -120,10 +150,12 @@ class BlueskyUserExtractor(BlueskyExtractor):
|
|||||||
def items(self):
|
def items(self):
|
||||||
base = "{}/profile/{}/".format(self.root, self.user)
|
base = "{}/profile/{}/".format(self.root, self.user)
|
||||||
return self._dispatch_extractors((
|
return self._dispatch_extractors((
|
||||||
(BlueskyPostsExtractor , base + "posts"),
|
(BlueskyAvatarExtractor , base + "avatar"),
|
||||||
(BlueskyRepliesExtractor, base + "replies"),
|
(BlueskyBackgroundExtractor, base + "banner"),
|
||||||
(BlueskyMediaExtractor , base + "media"),
|
(BlueskyPostsExtractor , base + "posts"),
|
||||||
(BlueskyLikesExtractor , base + "likes"),
|
(BlueskyRepliesExtractor , base + "replies"),
|
||||||
|
(BlueskyMediaExtractor , base + "media"),
|
||||||
|
(BlueskyLikesExtractor , base + "likes"),
|
||||||
), ("media",))
|
), ("media",))
|
||||||
|
|
||||||
|
|
||||||
@@ -213,6 +245,26 @@ class BlueskyPostExtractor(BlueskyExtractor):
|
|||||||
return self.api.get_post_thread(self.user, self.post_id)
|
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():
|
class BlueskyAPI():
|
||||||
"""Interface for the Bluesky API
|
"""Interface for the Bluesky API
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user