mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.86k stars 975 forks source link

[Instagram] Different dates (times) for filename and post #6081

Closed FuwaWata closed 2 months ago

FuwaWata commented 2 months ago

A similar issue was mentioned here: #4600 There's a difference of one or two seconds between the filename datetime gallery-dl outputted and the real datetime from the post. Based on what I observed, this only happens for SOME posts with more than one photo.

For posts with only one photo or one video: Example: https://www.instagram.com/p/C-xuZTmtNQR/ Using flag -K, gallery-dl outputted the following dates for directory and filenames.

Keywords for directory names:
-----------------------------
category
  instagram
count
  1
date
  2024-08-17 16:00:11

Keywords for filenames and --filter:
------------------------------------
category
  instagram
count
  1
date
  2024-08-17 16:00:11

The dates for both directory and filenames are the same in this case.

However, for some posts with more than one photo, the dates are different: Example: https://www.instagram.com/p/C-BJm6VScvU/?img_index=1

Keywords for directory names:
-----------------------------
category
  instagram
count
  10
date
  2024-07-29 19:15:06

Keywords for filenames and --filter:
------------------------------------
category
  instagram
count
  10
date
  2024-07-29 19:15:05

There's a one second difference in this case. Checking the source code for the post date, it shows the same datetime as the directory date gallery-dl outputted. Capture

Another example with two seconds difference: https://www.instagram.com/p/C9koxyoqgQX/?img_index=1

Keywords for directory names:
-----------------------------
category
  instagram
count
  4
date
  2024-07-18 17:29:30

Keywords for filenames and --filter:
------------------------------------
category
  instagram
count
  4
date
  2024-07-18 17:29:28

But there are also cases when gallery-dl outputted same datetimes for posts with more than one photo: Example: https://www.instagram.com/p/C-nUW1STK1c/?img_index=1

Keywords for directory names:
-----------------------------
category
  instagram
count
  4
date
  2024-08-13 15:00:13

Keywords for filenames and --filter:
------------------------------------
category
  instagram
count
  4
date
  2024-08-13 15:00:13

And so when I use --filename "{date:%Y-%m-%d %H.%M.%S}.{extension}", sometimes gallery-dl output the wrong datetime. Is there any way I can output the directory date instead of the filename date?

mikf commented 2 months ago

There's now a post_date metadata field, which is the "directory" / post datetime. Its value is the same for all files in a post. (https://github.com/mikf/gallery-dl/commit/a3642638109b22332072701fb157dcd6a4ef3a54)

FuwaWata commented 2 months ago

Thank you for the update. I can now use post_date when downloading instagram posts. However, a key error occurred when I'm downloading story.

It's indicating an error on line 216: data["date"] = data["post_date"]

It seems that post_date is only added in the regular image/video post code block but not the story or highlight block under the def _parse_post_rest(self, post) function.

I added "post_date": text.parse_timestamp(post.get("taken_at")), in the story code block and I can download successfully again. But I'm not sure if post.get("taken_at") is a valid key for instagram story.