Hi everyone,
I catalog all my photo/video files inside a folder named by date taken ([YYYY-MM-DD-description]).
I'm updating all my photos/videos doing these changes:
- Rename my all files to this format: YearMonthDay-HourMinuteSecond-Miliseconds-OriginalName
- Fix all -DateTimeOriginal -CreateDate -ModifyDate tags
- Add gps tags if they are empty
I've created a bash script to help including a function to do some validations.
For example I check if the DateTimeOriginal is different from the date of the folder (Directory)
Example:
exiftool -m -a -r -if '$Directory=~/.*\[(\d{4})\-(\d{2})\-(\d{2})\].*/ and ${Directory;s/.*\[(\d{4})\-(\d{2})\-(\d{2})\].*/${1}${2}${3}/} ne ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*\[(\d{4})\-(\d{2})\-(\d{2})\].*/${1}${2}${3}/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p '-------------------------------------------------------------' DIR
My problem is, sometimes when we take photos at night we get past midnight the days are different even though they are in the same folder as I intend to do.
What I intend to do now is check if the DateTimeOriginal is different from the date of the folder (Directory), and that difference is greater than 5 days for example.
Is there any way to do this?
Thanks in advance.
Answering this will require some work. I'll get back when I have time to do this.
- Phil
Ok Phil.
I'll look forward to your response. :)
OK. Something very similar was explained here (https://exiftool.org/forum/index.php/topic,4371.msg20798.html#msg20798).
The only difference is that you need to reformat the date/time from the directory name:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
TimeDiff => {
Require => {
0 => 'Directory',
1 => 'DateTimeOriginal',
},
ValueConv => q{
return undef unless $val[0] =~ /(\d{4})-(\d{2})-(\d{2})/;
my $secs = Image::ExifTool::GetUnixTime($val[1]) - Image::ExifTool::GetUnixTime("$1:$2:$3 00:00:00");
return $secs / (24 * 60 * 60);
},
PrintConv => 'Image::ExifTool::ConvertTimeSpan($val)',
},
},
);
1; #end
Also I have converted the time difference to days.
With this config file named "my.config" in the current directory, your command will look something like this:
exiftool -config my.config -m -a -r -if 'defined $timediff and $timediff > 0 and $timediff < 5' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p '-------------------------------------------------------------' DIR
- Phil
Thanks Phill for the quick response.
I added the abs function to always have the positive value.
my $secs = abs(Image::ExifTool::GetUnixTime($val[1]) - Image::ExifTool::GetUnixTime("$1:$2:$3 00:00:00"));
I did a few tests and I don't get why the > and define don't work inside of -if.
Here they are some examples I did:
Note: I'm using the Mac OS.
1 - Without -if
$ exiftool -config my.config -m -a -r -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
FileName: 20060101-025736-000-100_0785.mov
DirectoryDate: 20051231
DateTimeOriginal: 20060101
TimeDiff: 1.12333333333333 seconds
2 - Only with define $timediff it matched.
$ exiftool -config my.config -m -a -r -if 'defined $timediff' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
FileName: 20060101-025736-000-100_0785.mov
DirectoryDate: 20051231
DateTimeOriginal: 20060101
TimeDiff: 1.12333333333333 seconds
-------------------------------------------------------------
3 - Using > operator failed
$ exiftool -config my.config -m -a -r -if '$timediff > 1' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
1 files failed condition
4 - Using gt it works
$ exiftool -config my.config -m -a -r -if '$timediff gt 1' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
FileName: 20060101-025736-000-100_0785.mov
DirectoryDate: 20051231
DateTimeOriginal: 20060101
TimeDiff: 1.12333333333333 seconds
-------------------------------------------------------------
5 - But using a combination of define and gt doesn't work
$ exiftool -config my.config -m -a -r -if 'define $timediff and $timediff gt 1' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
1 files failed condition
Ah. TimeDiff has "seconds" added to it, so it isn't just numerical. My mistake. You should use $timeDiff# (with trailing "#") in the -if statement to compare the numerical value using ">".
- Phil
It works with #:
$ exiftool -config my.config -m -a -r -if '$timediff# > 1' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
FileName: 20060101-025736-000-100_0785.mov
DirectoryDate: 20051231
DateTimeOriginal: 20060101
TimeDiff: 1.12333333333333 seconds
But the combination with define doesn't work:
$ exiftool -config my.config -m -a -r -if 'define $timediff# and $timediff# > 1' -p 'FileName: ${FileName}' -p 'DirectoryDate: ${Directory;s/.*(\d{4})-(\d{2})-(\d{2}).*/$1$2$3/}' -p 'DateTimeOriginal: ${DateTimeOriginal;s/(\d{4}):(\d{2}):(\d{2})\ (\d{2}):(\d{2}):(\d{2})/$1$2$3/}' -p 'TimeDiff: $timediff' -p '-------------------------------------------------------------' \[2005-12-31\]\ Passagem\ de\ ano\ 2006/20060101-025736-000-100_0785.mov
1 files failed condition
Do you know the reason?
the key word is "defined", not "define".
Ah, great. ::)
Thanks Phil