From 36fa543715ff6830bff3b02409e91c315429f062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 26 Nov 2025 20:17:50 +0100 Subject: [PATCH] [twitter] add 'search-results' option (#8613) --- docs/configuration.rst | 14 ++++++++++++++ docs/gallery-dl.conf | 1 + gallery_dl/extractor/twitter.py | 23 ++++++++++++++++++----- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 7e8e34b7..a5fe78b3 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -6333,6 +6333,20 @@ Description to the Tweet ID value of the last retrieved Tweet. +extractor.twitter.search-results +-------------------------------- +Type + ``string`` +Default + ``"latest"`` +Description + Determines the target of search results. +Supported Values + * ``"top"`` + * ``"media"`` + * ``"latest"`` | ``"live"`` + + extractor.twitter.search-stop ----------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 84ab75e3..561f7963 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -880,6 +880,7 @@ "retweets" : false, "search-limit": 20, "search-pagination": "cursor", + "search-results" : "latest", "search-stop" : "auto", "size" : ["orig", "4096x4096", "large", "medium", "small"], "text-tweets" : false, diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index e6074b7e..b697557b 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -1450,23 +1450,36 @@ class TwitterAPI(): endpoint, variables, ("bookmark_timeline_v2", "timeline"), stop_tweets=128) - def search_timeline(self, query, product="Latest"): + def search_timeline(self, query, product=None): + cfg = self.extractor.config + + if product is None: + if product := cfg("search-results"): + product = { + "top" : "Top", + "live" : "Latest", + "user" : "People", + "media": "Media", + "list" : "Lists", + }.get(product.lower(), product).capitalize() + else: + product = "Latest" + endpoint = "/graphql/4fpceYZ6-YQCx_JSl_Cn_A/SearchTimeline" variables = { "rawQuery": query, - "count": self.extractor.config("search-limit", 20), + "count": cfg("search-limit", 20), "querySource": "typed_query", "product": product, "withGrokTranslatedBio": False, } - if self.extractor.config("search-pagination") in ( - "max_id", "maxid", "id"): + if cfg("search-pagination") in ("max_id", "maxid", "id"): update_variables = self._update_variables_search else: update_variables = None - stop_tweets = self.extractor.config("search-stop") + stop_tweets = cfg("search-stop") if stop_tweets is None or stop_tweets == "auto": stop_tweets = 3 if update_variables is None else 0