Skip to content

Commit

Permalink
[instagram] add 'post_date' metadata field (#6081)
Browse files Browse the repository at this point in the history
and restore 'date' metadata for GraphQL file results,
which got accidentally removed in a001c9c
  • Loading branch information
mikf committed Aug 24, 2024
1 parent 3bffe7a commit a364263
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gallery_dl/extractor/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ def _parse_post_rest(self, post):
data = {
"post_id" : post["pk"],
"post_shortcode": post["code"],
"post_url": "{}/p/{}/".format(self.root, post["code"]),
"post_date": text.parse_timestamp(post.get("taken_at")),
"likes": post.get("like_count", 0),
"pinned": post.get("timeline_pinned_user_ids", ()),
"date": text.parse_timestamp(post.get("taken_at")),
"liked": post.get("has_liked", False),
}

Expand Down Expand Up @@ -212,7 +213,7 @@ def _parse_post_rest(self, post):
data["owner_id"] = owner["pk"]
data["username"] = owner.get("username")
data["fullname"] = owner.get("full_name")
data["post_url"] = "{}/p/{}/".format(self.root, data["post_shortcode"])
data["date"] = data["post_date"]

data["_files"] = files = []
for num, item in enumerate(items, 1):
Expand Down Expand Up @@ -275,7 +276,6 @@ def _parse_post_graphql(self, post):
owner = post["owner"]
data = {
"typename" : typename,
"date" : text.parse_timestamp(post["taken_at_timestamp"]),
"likes" : post["edge_media_preview_like"]["count"],
"liked" : post.get("viewer_has_liked", False),
"pinned" : pinned,
Expand All @@ -285,11 +285,13 @@ def _parse_post_graphql(self, post):
"post_id" : post["id"],
"post_shortcode": post["shortcode"],
"post_url" : "{}/p/{}/".format(self.root, post["shortcode"]),
"post_date" : text.parse_timestamp(post["taken_at_timestamp"]),
"description": text.parse_unicode_escapes("\n".join(
edge["node"]["text"]
for edge in post["edge_media_to_caption"]["edges"]
)),
}
data["date"] = data["post_date"]

tags = self._find_tags(data["description"])
if tags:
Expand Down Expand Up @@ -319,6 +321,7 @@ def _parse_post_graphql(self, post):
media = {
"num": num,
"media_id" : node["id"],
"date" : data["date"],
"shortcode" : (node.get("shortcode") or
shortcode_from_id(node["id"])),
"display_url": node["display_url"],
Expand All @@ -334,6 +337,7 @@ def _parse_post_graphql(self, post):
dimensions = post["dimensions"]
media = {
"media_id" : post["id"],
"date" : data["date"],
"shortcode" : post["shortcode"],
"display_url": post["display_url"],
"video_url" : post.get("video_url"),
Expand Down

0 comments on commit a364263

Please sign in to comment.