Dates from filename Telegram chat export

Started by kot7k, March 07, 2022, 12:12:00 PM

Previous topic - Next topic

kot7k

Hi,

Just found out this great app and i'm trying to use it but i can't find the right way...

Im trying to insert a part of the filename as exif data. The filenames on a telegram chat export are like:
photo_1@27-02-2014_11-46-41.jpg
photo_89@25-11-2015_11-00-30.jpg
photo_114@21-02-2016_13-52-38.jpg

The date format is in day-month-year_hours_minutes_seconds.
The images doesn't have any tags (so i have to create them). How can i do all of this?
I'm doing this primarily cause amazon photos detects exif creation time and all this images from chat export doesn't have the tag but they have the date in the filename.

StarGeek

#1
If the date was formatted from Year to Second, then exiftool can usually copy the filename directly into the time stamps (see FAQ #5).  But the leading image count number and different order means that the data needs to be reordered.

Try
exiftool "-AllDates<${Filename;m/(\d\d)-(\d\d)-(\d{4})_(\d\d-\d\d-\d\d)/;$_=$3.$2.$1.$4}" /path/to/files/

This command uses RegEx (regular expressions) to match the date/time in the filename.  It then sets the filename to a new value consisting of the resorted date/time and copies that into the AllDates shortcut as per FAQ 5 above.

AllDates is a shortcut tag that fills the three most common EXIF timestamps, CreateDate, DateTimeOriginal, and ModifyDate.  For jpgs, this should properly sort in Amazon photos.

It might not work for PNG files, as PNG files have very little metadata support in most apps and websites.  I haven't tested PNGs on Amazon yet, so I don't know.

This command creates backup files.  Add -Overwrite_Original to suppress the creation of backup files.  Add -r to recurse into subdirectories.  If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.

Edit: Fixed regex
"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

kot7k

Hi,
I'm just answering to say thanks to you and to point out that the command had an small typo. (i'm using windows btw, maybe it works as it is on other systems)
If i used it as you told me:
exiftool "-AllDates<${Filename;m/(\d\d)-(/d/d)-(/d{4})_(\d\d-\d\d-\d\d)/;$_=$3.$2.$1.$4}" photo_1@27-02-2014_11-46-41.jpg

Gives the following output:
Warning: Unmatched ( in regex; marked by <-- HERE in m/(\d\d)-( <-- HERE / for 'Filename' - photo_1@27-02-2014_11-46-41.jpg
Warning: No writable tags set from photo_1@27-02-2014_11-46-41.jpg
    0 image files updated
    1 image files unchanged

I had to change the /d for \d and then:
exiftool "-AllDates<${filename;m/(\d\d)-(\d\d)-(\d{4})_(\d\d-\d\d-\d\d)/;$_=$3.$2.$1.$4}" photo_1@27-02-2014_11-46-41.jpg
    1 image files updated

Worked as i wanted! Thank you!



StarGeek

Quote from: kot7k on March 07, 2022, 02:24:17 PM
I had to change the /d for \d and then:

How the heck did I do that?  I know better than to make a mistake like that :D
"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