News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Grabbing date from filename

Started by singh132, September 27, 2019, 06:12:44 PM

Previous topic - Next topic

singh132

Hello,

I have a Mac desktop running High Sierra with exiftool ver. 11.65.  my problem seems to be a variation of many other newbies. I am trying to upload my jpg's and mp4's to Google Photos(GP).  Call me silly but I want it organized properly by date.  On my mac in the folders the "date Created" and the Date Modified" appear to be determined by the [System] FileModifyDate.  As far as I can determine GP uses the [Quicktime] CreateDate tag value for the date by which it organizes the photos time index. I have been able to get the job done with my jpg files using the following command : exiftool "-alldates<filename" "-filemodifydate<filename" DIR. 

However I am unable to change anything on the mp4 files. The files have the filename structure of 2011-03-30-87 (YYYY-MM-DD-file num), with the tags as follows:

server:~ raju$ exiftool -a -s -G1 -time:all /Users/raju/Desktop/Test/2011.03.30\ 87.mp4
[System]        FileModifyDate                  : 2014:02:25 21:32:23-08:00
[System]        FileAccessDate                  : 2019:09:27 14:20:34-07:00
[System]        FileInodeChangeDate             : 2019:09:27 06:25:13-07:00
[QuickTime]     CreateDate                      : 2014:02:09 04:51:53
[QuickTime]     ModifyDate                      : 2014:02:09 04:51:57
[Track1]        TrackCreateDate                 : 2014:02:09 04:51:53
[Track1]        TrackModifyDate                 : 2014:02:09 04:51:57
[Track1]        MediaCreateDate                 : 2014:02:09 04:51:53
[Track1]        MediaModifyDate                 : 2014:02:09 04:51:57
[Track2]        TrackCreateDate                 : 2014:02:09 04:51:53
[Track2]        TrackModifyDate                 : 2014:02:09 04:51:56
[Track2]        MediaCreateDate                 : 2014:02:09 04:51:53
[Track2]        MediaModifyDate                 : 2014:02:09 04:51:56
[Track3]        TrackCreateDate                 : 2014:02:09 04:51:53
[Track3]        TrackModifyDate                 : 2014:02:09 04:51:56
[Track3]        MediaCreateDate                 : 2014:02:09 04:51:53
[Track3]        MediaModifyDate                 : 2014:02:09 04:51:56

I have tried various command lines with the results as shown:

server:~ raju$ exiftool "-alldates<filename" /Users/raju/Desktop/Test/2011.03.30\ 87.mp4 
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in ExifIFD:DateTimeOriginal (PrintConvInv) - /Users/raju/Desktop/Test/2011.03.30 87.mp4
Warning: No writable tags set from /Users/raju/Desktop/Test/2011.03.30 87.mp4
    0 image files updated
    1 image files unchanged

server:~ raju$ exiftool "-alldates<$filename" /Users/raju/Desktop/Test/2011.03.30\ 87.mp4 
Warning: No writable tags set from /Users/raju/Desktop/Test/2011.03.30 87.mp4
    0 image files updated
    1 image files unchanged

server:~ raju$ exiftool "-filemodifydate<filename" /Users/raju/Desktop/Test/2011-03-30-87.mp4
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:FileModifyDate (PrintConvInv) - /Users/raju/Desktop/Test/2011-03-30-87.mp4
Warning: No writable tags set from /Users/raju/Desktop/Test/2011-03-30-87.mp4
    0 image files updated
    1 image files unchanged


server:~ raju$ exiftool "-system:filemodifydate<filename" /Users/raju/Desktop/Test/2011-03-30-87.mp4
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:FileModifyDate (PrintConvInv) - /Users/raju/Desktop/Test/2011-03-30-87.mp4
Warning: No writable tags set from /Users/raju/Desktop/Test/2011-03-30-87.mp4
    0 image files updated
    1 image files unchanged



I'm not sure how to proceed?!  Any help would be greatly appreciated.  ;D


StarGeek

See FAQ #5.

The "Invalid date/time" warning tells you what is wrong.  Your filename is "2011.03.30 87.mp4", it has a Year, Month, and Day, as well as another number.  But the warning tells you to "use YYYY:mm:dd HH:MM:SS".  You're missing the Hours, Minutes, and Seconds.  Now, as FAQ 5 says, exiftool is flexible about sticking to that format.  But it does need ALL parts of the Date/Time.  So what needs to happen is the trailing numbers need to be dropped (there's no such thing as hour 87) and a time needs to be added.  The most common approach to adding a time when the actual time isn't known is to use 00:00:00.

