I'm attempting to make a user defined tag that works with the MWG Keywords and having a problem. The tag requires KeywordInfo structure exist but only works if I add the -struct option.
Here's a test config file. It's meant to simply return "Works" if KeywordInfo exists.
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
TestMWG =>{
Require => 'KeywordInfo',
ValueConv => sub {
my ($val, $et) = @_;
my $MainArray_Ref = (${@$val[0]}{'Hierarchy'});
# More stuff to follow
return 'Works';
},
},
########
},
);
1; #end
My test file has the KeywordInfo from from this command:
exiftool -struct -KeywordInfo="{Hierarchy=[{Children=[{Children=[{Keyword=Georgia},{Keyword=Wyoming}],Keyword=States}],Keyword=Places},{Children=[{Keyword=Cat},{Keyword=Georgia}],Keyword=People},{Children=[{Children=[{Keyword=Cat},{Keyword=Dog}],Keyword=Mammals}],Keyword=Animals}]}" y:\!temp\Test4.jpg
When I run this config file, I only get the tag if I add the -struct option:
C:\>exiftool -config test3.config -TestMWG y:\!temp\Test4.jpg
C:\>exiftool -config test3.config -TestMWG y:\!temp\Test4.jpg -struct
Test MWG : Works
Is it possible to Require a structured tag without using the -struct option?
You can set the Struct option in the %Image::ExifTool::UserDefined::Options of the config file. Would that be good enough?
- Phil
I'm not sure. I was hoping there was a way of detecting it and I was just missing out.
The objective is to convert between MWG:Keywords and HierarchicalSubject. I've got the MWG to HS part working and it copies fine with or without the -struct option. If all someone wants to do is copy from one to the other, then it's fine. But if someone wants to just get the HierarchicalSubject data for processing somewhere else, it requires the -struct option and it'll take extra steps to remove the structure from it, made extra problematic by the fact that HierarchicalSubject uses pipe characters.
Example output:
C:\>exiftool -config MWGKeywordsConversion.config "-MWGKeywordsToHS" y:\!temp\Test4.jpg
C:\>exiftool -config MWGKeywordsConversion.config "-MWGKeywordsToHS" -struct y:\!temp\Test4.jpg
MWG Keywords To HS : [Places||States||Georgia,Places||States||Wyoming,People||Cat,People||Georgia,Animals||Mammals||Cat,Animals||Mammals||Dog]
C:\>exiftool -config MWGKeywordsConversion.config -P -overwrite_original -TagsFromFile @ "-HierarchicalSubject<MWGKeywordsToHS" y:\!temp\Test4.jpg
1 image files updated
C:\>exiftool -HierarchicalSubject y:\!temp\Test4.jpg
Hierarchical Subject : Places|States|Georgia, Places|States|Wyoming, People|Cat, People|Georgia, Animals|Mammals|Cat, Animals|Mammals|Dog
I completely blame @colink for bringing up the MWG:Keywords tags, which implanted this earworm in my head. :D I've got a bit of a better grip on structure tags now because of it.
I'm glad you're getting more familiar with structures. They are definitely more complicated than I would have liked (one of the more advanced ExifTool features for sure).
The other way to test for this is to look for the flattened tags. Looking at this structure, if the MWG:KeywordInfo structure extists, then HierarchicalKeywords1 should certainly exist as a flat tag.
- Phil
Edit: I should mention that if you set the API Struct option to 2 (eg. via the config file), then you will get both structured and flattened tags.
After thinking about it overnight, I feel it's probably good enough to just be able to do the conversion. MWG:Keywords are rare enough and probably very few people will have use for this config. It's certainly not for my own use. Maybe if someone decides they want more flexibility and speaks up, then I'll think about checking for HierarchicalKeywords1. It just feels like a bit of a hack.
I just have to finish off the reverse tag (HS to Keywords) and then I'll post it.