Setting created date by file name

Started by DrBarq, April 29, 2020, 04:54:27 PM

Previous topic - Next topic

DrBarq

First off, thank you to Phil, the teams, and the community.  Wow, what a support network!  Very thankful to have found this tool.

I found this blog post and it has been very helpful https://arslan.io/2018/04/18/tips-tricks-to-batch-edit-exif-metadata-of-photos/
I've been searching the forum and I believe I have a regex problem.  I really want to understand how to handle these errors and would appreciate any help. 

Example1: IMG_0403.2014-11-07_004721.JPG
Example2: 2014-12-27_192124000_FB048_iOS.png

Example1: fails I believe due to the IMG prefix on the filename.  What command would I use to set the created date to the date information following the IMG prefix? 
exiftool "-AllDates<filename" *

returns
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in ExifIFD:DateTimeOriginal (PrintConvInv) - IMG_0403.2014-11-07_004721.JPG


Example2:  fails I believe due to .png.  Do I need to specify commands based on file types?  JPEG with similar file name/structure was updated without an issue.


Thank you for any help/advice!!


StarGeek

Quote from: DrBarq on April 29, 2020, 04:54:27 PM
Example1: fails I believe due to the IMG prefix on the filename.

It isn't the image prefix, it's the numbers that are in front of the date.  Those can be removed with
exiftool "-AllDates<${Filename;s/^IMG_\d+//}" /path/to/files

See FAQ #5 for details on how flexible exiftool is when dealing with dates.

QuoteExample2:  fails I believe due to .png. 

It shouldn't be a problem unless you're using a very old version of exiftool.
C:\Programs\My_Stuff>exiftool "-alldates<filename" "Y:\!temp\bb\2014-12-27_192124000_FB048_iOS.png"
    1 image files updated

C:\Programs\My_Stuff>exiftool -g1 -a -s -alldates "Y:\!temp\bb\2014-12-27_192124000_FB048_iOS.png"
---- PNG ----
CreateDate                      : 2014:12:27 19:21:24
ModifyDate                      : 2014:12:27 19:21:24
---- IFD0 ----
ModifyDate                      : 2014:12:27 19:21:24
---- ExifIFD ----
DateTimeOriginal                : 2014:12:27 19:21:24
CreateDate                      : 2014:12:27 19:21:24
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

DrBarq

Thank you StarGeek!

That helped out a lot but I have a different issue now.  I was able to update/write the created date for the jpeg/png/mov

But I have an issue with the .mp4's; they look correct in finder/info with the correct created date but when in photos it references another date "January 5 181584"  this is applied to all mp4 and are now at the top of my Photos date. 


Any ideas? 

DrBarq

I ran exiftool -time:all -a -G0:1 -s test and saw some fields weren't consistent per the screenshot below. (prefixed with a . or file name extension)  I imagine this is my problem?  is there an additional command I could run?



StarGeek

Whoa, there's a lot of extra tags there.  You didn't happen to do something like this, did you?
exiftool '-time:all<$filename'

I'd suggest removing all the time tags and redoing it.  Replace the AllDates part with the correct command from above if needed.
exiftool -time:all= '-Alldates<Filename' /path/to/files/
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

DrBarq

Quote from: StarGeek on April 29, 2020, 07:45:41 PM
Whoa, there's a lot of extra tags there.  You didn't happen to do something like this, did you?
exiftool '-time:all<$filename'


Is that asking because you are curious?  or "I hope he didn't do that"?  Just trying to learn either way



I just ran exiftool -time:all= '-AllDates<${Filename;s/^IMG_\d+//}' test
*test in this case is the name of the folder I am running the command on

It did something different.  now it says it was created in August 8, 174729.  thoughts?

StarGeek

Ah, I finally remembered a previous problem with Photos.  See this thread.  The problem turned out to be the Quicktime:DateTimeOriginal tag (aka UserData:DateTimeOriginal.  So remove that with
exiftool -Quicktime:DateTimeOriginal= /path/to/files/

So for videos you're going to have to either set Quicktime:ModifyDate and Quicktime:CreateDate separately
exiftool  '-ModifyDate<${Filename;s/^IMG_\d+//}' '-ModifyDate<${CreateDate;s/^IMG_\d+//}' /path/to/files/

Or you could use the Alldates, if you have videos and images mixed in a directory, and then run the command above to remove the Quicktime:DateTimeOriginal tags.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

DrBarq

Thank you!! This is amazing.  You're the best. 

Phil Harvey

I wish I knew what was happening here, but I wasn't able to reproduce this myself with MacOS 10.13.6 with Photos version 3.0.

What version of MacOS and Photos are you running?

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

DrBarq

Hi Phil,

I am running macOS Catalina 10.15.4 and Photos version 5.0

The files came from Amazon Photos Mobile backup program and I had an issue with ~90 .mp4 files, no issues with the ~2k other .mov/.jpg/.png.   I just downloaded the original again to see if I could replicate and I could not.  It is very possible that I messed something up in the import.  Please let me know if you would like one of the files or have me try to replicate anything, happy to help in any way I can.   

Just curious, what photo management tool do you use?   

Phil Harvey

If you could send me one of the problem files (with the crazy date), I'll try it here.  (my email is philharvey66 at gmail.com)

I use ExifTool and icat to manage my photo library.

- 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: DrBarq on April 29, 2020, 10:30:46 PM
Thank you!! This is amazing.  You're the best.

It's all because Resultant took the time to figure it out.  I don't have access to a Mac so it wasn't something I could test.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

wywh

#12
Quote from: DrBarq on April 29, 2020, 08:03:48 PM
now it says it was created in August 8, 174729.  thoughts?

I noticed that if "[Keys] CreationDate", "[UserData] DateTimeOriginal" and obviously also "[Quicktime] DateTimeOriginal" lack a timezone like +02:00, then Catalina's Photos.app 5.0 generates weird scrambled datetimes with the year displayed something like "177294" etc. So it is important to make sure a timezone is set there. For example, some exiftool commands like "-AllDates<filename" create "[UserData] DateTimeOriginal" without timezone by default.

Martin Z

Quote from: StarGeek on April 29, 2020, 05:02:31 PMexiftool "-AllDates<${Filename;s/^IMG_\d+//}" /path/to/files

How "fuzzily" is EXIFtool able to match dates from int strings (in amongst other characters, seperators, etc)?, as in...
  • I haven't compiled a full list (as have 200,000+ images I need to process at some point) but...
  • ✅ I know that some files will have date information in their filenames,...
  • ❌ However, this will be in at least several different formats for sure, e.g. ...
    • "Screenshot_DDMMYYYY_HHMMSS.ext"
    • "Screen Recording_DDMMYYYY HHMMSS.ext"
    • "YYYY-MM-DD-HH-MM-SS.ext"

I assume I would need to separate out the files for each 'regex style' and process them in multiple batches, and create the correct regex that applies to each set of files specifically)... or is EXIFtool able to "fuzzy find" the date info for me as long as the file is in one of X / Y / Z formats, or contains a string of xxxxxx, etc?

StarGeek

Quote from: Martin Z on April 04, 2023, 03:21:16 PMHow "fuzzily" is EXIFtool able to match dates from int strings (in amongst other characters, seperators, etc)?

It just needs the 14 numbers (maybe a few less?) in order from year->seconds, without regards to any intervening characters.

So if the numbers are out of order then they need to be reordered, usually by regex. If there are leading non-date/time numbers, then those also need to be removed.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).