From d491564f8a053e95851a42de998d1c2b6baa8c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 10 Feb 2026 16:46:33 +0100 Subject: [PATCH] [instagram] add 'user-strategy' option (#8978 #9025) --- docs/configuration.rst | 16 ++++++++++++++++ docs/gallery-dl.conf | 3 ++- gallery_dl/extractor/instagram.py | 27 +++++++++++++++------------ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 37d1d861..d4b4b703 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -3881,6 +3881,22 @@ Description Cache user data in memory +extractor.instagram.user-strategy +--------------------------------- +Type + ``string`` +Default + ``"topsearch"`` +Description + Selects how to retrieve user profile data. + + ``"topsearch"`` | ``"search"`` + Use `topsearch` results + ``"web_profile_info"`` | ``"info"`` + | Use `web_profile_info` results + | (high liklyhood of ``429 Too Many Requests`` errors) + + extractor.instagram.videos -------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 9ef119fb..cddb1d4d 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -474,7 +474,8 @@ "order-files": "asc", "order-posts": "asc", "previews" : false, - "user-cache" : "disk", + "user-cache" : "disk", + "user-strategy": "topsearch", "videos" : true, "warn-images": true, "warn-videos": true, diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index 98760835..fa0b59b6 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -811,6 +811,13 @@ class InstagramRestAPI(): self.user_by_name = _cache(36500*86400, 0)(self.user_by_name) self.user_by_search = _cache(36500*86400, 0)(self.user_by_search) + strategy = self.extractor.config("user-strategy") + if strategy is not None and strategy in { + "web_profile_info", "profile_info", "info"}: + self._topsearch = False + else: + self._topsearch = True + def guide(self, guide_id): endpoint = "/v1/guides/web_info/" params = {"guide_id": guide_id} @@ -899,18 +906,14 @@ class InstagramRestAPI(): return user def user_by_screen_name(self, screen_name): - if user := self.user_by_search(screen_name): - return user - - self.user_by_search.invalidate(screen_name) - self.extractor.log.warning( - "Failed to find profile '%s' via search. " - "Trying 'web_profile_info' fallback", screen_name) - - if user := self.user_by_name(screen_name): - return user - - self.user_by_name.invalidate(screen_name) + if self._topsearch: + if user := self.user_by_search(screen_name): + return user + self.user_by_search.invalidate(screen_name) + else: + if user := self.user_by_name(screen_name): + return user + self.user_by_name.invalidate(screen_name) raise exception.NotFoundError("user") def user_id(self, screen_name, check_private=True):