Why does exiftool not have an -else or -elsif

Started by J4c06r1nw1s, October 31, 2021, 07:18:42 AM

Previous topic - Next topic

J4c06r1nw1s

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...

Using ExifTool v12.37 on Linux

Phil Harvey

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

J4c06r1nw1s

#2
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?
Using ExifTool v12.37 on Linux

StarGeek

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 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. 
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

J4c06r1nw1s

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;
         },
      },
   },
);


Using ExifTool v12.37 on Linux

StarGeek

Double equal signs == is a numerical comparison.  For string comparison, use eq, e.g. if ($val eq 'Apple') { return "APPLE"; }
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

J4c06r1nw1s

Using ExifTool v12.37 on Linux