From 9c10be54fbc0cf2ead6bf43782ebe15e9f85711d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 8 Feb 2024 21:58:17 +0100 Subject: [PATCH] [bluesky] add 'following' extractor (#4438) --- gallery_dl/extractor/bluesky.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/bluesky.py b/gallery_dl/extractor/bluesky.py index 5676878ad04..30f7afa3c9e 100644 --- a/gallery_dl/extractor/bluesky.py +++ b/gallery_dl/extractor/bluesky.py @@ -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/([^/?#]+)" @@ -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 = { @@ -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: