ExifTool Forum

ExifTool => Newbies => Topic started by: J4c06r1nw1s on October 31, 2021, 07:18:42 AM

Title: Why does exiftool not have an -else or -elsif
Post by: J4c06r1nw1s on October 31, 2021, 07:18:42 AM
Why does exiftool not have an -else or -elsif function like -if I'm trying to understand.
I'm asking this because I'm repeating so much code for so much cameras makers and models.
A lot of code is the same for all cameras.
Is this how PERL works or is this how ExitTool is just meant to be?

Can you please explain that to me?
:) I like to learn and understand.


exiftool -if '$Model eq "Model A"' ...code...
exiftool -if '$Model eq "Model B"' ...repeating code...
exiftool -if '$Model eq "Model A"' ...repeating code...
...
exiftool -if '$Model eq "Model Z"' ...repeating code...

Title: Re: Why does exiftool not have an -else or -elsif
Post by: Phil Harvey on October 31, 2021, 08:16:18 AM
It sounds like you should be doing this:

exiftool -if '$model eq "Model A" or $model eq "Model B" or ...' ...code...

but I like to use regular expressions for cases like this

exiftool -if '$model =~ /^(Model A|Model B|...)$/' ...code...

- Phil
Title: Re: Why does exiftool not have an -else or -elsif
Post by: J4c06r1nw1s on October 31, 2021, 08:24:16 AM
Maybe I should explain my problem more.

In some files the Model tag does contain also the maker name in it.
NIKON D800 (has maker name in it)
COOLPIX P7100 (has not in it)

In other cases, Model tag is gives a different name then the readable model name
SM-G988B (but readable name is SAMSUNG GALAXY S20 ULTRA)

If it goes well

exiftool '-TestName</volume1/output/$Make/$Model/$Make_$Model__$FileName' -r /volume1/input


The Make tag gives SM-G988B but the readable model name is SAMSUNG GALAXY S20 ULTRA
So i must set it manually

exiftool -if '$Model eq "SM-G988B"' '-FileName</volume1/output/$Make/SAMSUNG_GALAXY_S20_ULTRA/SAMSUNG_GALAXY_S20_ULTRA__$FileName' -r /volume1/input


In iPhone files, the Model does not contain the maker name.
So i have to do it myself

exiftool -if '$Model eq "iPhone"' '-FileName</volume1/output/$Make/$Make_$Model/$Make_$Model__$FileName' -r /volume1/input


DJI AIR 2S files has no Make and Model tags
So i must set it all manually

exiftool -if '$Model eq "FC7303"' '-FileName</volume1/output/DJI/DJI_AIR_2S/DJI_AIR_2S__$FileName' -r /volume1/input



Now if I want to edit more tags like -copyright -artist -keywords, there will be a lot of repetition.
And then you have to add the -ext and -i.
Or is there a better way?
Title: Re: Why does exiftool not have an -else or -elsif
Post by: StarGeek on October 31, 2021, 10:35:12 AM
Most command line programs do not have IF THEN constructs. At least none that I can think of.  And exiftool allows options, with only a few limitations, to be placed anywhere in the command, which is common among linux commands, which is pretty much the environment that exiftool is made.

But it sounds like what you really want is to make a user defined tag that will construct the filename for you.  As an example, see this post (https://exiftool.org/forum/index.php?topic=12318.msg66643#msg66643) where I have a tag that returns the name of the owner of a camera based upon the serial number, which I then use in setting the copyright tags. 
Title: Re: Why does exiftool not have an -else or -elsif
Post by: J4c06r1nw1s on November 04, 2021, 11:29:14 AM
I'm trying it now with custom tags in a config file, but I'm running into a problem.
It does not give the correct MyMake and MyModel output.
What am I doing wrong?

exiftool -config my_config -Make -Model -MyMake -MyModel -s -ext jpg -i @eaDir \
'/volume1/homes/username/Photos/MobileBackup/Galaxy S20 Ultra 5G van User/DCIM/Camera/2021/11/20211101_082816.jpg' \


Make                            : samsung
Model                           : SM-G988B
MyMake                          : APPLE
MyModel                         : IPHONE


%Image::ExifTool::UserDefined = (
   'Image::ExifTool::Composite' => {
      MyMake => {
         Require => 'Make',
         ValueConv => q{
            if ($val == 'Apple') { return "APPLE"; }
            if ($val == 'samsung') { return "SAMSUNG"; }
            if ($val == 'GoPro') { return "GOPRO"; }
            return undef;
         },
      },
      MyModel => {
         Require => 'Model',
         ValueConv => q{
            if ($val == 'iPhone') { return "IPHONE 1"; }
            if ($val == 'SM-G988B')   { return "GALAXY S20 ULTRA"; }
            if ($val == 'Hero6 Black')   { return "HERO 6 BLACK"; }
            if ($val == 'FC7303')   { return "MINI 2"; }
            return undef;
         },
      },
   },
);


Title: Re: Why does exiftool not have an -else or -elsif
Post by: StarGeek on November 04, 2021, 11:32:14 AM
Double equal signs == is a numerical comparison.  For string comparison, use eq, e.g. if ($val eq 'Apple') { return "APPLE"; }
Title: Re: Why does exiftool not have an -else or -elsif
Post by: J4c06r1nw1s on November 04, 2021, 11:35:19 AM
But of course.
Thank you.