[bluesky] add 'search' extractor (#4438)
Both https://bsky.app/search?q=QUERY and https://bsky.app/search/QUERY are recognized as search URLs, where QUERY gets forwarded unmodified as 'q' parameter for app.bsky.feed.searchPosts . User searches are not supported yet.
This commit is contained in:
@@ -124,7 +124,7 @@ Consider all listed sites to potentially be NSFW.
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Bluesky</td>
|
<td>Bluesky</td>
|
||||||
<td>https://bsky.app/</td>
|
<td>https://bsky.app/</td>
|
||||||
<td>Feeds, Followed Users, Likes, Lists, Media Files, Posts, Replies, User Profiles</td>
|
<td>Avatars, Backgrounds, Feeds, Followed Users, Likes, Lists, Media Files, Posts, Replies, Search Results, User Profiles</td>
|
||||||
<td>Supported</td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class BlueskyExtractor(Extractor):
|
|||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
for post in self.posts():
|
for post in self.posts():
|
||||||
post = post["post"]
|
if "post" in post:
|
||||||
|
post = post["post"]
|
||||||
post.update(post["record"])
|
post.update(post["record"])
|
||||||
del post["record"]
|
del post["record"]
|
||||||
|
|
||||||
@@ -265,6 +266,15 @@ class BlueskyBackgroundExtractor(BlueskyExtractor):
|
|||||||
return self._make_post(self.user, "banner")
|
return self._make_post(self.user, "banner")
|
||||||
|
|
||||||
|
|
||||||
|
class BlueskySearchExtractor(BlueskyExtractor):
|
||||||
|
subcategory = "search"
|
||||||
|
pattern = BASE_PATTERN + r"/search(?:/|\?q=)(.+)"
|
||||||
|
example = "https://bsky.app/search?q=QUERY"
|
||||||
|
|
||||||
|
def posts(self):
|
||||||
|
return self.api.search_posts(self.user)
|
||||||
|
|
||||||
|
|
||||||
class BlueskyAPI():
|
class BlueskyAPI():
|
||||||
"""Interface for the Bluesky API
|
"""Interface for the Bluesky API
|
||||||
|
|
||||||
@@ -360,6 +370,14 @@ class BlueskyAPI():
|
|||||||
params = {"handle": handle}
|
params = {"handle": handle}
|
||||||
return self._call(endpoint, params)["did"]
|
return self._call(endpoint, params)["did"]
|
||||||
|
|
||||||
|
def search_posts(self, query):
|
||||||
|
endpoint = "app.bsky.feed.searchPosts"
|
||||||
|
params = {
|
||||||
|
"q" : query,
|
||||||
|
"limit": "100",
|
||||||
|
}
|
||||||
|
return self._pagination(endpoint, params, "posts")
|
||||||
|
|
||||||
def _did_from_actor(self, actor):
|
def _did_from_actor(self, actor):
|
||||||
if actor.startswith("did:"):
|
if actor.startswith("did:"):
|
||||||
did = actor
|
did = actor
|
||||||
|
|||||||
Reference in New Issue
Block a user