[instagram] add 'followers' extractor (#7374)
This commit is contained in:
@@ -466,7 +466,7 @@ Consider all listed sites to potentially be NSFW.
|
||||
<tr>
|
||||
<td>Instagram</td>
|
||||
<td>https://www.instagram.com/</td>
|
||||
<td>Avatars, Collections, Followed Users, Guides, Highlights, User Profile Information, Posts, Reels, Saved Posts, Stories, Tag Searches, Tagged Posts, User Profiles</td>
|
||||
<td>Avatars, Collections, Followers, Followed Users, Guides, Highlights, User Profile Information, Posts, Reels, Saved Posts, Stories, Tag Searches, Tagged Posts, User Profiles</td>
|
||||
<td><a href="https://github.com/mikf/gallery-dl#cookies">Cookies</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -606,6 +606,20 @@ class InstagramHighlightsExtractor(InstagramExtractor):
|
||||
return self.api.highlights_media(uid)
|
||||
|
||||
|
||||
class InstagramFollowersExtractor(InstagramExtractor):
|
||||
"""Extractor for an Instagram user's followers"""
|
||||
subcategory = "followers"
|
||||
pattern = USER_PATTERN + r"/followers"
|
||||
example = "https://www.instagram.com/USER/followers/"
|
||||
|
||||
def items(self):
|
||||
uid = self.api.user_id(self.item)
|
||||
for user in self.api.user_followers(uid):
|
||||
user["_extractor"] = InstagramUserExtractor
|
||||
url = "{}/{}".format(self.root, user["username"])
|
||||
yield Message.Queue, url, user
|
||||
|
||||
|
||||
class InstagramFollowingExtractor(InstagramExtractor):
|
||||
"""Extractor for an Instagram user's followed users"""
|
||||
subcategory = "following"
|
||||
@@ -816,6 +830,11 @@ class InstagramRestAPI():
|
||||
params = {"count": 30}
|
||||
return self._pagination(endpoint, params)
|
||||
|
||||
def user_followers(self, user_id):
|
||||
endpoint = "/v1/friendships/{}/followers/".format(user_id)
|
||||
params = {"count": 12}
|
||||
return self._pagination_following(endpoint, params)
|
||||
|
||||
def user_following(self, user_id):
|
||||
endpoint = "/v1/friendships/{}/following/".format(user_id)
|
||||
params = {"count": 12}
|
||||
@@ -908,9 +927,10 @@ class InstagramRestAPI():
|
||||
for item in data["items"]:
|
||||
yield from item["media_items"]
|
||||
|
||||
if "next_max_id" not in data:
|
||||
next_max_id = data.get("next_max_id")
|
||||
if not next_max_id:
|
||||
return extr._update_cursor(None)
|
||||
params["max_id"] = extr._update_cursor(data["next_max_id"])
|
||||
params["max_id"] = extr._update_cursor(next_max_id)
|
||||
|
||||
def _pagination_following(self, endpoint, params):
|
||||
extr = self.extractor
|
||||
@@ -921,10 +941,10 @@ class InstagramRestAPI():
|
||||
|
||||
yield from data["users"]
|
||||
|
||||
if len(data["users"]) < params["count"]:
|
||||
next_max_id = data.get("next_max_id")
|
||||
if not next_max_id:
|
||||
return extr._update_cursor(None)
|
||||
params["max_id"] = extr._update_cursor(
|
||||
params["max_id"] + params["count"])
|
||||
params["max_id"] = extr._update_cursor(next_max_id)
|
||||
|
||||
|
||||
class InstagramGraphqlAPI():
|
||||
|
||||
Reference in New Issue
Block a user