Skip to content

Commit

Permalink
[bluesky] add 'following' extractor (#4438)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Feb 8, 2024
1 parent 86ce35d commit 9c10be5
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions gallery_dl/extractor/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ def posts(self):
return self.api.get_list_feed(self.user, self.list)


class BlueskyFollowingExtractor(BlueskyExtractor):
subcategory = "following"
pattern = USER_PATTERN + r"/follows"
example = "https://bsky.app/profile/HANDLE/follows"

def items(self):
for user in self.api.get_follows(self.user):
url = "https://bsky.app/profile/" + user["did"]
yield Message.Queue, url, user


class BlueskyPostExtractor(BlueskyExtractor):
subcategory = "post"
pattern = USER_PATTERN + r"/post/([^/?#]+)"
Expand Down Expand Up @@ -206,6 +217,14 @@ def get_feed(self, actor, feed):
}
return self._pagination(endpoint, params)

def get_follows(self, actor):
endpoint = "app.bsky.graph.getFollows"
params = {
"actor": self._did_from_actor(actor),
"limit": "100",
}
return self._pagination(endpoint, params, "follows")

def get_list_feed(self, actor, list):
endpoint = "app.bsky.feed.getListFeed"
params = {
Expand Down Expand Up @@ -293,10 +312,10 @@ def _call(self, endpoint, params):
"API request failed (%s %s)",
response.status_code, response.reason)

def _pagination(self, endpoint, params):
def _pagination(self, endpoint, params, key="feed"):
while True:
data = self._call(endpoint, params)
yield from data["feed"]
yield from data[key]

cursor = data.get("cursor")
if not cursor:
Expand Down

0 comments on commit 9c10be5

Please sign in to comment.