ExifTool Forum

ExifTool => Developers => Topic started by: davo777 on May 26, 2020, 05:32:53 AM

Title: Java - Creating a new Command Executor
Post by: davo777 on May 26, 2020, 05:32:53 AM
Hello,

I've ran into an issue where I'm struggling to translate a command line argument into some java code.
I want to run this "ExifTool.exe -a C:\Users\MyName\Downloads\file-name.zip" using the mjeanroy java library.

My understanding of the library is that it should be possible by creating a new command executor, however it always seems to default back to the previous 'baseline' exiftool app.

This is what I'm trying to do at the moment:


Command exifToolCommandLineArgs = CommandBuilder
               .builder(EXIFTOOL_PATH)
               .addArgument("-a")
               .build();

ExifToolCommandExecutor exifToolCommandExecutor = new ExifToolCommandExecutor(exifToolCommandLineArgs);



ExifTool tool = new ExifToolBuilder()
         .withExecutor(exifToolCommandExecutor)
         .build();


Title: Re: Java - Creating a new Command Executor
Post by: Phil Harvey on May 26, 2020, 06:03:30 AM
Have you looked at the example Java examples in the programming examples section of the ExifTool home page (https://exiftool.org/#related_prog)?

- Phil
Title: Re: Java - Creating a new Command Executor
Post by: davo777 on May 26, 2020, 07:29:25 AM
Unfortunately there aren't any examples for this particular scenario. I've now created a new ExecutionStrategy, which include the -a tag for duplicates, however the image metadata method only seems to return 1 line of the metadata at the moment.

For example my current command + output using java is :
C:\Users\Name\bin\exiftool.exe\ExifTool -a -n -S -ZipFileName C:\Users\Name\AppData\Local\Temp\ace3ba90-76d1-4ea8-bd01-38a8468195e4\d11aa22a-0cc5-4c0c-ba67-a5564356df52.zip -execute

{UnspecifiedTag{name: "ZipFileName"}=SupplementaryMaterialTables_V1.docx}

Where as on the command line:
C:\Users\Name\bin\exiftool.exe\ExifTool -a -n -S -ZipFileName C:\Users\Name\Downloads\file.zip -execute

ZipFileName: Scheme02_V1.tiff
ZipFileName: SupplementaryMaterialFigures_V1.docx
ZipFileName: SupplementaryMaterialTables_V1.docx


Edit:
I suspect it's something to do with the UnspecifiedTag.
It returns a String List and I'm only handling a string...
Consequently, when parsing, it returns a String[] regardless of whether the tag will ever have multiple values. Further parsing is then up to the caller.

Map<Tag, String> zipFileNameMap =
               tool.getImageMeta(tempFile, Collections.singleton(zipFileNameTag));


Due to the Tag being the key, it seems like the String value is being overridden each time.
Title: Re: Java - Creating a new Command Executor
Post by: davo777 on May 27, 2020, 10:47:35 AM
Can't seem to edit my previous post.

My solution has been to create helper classes, turning the Map<Tag, String> to Map<String, Tag> which means duplicates aren't removed.
Title: Re: Java - Creating a new Command Executor
Post by: Phil Harvey on May 27, 2020, 09:41:02 PM
I'm glad you figured it out because I wouldn't be able to help here.

- Phil