Try this
exiftool "-alldates<${filename;m/(\d{4}\.\d\d\.\d\d)/;$_=$1} 00:00:00" /Users/raju/Desktop/Test/2011.03.30\ 87.mp4
This command uses a RegEx match to grab the Year.Month.Day from the file name and then adds the 00 time after that.
* 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).

singh132

Thanks Stargeek for your reply. I tried as you suggested and got this below.

server:~ raju$ exiftool "-alldates<${filename;m/(\d{4}\.\d\d\.\d\d)/;$_=$1} 00:00:00" /Users/raju/Desktop/Test/2011.03.30.87.mp4
-bash: -alldates<${filename;m/(\d{4}\.\d\d\.\d\d)/;$_=$1} 00:00:00: bad substitution

I've looked at the advanced formatting part of the FAQ's but I don't quite get what you did.  The d{4} is the year.  The .\d\d\. is the 2 digit month and day. The m at the beginning of the expression as well as the "$" signs are unfamiliar to me. Any thoughts?

singh132

Also just for general info, if the file were in the following format 2011-03-30-87.mp4 - would the expression then become:
exiftool "-alldates<${filename;m/(\d{4}\-\d\d\-\d\d)/;$_=$1} 00:00:00" /Users/raju/Desktop/Test/2011-03-30-87.mp4


What if the file were in the following format 2012_03_10 12_40_11.MOV - could I just use the following expression:
exiftool "-alldates<filename"

greybeard

Quote from: singh132 on September 28, 2019, 03:21:09 AM
Thanks Stargeek for your reply. I tried as you suggested and got this below.

server:~ raju$ exiftool "-alldates<${filename;m/(\d{4}\.\d\d\.\d\d)/;$_=$1} 00:00:00" /Users/raju/Desktop/Test/2011.03.30.87.mp4
-bash: -alldates<${filename;m/(\d{4}\.\d\d\.\d\d)/;$_=$1} 00:00:00: bad substitution

I've looked at the advanced formatting part of the FAQ's but I don't quite get what you did.  The d{4} is the year.  The .\d\d\. is the 2 digit month and day. The m at the beginning of the expression as well as the "$" signs are unfamiliar to me. Any thoughts?

Looks like an operating system issue - try single quotes

exiftool '-alldates<${filename;/(\d{4}\D?\d{2}\D?\d{2})/;$_=$1} 00:00:00' 2011.03.30.87.mp4

Note also changed so that any delimiter (or none) will work (2011-03-87-87.mp4 or even 20110387.mp4)

In this case the m in the regular expression isn't needed (it ignores newline characters).

You might try Googling for a Perl regular expression tutorial for more information on the syntax

StarGeek

Quote from: singh132 on September 28, 2019, 03:21:09 AM
Thanks Stargeek for your reply. I tried as you suggested and got this below.
...
bad substitution

Sorry, I wasn't paying enough attention to realize you were on bash.  You only mentioned it in your first sentence :D.  But as greybeard said, change the double quotes to single quotes. 

The problem with using my version of that command, which works on Windows, is that the dollar sign within the double quotes is interpreted by bash to be a bash variable.

QuoteI've looked at the advanced formatting part of the FAQ's but I don't quite get what you did.  The d{4} is the year.  The .\d\d\. is the 2 digit month and day. The m at the beginning of the expression as well as the "$" signs are unfamiliar to me. Any thoughts?

The m/.../ structure is from Perl.  It is a Perl match operation.  As greybeard said, the m isn't necessary, but I like to include it for clarity.  I find it easier to parse out what's happening from a glance with it in.

The dollar sign is used to indicate tags when when doing tag copying or advanced formatting.  See the fifth paragraph under the -TagsFromFile option.

The last part, $_=$1, is Perl.  The parenthesis in the match operation indicated the part of the match that was going to be captured.  The $1 is the variable that holds the value that was captured.  The $_ is the Perl default variable, which in this case is the value of the tag.  So $_=$1 replaces the value of the tag with the match that was captured.

Quote from: singh132 on September 28, 2019, 03:28:31 AM
Also just for general info, if the file were in the following format 2011-03-30-87.mp4 - would the expression then become:
exiftool "-alldates<${filename;m/(\d{4}\-\d\d\-\d\d)/;$_=$1} 00:00:00" /Users/raju/Desktop/Test/2011-03-30-87.mp4

That would work, but the dash doesn't need a slash before it.  It could be written as m/(\d{4}-\d\d-\d\d)/.  The dot has special meaning in RegEx, so it needs to be escaped with a backslash before it "\."   But greybeard's solution is much better.

QuoteWhat if the file were in the following format 2012_03_10 12_40_11.MOV - could I just use the following expression:
exiftool "-alldates<filename"

Yes, see third paragraph under FAQ #5.
* 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).

singh132

Thanks so much everybody for giving invaluable advice.  It worked. Eureka!!!!!!