News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Java - Creating a new Command Executor

Started by davo777, May 26, 2020, 05:32:53 AM

Previous topic - Next topic

davo777

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();



Phil Harvey

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

davo777

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

davo777

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.

Phil Harvey

I'm glad you figured it out because I wouldn't be able to help here.

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