ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: captured on November 05, 2018, 08:20:07 PM

Title: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: captured on November 05, 2018, 08:20:07 PM
Hello.

System: Linux Mint 18.4 64bit, exiftool 11.10, bash 4.3.48

Is it possible to use exiftool to attempt to extract a DateTimeOriginal or DateCreated...
and if they do not exist, to substitute the the FileModifyDate ?

I'm using this now;
exiftool -T -d "%Y-%m-%d" -q -q -m -p '$datetimeoriginal; $filemodifydate; $filename; $filetype; $mimetype; $imagewidth; $imageheight' .

Results;
2018-05-25; 2018-07-17; Stock-Photo-259551609.jpg; JPEG; image/jpeg; 2000; 766
-; 2018-06-06; 5Daydeal_Post.jpg; JPEG; image/jpeg; 1185; 670

Explanation;
If there is no exif (datetimeoriginal), it will be a dash in the first field (delimiter ; ).
I can use awk to obtain the filemodifydate from the second field, it will always be available
since it is an attribute direct from the file.

Question;
Can I have exiftool use 'if' logic... for example if there is no DateTimeOriginal or CreateDate,
use the FileModifyDate instead and appear in the 1st field (6 total fields, not 7) ?
2018-06-06; 5Daydeal_Post.jpg; JPEG; image/jpeg; 1185; 670

Thank you.

Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: Phil Harvey on November 05, 2018, 09:28:11 PM
The question is: What do you want to do with it once it is extracted?  If you just want to extract a single value from a list of tags by applying some logic like this, then a user-defined Composite tag is the way to go, with a config file something like this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => {
                0 => 'DateTimeOriginal',
                1 => 'CreateDate',
                2 => 'FileModifyDate',
            },
            ValueConv => '$val[0] || $val[1] || $val[2]',
            PrintConv => '$self->ConvertDateTime($val)',
        },
    },
);
1; #end


The command could be:

exiftool -config my.config ... -p '$mydate; ...' ...

- Phil
Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: captured on November 05, 2018, 10:22:06 PM
I am contantly amazed by your program Phil.

A Million Thanks.
I spent a lot of time on the docs, didn't arrive at what you did..., beautiful.

Happy again.

Final;
exiftool -config my.config -T -d "%Y-%m-%d" -q -q -m -p '$mydate; $filename; $filetype; $mimetype; $imagewidth; $imageheight' .

P.S.

Can I use the my.config to organize my files copied to a Directory Structure, no change to files;
-Year (from $mydate)
    -Model (exif)
        -Month (from $mydate)
            -MyDate (%Y-%m-%d)
                -filename (Original unchanged)

Like This;

2018/
├── Nikon_D750
│   └── 10
│       └── 2018-10-31
│           ├── DSC_6080.NEF
│           ├── DSC_6080.xmp
│           ├── DSC_6119.NEF
│           ├── DSC_6119.xmp
└── Zenphone
    └── 09
        └── 2018-09-23
            ├── Stock-Photo-110296445.webp
            ├── Stock-Photo-110682663.webp
            ├── Stock-Photo-115748165.jpg
            └── Stock-Photo-118128801.jpg

Thank you.


Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: Phil Harvey on November 06, 2018, 07:03:20 AM
Quote from: captured on November 05, 2018, 10:22:06 PM
Can I use the my.config to organize my files copied to a Directory Structure, no change to files;
-Year (from $mydate)
    -Model (exif)
        -Month (from $mydate)
            -MyDate (%Y-%m-%d)
                -filename (Original unchanged)

This should do it:

exiftool '-directory<DSTDIR/${mydate#;DateFmt("%Y")}/${model;tr/ /_/}/${mydate#;DateFmt("%m")}/$mydate' -d %Y-%m-%d SRCDIR

Search the forum for "MyModel" if you also want to do any tweaking of the model names.  To handle files without a Model, you may want to do something like this:

exiftool '-directory<DSTDIR/${mydate#;DateFmt("%Y")}/NO_MODEL/${mydate#;DateFmt("%m")}/$mydate' '-directory<DSTDIR/${mydate#;DateFmt("%Y")}/${model;tr/ /_/}/${mydate#;DateFmt("%m")}/$mydate' -d %Y-%m-%d SRCDIR

- Phil
Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: captured on November 07, 2018, 11:20:33 AM
I'll fine tune the Model later, thanks Phil.

In the meantime, I'm not achieving...

my.config (/home/user/Desktop/my.config)
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => {
                0 => 'DateTimeOriginal',
                1 => 'CreateDate',
                2 => 'ModifyDate',
                3 => 'FileModifyDate',
            },
            ValueConv => '$val[0] || $val[1] || $val[2] || $val[3]',
            PrintConv => '$self->ConvertDateTime($val)',
        },
    },
);
1; #end


exiftool -o . -config ~/Desktop/my.config '-directory</home/user/Desktop/DestFolder/${MyDate#;DateFmt("%Y")}/${MyDate#;DateFmt("%m")}/$MyDate' -d %Y-%m-%d /home/user/Desktop/SrcFolder/*

Warnings;
Warning: No writable tags set from /home/user/Desktop/SrcFolder/Beach-Rangiroa-Tuamotu-Island-French-Ocean-Sky-Palms-Polynesia-Isla.jpg
Warning: [minor] Tag 'MyDate' not defined - /home/user/Desktop/SrcFolder/Beautiful-Beach.jpg

Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: Phil Harvey on November 07, 2018, 11:23:23 AM
You should have also got this message:

Ignored -config option (not first on command line)

- Phil
Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: captured on November 07, 2018, 12:14:47 PM
Sorry about that Chief.

Hats off 2 U again.

Cheers.

[Solved]
Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: Kenneth on November 23, 2018, 04:28:41 AM
Hi Phil... I'm trying to understand this magic tool and I come across this code which if I'm right it selects the first date on the list and places that date into the mydate variable. Now suppose what I really want is not just the first date it finds, but the earliest date it finds. How can I change this code to do that and also add any other possible dates, like ProfileDateTime? What I really want is to extract the earliest date anywhere in the metadata and push that to the Create Date and the Modify Date unless the modify date is later than the pushed Create Date.

My reasoning is that given all the various dates available in photo file metadata if the Create Date is later than any other date, it must be wrong. Seems to me that the photo cannot be created after it is modified or profiled or anything else. As I have acquired tons of photos from a large number of family members and they have been copied over and over, there are a great many photos whose dates are garbage. So setting create to the earliest is the best I can do.
Title: Re: If DateTimeOriginal Doesn't Exist, Use Next available Modified Date
Post by: Phil Harvey on December 01, 2018, 10:38:41 AM
Answered in this thread (https://exiftool.org/forum/index.php/topic,9686.0.html).