Author Topic: Use TAG-A and output to JSON, if not Exist use TAG-B as replacement - composite  (Read 106 times)

elfreako

  • Newbie
  • *
  • Posts: 5
Hi, I've been mucking about with exiftool using just the commands, looking to output certain EXIF details into JSON which I can then import into Power BI for some basic analysis.

At the moment my basic command looks like this;
Code: [Select]
exiftool -TAG -filetype -make -model -orientation -exposureprogram -iso -shutterspeedvalue -aperturevalue -focallength -lensmodel -lens -fov -focallength35efl --ext jpg --ext jpeg --ext psd --ext psb --ext tif --ext tiff -r -j "Y:\My Pictures\Camera" > output.json
I've noticed that not all camera models have -lensmodel or -lens, thus I have to run a separate command in a sub folder using -lenstype and join the JSON together later manually.

I'm looking to filter out the manual labour in favour for some user defined EXIF tags using the Perl config. I'm no programmer, and understand a bit of code, but I do struggle. So bear with me if I ask some dumb questions, as I've searched the forums but are unable to find something I can hack together.

Essentially, I'm wanting (Require) to use -lensmodel, but if it doesn't exist I would like to (Desire) use -lens or -lenstype in its place in the JSON output. I'm thinking of something along these lines; http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,1936.msg8459.html

If anyone is able to help me with this, I would be greatly appreciated.

...whilst I'm on the subject, am I right in assuming that the following will allow me to append -camera to the script in replacement of -make and -model, combining the both to shorthand the code?

Code: [Select]
%Image::ExifTool::UserDefined::Shortcuts = (
    MyShortcut => ['exif:make' , 'model'],
    MyAlias => 'Camera',
);

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13669
    • ExifTool Home Page
The goal of the Composite LensID tag is just this, but it doesn't give LensModel the priority that you want.

It sounds like you may want to create a user-defined Composite tag as you suspected.

The logic is simple, and would look almost exactly like this config file except with different tag names.

...whilst I'm on the subject, am I right in assuming that the following will allow me to append -camera to the script in replacement of -make and -model, combining the both to shorthand the code?

Code: [Select]
%Image::ExifTool::UserDefined::Shortcuts = (
    MyShortcut => ['exif:make' , 'model'],
    MyAlias => 'Camera',
);

Not quite.  Try this:

Code: [Select]
%Image::ExifTool::UserDefined::Shortcuts = (
    Camera => ['exif:make' , 'exif:model'],
);

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

elfreako

  • Newbie
  • *
  • Posts: 5
Hi Phil, I had a crack at what you suggested but I receive an error and the output doesn't show the tags at all.

Code: [Select]
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyLens => {
            Desire => {
                0 => 'LensType',
                1 => 'LensID',
                2 => 'Lens',
            },
            ValueConv => '$val[0] || $val[1] || $val[2]',
            PrintConv => '$self->ConvertLens($val)',
        },
    },
);
1; #end

Command run;
Code: [Select]
PS E:\Downloads\Compressed> .\exiftool.exe -config .\ExifTool.config -MyLens -r -j "test" > out-test.json
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/DSC_0001.NEF
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/P5100031.ORF
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/_A143193.dng
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/_DSF5222.dng
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/_DSF9910.DNG
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/_MG_0079.dng
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/_Z1A4515.DNG
    1 directories scanned
    9 image files read

But the output is the same (show very bottom)...

So I try specifying -ConvertLens instead
Code: [Select]
PS E:\Downloads\Compressed> .\exiftool.exe -config .\ExifTool.config -ConvertLens -r -j "test" > out-test.json
    1 directories scanned
    9 image files read


But output nothing (same as first command);
Code: [Select]
[{
  "SourceFile": "test/DSCF0002.dng"
},
{
  "SourceFile": "test/DSC_0001.NEF"
},
{
  "SourceFile": "test/P1000047.dng"
},
{
  "SourceFile": "test/P5100031.ORF"
},
{
  "SourceFile": "test/_A143193.dng"
},
{
  "SourceFile": "test/_DSF5222.dng"
},
{
  "SourceFile": "test/_DSF9910.DNG"
},
{
  "SourceFile": "test/_MG_0079.dng"
},
{
  "SourceFile": "test/_Z1A4515.DNG"
}]

