Skip to content

Commit

Permalink
(instagram) Add tagged_users to keywords for stories (mikf#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
Infinitay committed May 12, 2022
1 parent 9c8647a commit 1fb851e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions gallery_dl/extractor/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ def _parse_post_api(self, post):
else:
video = None
media = image

files.append({
media = {
"num" : num,
"date" : text.parse_timestamp(item.get("taken_at") or
media.get("taken_at")),
Expand All @@ -319,7 +319,9 @@ def _parse_post_api(self, post):
"video_url" : video["url"] if video else None,
"width" : media["width"],
"height" : media["height"],
})
}
self._extract_tagged_users(item, media)
files.append(media)

return data

Expand All @@ -332,18 +334,20 @@ def _shortcode_from_id(post_id):
"0123456789-_")

def _extract_tagged_users(self, src, dest):
if "edge_media_to_tagged_user" not in src:
if "edge_media_to_tagged_user" not in src and "reel_mentions" not in src:
return
edges = src["edge_media_to_tagged_user"]["edges"]
edges = src["edge_media_to_tagged_user"]["edges"] if "edge_media_to_tagged_user" in src else src["reel_mentions"]
if edges:
dest["tagged_users"] = tagged_users = []
for edge in edges:
user = edge["node"]["user"]
tagged_users.append({
"id" : user["id"],
user = edge["node"]["user"] if "edge_media_to_tagged_user" in src else edge["user"]
tagged_user = {
"username" : user["username"],
"full_name": user["full_name"],
})
}
if "edge_media_to_tagged_user" in src:
tagged_user["id"] = user["id"]
tagged_users.append(tagged_user)

def _extract_shared_data(self, url):
page = self.request(url).text
Expand Down

0 comments on commit 1fb851e

Please sign in to comment.