1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-26 12:42:29 +01:00

[instagram] add 'user' metadata field (#3107)

at the moment only for URLs that need to translate user name to ID
This commit is contained in:
Mike Fährmann 2023-02-06 14:43:35 +01:00
parent 3436c6b117
commit f2e91732ae
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -40,6 +40,7 @@ class InstagramExtractor(Extractor):
self._logged_in = True
self._find_tags = re.compile(r"#\w+").findall
self._cursor = None
self._user = None
def items(self):
self.login()
@ -60,6 +61,8 @@ class InstagramExtractor(Extractor):
post = self._parse_post_graphql(post)
else:
post = self._parse_post_rest(post)
if self._user:
post["user"] = self._user
post.update(data)
files = post.pop("_files")
@ -363,6 +366,22 @@ class InstagramExtractor(Extractor):
self._cursor = cursor
return cursor
def _assign_user(self, user):
self._user = user
for key, old in (
("count_media" , "edge_owner_to_timeline_media"),
("count_video" , "edge_felix_video_timeline"),
("count_saved" , "edge_saved_media"),
("count_mutual" , "edge_mutual_followed_by"),
("count_follow" , "edge_follow"),
("count_followed" , "edge_followed_by"),
("count_collection", "edge_media_collections")):
try:
user[key] = user.pop(old)["count"]
except Exception:
user[key] = 0
class InstagramUserExtractor(InstagramExtractor):
"""Extractor for an Instagram user profile"""
@ -796,6 +815,7 @@ class InstagramRestAPI():
name = user["username"]
s = "" if name.endswith("s") else "s"
raise exception.StopExtraction("%s'%s posts are private", name, s)
self.extractor._assign_user(user)
return user["id"]
def user_clips(self, user_id):