Add Date Based on Sequence

Started by Rowan1002, May 10, 2020, 07:04:35 AM

Previous topic - Next topic

Rowan1002

Hi All - I have been struggling with this for a while.

I have a Mac, and have a folder which includes photos taken on my IPhone. I have used exiftool to rename in bulk all of the files so they are now in the correct order sequentially, which is great.

The issue I have is that, as some many of them were received on Whatsapp, when I upload them to "Photos" in my Mac, those Whatsapp pics end up in random dates.

Is there a way I can apply a command which will adjust the Create date of only those pictures without a create date and make it match the create date of either the photo before or after it in the sequence (as an estimated date)? The command would also need to not change the date if there is a create date already present, as I only want to redate the photos from Whatsapp...

Bit complex but hoping someone may have the solution? I think the main issue is that I want the command to use the previous or next photo's date as an estimate..not sure if possible.

Phil Harvey

Quote from: Rowan1002 on May 10, 2020, 07:04:35 AM
make it match the create date of either the photo before or after it in the sequence (as an estimated date)?

How do you determine the name of the photo before/after?  ie. what is the form of the file names?  If it is something like IMG_12345.jpg with a sequential number for each file, then this is possible, but will be a bit tricky.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rowan1002

Hi Phil - thanks for coming back to me.

I batch name changed them to the format: IMG_00001.JPEG, IMG_00002.MOV, and so on.

I guess I can always batch name change them again if a different naming format will work better?

Thanks, R

Rowan1002

