Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instagram] Add tagged_users to keywords for stories (#2582) #2584

Merged
merged 5 commits into from
May 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions gallery_dl/extractor/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _parse_post_api(self, post):
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 @@ -331,19 +333,43 @@ def _shortcode_from_id(post_id):
"abcdefghijklmnopqrstuvwxyz"
"0123456789-_")

def _extract_tagged_users(self, src, dest):
if "edge_media_to_tagged_user" not in src:
return
edges = src["edge_media_to_tagged_user"]["edges"]
@staticmethod
def _extract_tagged_users(src, dest):
dest["tagged_users"] = tagged_users = []

edges = src.get("edge_media_to_tagged_user")
if edges:
dest["tagged_users"] = tagged_users = []
for edge in edges:
for edge in edges["edges"]:
user = edge["node"]["user"]
tagged_users.append({
"id" : user["id"],
"username" : user["username"],
"full_name": user["full_name"],
})
tagged_users.append({"id" : user["id"],
"username" : user["username"],
"full_name": user["full_name"]})

usertags = src.get("usertags")
if usertags:
for tag in usertags["in"]:
user = tag["user"]
tagged_users.append({"id" : user["pk"],
"username" : user["username"],
"full_name": user["full_name"]})

mentions = src.get("reel_mentions")
if mentions:
for mention in mentions:
user = mention["user"]
tagged_users.append({"id" : user.get("pk"),
"username" : user["username"],
"full_name": user["full_name"]})

stickers = src.get("story_bloks_stickers")
if stickers:
for sticker in stickers:
sticker = sticker["bloks_sticker"]
if sticker["bloks_sticker_type"] == "mention":
user = sticker["sticker_data"]["ig_mention"]
tagged_users.append({"id" : user["account_id"],
"username" : user["username"],
"full_name": user["full_name"]})

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