From a4791f524330820e624e2ed3f6b759711fcc99e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 27 Oct 2024 13:59:46 +0100 Subject: [PATCH] [bluesky] add 'hashtag' extractor (#4438) https://github.com/mikf/gallery-dl/issues/4438#issuecomment-2439979958 --- docs/supportedsites.md | 2 +- gallery_dl/extractor/bluesky.py | 12 +++++++++++- test/results/bluesky.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/supportedsites.md b/docs/supportedsites.md index cec88be2..4f9e1a1f 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -136,7 +136,7 @@ Consider all listed sites to potentially be NSFW. Bluesky https://bsky.app/ - Avatars, Backgrounds, Feeds, Followed Users, Likes, Lists, Media Files, Posts, Replies, Search Results, User Profiles + Avatars, Backgrounds, Feeds, Followed Users, Hashtags, Likes, Lists, Media Files, Posts, Replies, Search Results, User Profiles Supported diff --git a/gallery_dl/extractor/bluesky.py b/gallery_dl/extractor/bluesky.py index a1a488ee..de5d0c6f 100644 --- a/gallery_dl/extractor/bluesky.py +++ b/gallery_dl/extractor/bluesky.py @@ -317,6 +317,15 @@ class BlueskySearchExtractor(BlueskyExtractor): return self.api.search_posts(self.user) +class BlueskyHashtagExtractor(BlueskyExtractor): + subcategory = "hashtag" + pattern = BASE_PATTERN + r"/hashtag/([^/?#]+)(?:/(top|latest))?" + example = "https://bsky.app/hashtag/NAME" + + def posts(self): + return self.api.search_posts("#"+self.user, self.groups[1]) + + class BlueskyAPI(): """Interface for the Bluesky API @@ -412,11 +421,12 @@ class BlueskyAPI(): params = {"handle": handle} return self._call(endpoint, params)["did"] - def search_posts(self, query): + def search_posts(self, query, sort=None): endpoint = "app.bsky.feed.searchPosts" params = { "q" : query, "limit": "100", + "sort" : sort, } return self._pagination(endpoint, params, "posts") diff --git a/test/results/bluesky.py b/test/results/bluesky.py index 3831aca7..50a0dcd9 100644 --- a/test/results/bluesky.py +++ b/test/results/bluesky.py @@ -110,6 +110,22 @@ __tests__ = ( "#archive" : False, }, +{ + "#url" : "https://bsky.app/hashtag/nature", + "#class" : bluesky.BlueskyHashtagExtractor, + "#range" : "1-40", + "#count" : 40, + "#archive" : False, +}, +{ + "#url" : "https://bsky.app/hashtag/top", + "#class" : bluesky.BlueskyHashtagExtractor, +}, +{ + "#url" : "https://bsky.app/hashtag/nature/latest", + "#class" : bluesky.BlueskyHashtagExtractor, +}, + { "#url" : "https://bsky.app/profile/bsky.app/post/3kh5rarr3gn2n", "#category": ("", "bluesky", "post"),