Just to add, for example, if I drop the first 30 files into Mac "Photos" and the photos are all taken in Jan 2010 with one file received at some point in Jan 2010 via WhatsApp and that one happens to be IMG_000025 - in finder it will be in the right order but it will go into "Photos" on Mac at May 2019 (even though I don't see that date in it's EXIF properties. So ends up at the end of the sequence.

Hope that helps to explain.

Phil Harvey

Hi Rowan,

OK, you can do it like this, using 2 commands:

1. exiftool '-symlink<tmp/${filename;s/(\d+)/sprintf("%.5d",$1+1)/e}' DIR

2. exiftool -tagsfromfile tmp/%f.%e -createdate -if 'not $createdate' -fileorder filename DIR

The first command creates a set of symbolic links to the file with the previous number to be used when copying the CreateDate.

The trick is to use a symlink instead of a hard link and process the files in order of file name in the second command so that multiple consecutive missing CreateDates will be set properly.

After you are done with the command, you can delete the "tmp" directory containing the symlinks.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rowan1002

Hi Phil,

Thanks so much - that seems to have worked!!!

Just for reference, sometimes the image has been dated to the file which is a couple of files back in the sequence (not sure why?), but in most cases it has dated to the date of the previous image in the sequence!

Couple of q's -

1. Out of curiosity - which date in the Exif Data would that have adjusted? (eg. I assume it's not 'modified' or 'created'?). Reason for the question is - now the files are named in sequential order and the Whatsapp images now have a date in the Exif data (which is great!) I want to include the date in the file name (see point 2 below).

2. To do this I used this command: exiftool -d '%Y%m%d-%H%M%%-03.c.%%e' '-filename<CreateDate' DIR, which has worked, the only files that didn't rename are .PNG files, they seem to be screenshots images. For these files, the file names didn't change and when you import them into 'Photos' on Mac they are the only images that end up still in a random date (7 Jul 2019, which I assume could be the last modified date) - any idea why these wouldn't have been picked up by the symlink command?

Thanks, Rowan

Phil Harvey

Hi Rowan,

Quote from: Rowan1002 on May 11, 2020, 12:27:59 PM
sometimes the image has been dated to the file which is a couple of files back in the sequence

Interesting, but I don't see how this could ever happen because the tag is copied only from the softlink with the same name (which is linked only to the file with the previous number).

Quote1. Out of curiosity - which date in the Exif Data would that have adjusted?

This will write the EXIF CreateDate tag for JPG files.  You could also write DateTimeOriginal and/or ModifyDate if you want.  To write all three, use AllDates instead.

Quoteany idea why these wouldn't have been picked up by the symlink command?

The symlink probably worked, but nothing will be copied for these files if CreateDate doesn't exist.  Use this command to see what date/time tags are available:

exiftool -time:all -a -G1 FILE

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rowan1002

Hi Phil,

I have tried the command you mentioned to check the dates/time tags on a sample of the files and they do have dates (see below for some examples).

Does the below data indicate at all why these particular .PGN files did not rename to the dates even after I applied the symlink command that you suggested and the rename command I posted in my previous post?

Instead, as mentioned, when I drop these files into 'Photos' on Mac, they all go into 19 MAY 2017 which seems to be their created date (maybe this is the date that I downloaded them from Iphone to Mac). Not sure why this is, as after I use your symlink command they should have been re-dated to the previous file in the file sequence?

Last login: Mon May 11 19:28:58 on ttys000
Rowans-MBP:~ james$ exiftool -time:all -a -G1 /Users/james/Pictures/Exiftest\ -\ successful\ except\ for\ PGN/IMG_00176.PNG
[System]        File Modification Date/Time     : 2014:09:02 23:39:12+01:00
[System]        File Access Date/Time           : 2020:05:11 19:29:11+01:00
[System]        File Inode Change Date/Time     : 2020:05:11 17:10:42+01:00
Rowans-MBP:~ james$ exiftool -time:all -a -G1 /Users/james/Pictures/Exiftest\ -\ successful\ except\ for\ PGN/IMG_00236.PNG
[System]        File Modification Date/Time     : 2014:09:02 23:41:21+01:00
[System]        File Access Date/Time           : 2020:05:11 19:29:10+01:00
[System]        File Inode Change Date/Time     : 2020:05:11 17:10:42+01:00
Rowans-MBP:~ james$ exiftool -time:all -a -G1 /Users/james/Pictures/Exiftest\ -\ successful\ except\ for\ PGN/IMG_00254.PNG
[System]        File Modification Date/Time     : 2014:09:02 23:41:24+01:00
[System]        File Access Date/Time           : 2020:05:11 19:29:08+01:00
[System]        File Inode Change Date/Time     : 2020:05:11 17:10:42+01:00
Rowans-MBP:~ james$ exiftool -time:all -a -G1 /Users/james/Pictures/Exiftest\ -\ successful\ except\ for\ PGN/IMG_00273.PNG
[System]        File Modification Date/Time     : 2014:09:02 23:41:31+01:00
[System]        File Access Date/Time           : 2020:05:11 19:29:12+01:00
[System]        File Inode Change Date/Time     : 2020:05:11 17:10:42+01:00

Phil Harvey

The PNG files have do not have CreateDate tag, which is what you are copying to the FileName.  They have only FileModifyDate, FileAccessDate and FileInodeChangeDate (I should have asked you to add -s to the command so you could see the tag names, so this would be more clear).

Try changing CreateDate to FileModifyDate and adding -ext png to rename only the PNG files according to the FileModifyDate instead.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rowan1002

Hi Phil,

Great - the PNG files did rename using the command.

1. The FileModifyDate however doesn't really represent their date taken as well as the order they were in the original naming sequence of IMG_00025 etc. So is there a way we can use that sequence to date them rather than their FileModifyDate?

2. When dropping them into Photos on Mac they still all end up in 17 JUL 2019?

The file name format is now like so: 20140902-234143-003.PNG

Thanks, Rowan

Phil Harvey

Are the PNG images numbered in the same sequence as JPG images.  ie)

IMG_00001.jpg
IMG_00002.jpg
IMG_00003.png
IMG_00004.jpg

?

If so, my scheme fails because the symlinks won't work if the extensions are different.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rowan1002

Hi Phil,

Yes that is the exact format of my list, for completeness, the file list also includes some .MOV files which are probably video's taken on Iphone.

Got it re. your symlink not working with the extensions being different - is there another method I could use to give the png files the same date as the prior or post file in the sequence?

Thanks, R

Phil Harvey

OK.  This should work for files with different extensions (the symlink file is created without an extension):

1. exiftool '-symlink<tmp/${filename;s/(\d+)/sprintf("%.5d",$1+1)/e;s/\.\w+$//}' DIR

2. exiftool -tagsfromfile tmp/%f -createdate -if 'not $createdate' -fileorder filename DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rowan1002

Hi Phil,

Ok applied just the two commands on a smaller test folder & then dropped the files into Photos on Mac.

Doesn't seem to have worked for some reason?

See below, the first command had the below result:
1 directories scanned
    0 image files updated
  253 image files unchanged
    0 symbolic links created
  253 symbolic links could not be created

The second command had the below result:
  1 directories scanned
  167 files failed condition
    0 image files updated
   86 image files unchanged

Then dropped them into Photos on Mac to see the result. The order still doesn't match that of the file sequence, as I still I have a bulk of files which are in the 7JUL2019 date. It's a mixture of JPEG files and PNG files.

Maybe I need to change the commands?

Thanks, Rowan

Phil Harvey

The first command didn't create any symlinks.  It should have given some warnings to indicate why.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).