Skip to content

Commit

Permalink
[bluesky] add 'search' extractor (#4438)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikf committed Feb 16, 2024
1 parent 91e5c4f commit ee7c054
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>Bluesky</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>
</tr>
<tr>
Expand Down
20 changes: 19 additions & 1 deletion gallery_dl/extractor/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def _init(self):

def items(self):
for post in self.posts():
post = post["post"]
if "post" in post:
post = post["post"]
post.update(post["record"])
del post["record"]

Expand Down Expand Up @@ -265,6 +266,15 @@ def posts(self):
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():
"""Interface for the Bluesky API
Expand Down Expand Up @@ -360,6 +370,14 @@ def resolve_handle(self, handle):
params = {"handle": handle}
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):
if actor.startswith("did:"):
did = actor
Expand Down

0 comments on commit ee7c054

Please sign in to comment.