use UTC time to rename filename of JSON file

Started by husch, November 06, 2022, 05:11:37 AM

Previous topic - Next topic

husch

Hi,
I've a lot of photos from Google TakeOut. Some photos and MP4 are lacking a timestamp (CreateDate); for example those uploaded from WhatsApp. In the JSON sidecar I can find the tag PhotoTakenTimeTimestamp. With this tag I can create the ALLDates tag and rename the filename in YYYYMMDD_HHMMSS format in the JPG and MP4 files (thanks to examples of Stargeek).

However, I don't want to loose the connection with the JSON-files which also contain for example face recognition info. So, I should also rename the JSON-files. They also contain the correct tag PhotoTakenTimeTimestamp.

Example
IMG_4578.JPG    ---> renamed to 20221021_081000.JPG
IMG_4578.JPG.JSON ---> should also be renamed to 20221021_081000.JSON

I've tried commands such as
exiftool -api QuickTimeUTC -EXT JSON -d %Y%m%d_%H%M%%-c.%%e "-filename<PhotoTakenTimeTimestamp" .
but with no result.

The actual Google takeout formats are even a bit more complicated with MP4 files.
I've added a typical json-file.

Any suggestions or link to other solutions?

Thanks.


Phil Harvey

This is tricky for 2 reasons.

1. The -d option has no effect here because this isn't a standard date/time tag.

2. We may run into time zone problems if you named your videos using local time.

Ignoring 2 for now, this will get us started:

exiftool -ext json -d %s "-filename<${PhotoTakenTimeTimestamp;$_=$self->InverseDateTime($_);DateFmt('%Y%m%d_%H%M%%-c.%%e')}" .

The -d option is effective in the call to InverseDateTime, which returns a standard EXIF-format date/time string.  We then reformat it for your file name using the DateFmt helper function.

- 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 ($).

husch

Thanks very much. Works like a charm. Perhaps for future users of Google TakeOut, I 've added the other commands to rename the downloaded files (photo & video).

exiftool --ext json -r -tagsfromfile "%d/%F.json" -d %s "-Alldates<PhotoTakenTimeTimestamp" .
exiftool --ext json -d %Y%m%d_%H%M%S%%-c.%%e "-filename<CreateDate" -overwrite_original .
exiftool -ext json -d %s "-filename<${PhotoTakenTimeTimestamp;$_=$self->InverseDateTime($_);DateFmt('%Y%m%d_%H%M%S%%-c.%%e')}" -overwrite_original .

The first command moves the date from the Google TakeOut JSON-sidecar to the exif-dates; e.g. CreateDate. Only  for non-JSON files.
The second command renames those files with the CreateDate formatted as YYYYMMDD_HHMMSS.xxx. The overwrite_original option however leaves sometimes orphan-files.
The last command is taken from above and renames the JSON files also; so that the photo and JSON file have the same name (in case you want later to access other info e.g. face recognition data in the sidecar).

Phil Harvey

Quote from: husch on November 06, 2022, 11:59:32 AMThe overwrite_original option however leaves sometimes orphan-files.

What do you mean by this?

- 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 ($).

husch

It does leave some ..._original files after processing. I thought that the -overwrite_original option would delete them. I also tried the -overwrite_original_in_place option, but with the same result. Below I give you a screenshot with one JPG + JSON (typical result of a Google TakeOut of Whatsapp uploads); before and after the processing with the above commands. As you can see, the original jpg is preserved.


I've also included the original files, in case you need some testing.

Phil Harvey

Your first command didn't use -overwrite_original, so that's where they came from.  The second command won't delete "_original" files that already exist.

- 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 ($).

StarGeek

Quote from: Phil Harvey on November 07, 2022, 06:26:51 AMYour first command didn't use -overwrite_original

Specifically,
exiftool --ext json -r -tagsfromfile "%d/%F.json" -d %s "-Alldates<PhotoTakenTimeTimestamp" .

which should be
exiftool --ext json -r -overwrite_original -tagsfromfile "%d/%F.json" -d %s "-Alldates<PhotoTakenTimeTimestamp" .
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype