[instagram] add 'user-strategy' option (#8978 #9025)

This commit is contained in:
Mike Fährmann
2026-02-10 16:46:33 +01:00
parent a8376f2804
commit d491564f8a
3 changed files with 33 additions and 13 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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):