Any ideas where I'm going wrong?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13669
    • ExifTool Home Page
Warning: PrintConv MyLens: Undefined subroutine Image::ExifTool::ConvertLens called - test/DSC_0001.NEF

Right.  Just remove the PrintConv line from your definition.  ConvertDateTime() was used for time tags, but ConvertLens() isn't a thing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

elfreako

  • Newbie
  • *
  • Posts: 5
Ah, thank you. The command runs, but gives a strange output. Some of them have proper values, the others do not. I've checked the EXIF of the files, and I've no idea where they're getting the numeric output from? Nothing that suggests that even in the lens, as in, if the output has 6, then 6 is not actually listed in the EXIF for any Lens entry.

Code: [Select]
[{
  "SourceFile": "test/DSCF0002.dng"
},
{
  "SourceFile": "test/DSC_0001.NEF",
  "MyLens": 6
},
{
  "SourceFile": "test/P1000047.dng"
},
{
  "SourceFile": "test/P5100031.ORF",
  "MyLens": "0 23 00"
},
{
  "SourceFile": "test/_A143193.dng",
  "MyLens": "0 06 01"
},
{
  "SourceFile": "test/_DSF5222.dng",
  "MyLens": "XF18-55mmF2.8-4 R LM OIS"
},
{
  "SourceFile": "test/_DSF9910.DNG",
  "MyLens": "XF56mmF1.2 R"
},
{
  "SourceFile": "test/_MG_0079.dng",
  "MyLens": 237
},
{
  "SourceFile": "test/_Z1A4515.DNG",
  "MyLens": 254
}]

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13669
    • ExifTool Home Page
Ah, right.  You want to use the print-converted versions of your Desire'd tags:

Code: [Select]
            ValueConv => '$prt[0] || $prt[1] || $prt[2]',
Also, I thought you wanted LensModel to be one of the Desire'd tags?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

elfreako

  • Newbie
  • *
  • Posts: 5
Ah yes, that's it. I might change it around a bit in order of preference, but it is what I wanted.

Code: [Select]
[{
  "SourceFile": "test/DSCF0002.dng"
},
{
  "SourceFile": "test/DSC_0001.NEF",
  "MyLens": "G"
},
{
  "SourceFile": "test/P1000047.dng"
},
{
  "SourceFile": "test/P5100031.ORF",
  "MyLens": "Olympus Zuiko Digital ED 14-42mm F3.5-5.6"
},
{
  "SourceFile": "test/_A143193.dng",
  "MyLens": "Olympus Zuiko Digital ED 8mm F3.5 Fisheye"
},
{
  "SourceFile": "test/_DSF5222.dng",
  "MyLens": "XF18-55mmF2.8-4 R LM OIS"
},
{
  "SourceFile": "test/_DSF9910.DNG",
  "MyLens": "XF56mmF1.2 R"
},
{
  "SourceFile": "test/_MG_0079.dng",
  "MyLens": "Canon EF 24-105mm f/4L IS USM"
},
{
  "SourceFile": "test/_Z1A4515.DNG",
  "MyLens": "Canon EF 100mm f/2.8L Macro IS USM"
}]

Yes, LensModel was originally part of it, but I'm looking through some sample EXIFs to find ones  best suited. Many thanks for your input. Perhaps I might annoy you again one day...

elfreako

  • Newbie
  • *
  • Posts: 5
Cheers for your help, Phil. This is what you were able to help me achieve.

Image on 500px: https://500px.com/photo/281989057/camera-powerbi-by-paul-mackinnon?ctx_page=1&from=user&user_id=207656

Interactive Data: https://goo.gl/MkHJrL

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13669
    • ExifTool Home Page
Impressive
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).