"User Field Definitions"

Started by EzraButler, July 10, 2019, 07:30:07 AM

Previous topic - Next topic

StarGeek

#15
Ahhh.  Finally got it.  There's an interaction between the -sep option and the comma in the CoverDisplayDate field.  You probably see the same problem in Caption of 146277.psd.

I'm not sure if there's a way to fix this other than to use a different separator, as the -sep option will affect any string in one of these added fields that contains the separator.  For example, double hashtags between the keywords and use -sep "##"  Or the other option would be to run without the -sep option and then run a second command to fix the keywords.  The first run would require use of the -m (ignoreMinorErrors) option, because Keywords normally has a limit to how long the keywords are.

The later would look like this
exiftool -m -csv=test.csv .
exiftool -sep "," -tagsFromFile @ -keywords .

edit: Tried to code a workaround, but the -sep option affects the value once it gets written to the UserFields
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

EzraButler

That was a simple fix. I just changed the separator to a semicolon and it worked perfectly.

Thank you so much again for all your help!!

StarGeek

Make sure you be aware of the possibility of a semicolon elsewhere in your data.  You'll have the same problem. 
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

EzraButler

Good point! Double hashtags it is!

StarGeek

I knew I had fixed the ARRAY problem and finally realized I had created this based upon my old code.  It doesn't solve the problem with the sep option interaction, but would have made it more obvious what the problem was.

In this code, the case of data with a comma while using -sep, for example,
exiftool -config test.config -sep "," -CoverDisplayDate="April 15, 2019" FILE
would result in a UserFields with the value
CoverDisplayDate=April 15, CoverDisplayDate= 2019

Not the desired result, but it handles the data properly and makes it more obvious where the problem is.

It's up to you if you want to fix the code as it works well enough as long as you watch out for the separator characters.

Yes, this has been rolling around in my head for the past 6 hours before I remembered I had the correct code duplicated in a different config file.

# Config file to write values to MediaPro Userfields, format it as FIELD=VALUE tag pairs, and treate
# each item as an individual tag.
#
# These tag names MUST be treated carefully and as if they were being added to a List type tag
# as described in exiftool FAQ #17 <https://exiftool.org/faq.html#Q17>
# If you simply assign a value, such as -IsOuttake=True, then this value will OVERWRITE
# all previous Userfields values.
#
# Requires exiftool ver 10.13 or earlier, or 10.98 or later

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
#---------------------------
CoverDisplayDate => {
Require => 'XMP-mediapro:UserFields',
Writable => 1,
List => 'Bag',
WriteAlso => {
'XMP-mediapro:UserFields' => q {
# Check if $val is ARRAY reference, if so, de-reference else pass value as array
my @temp = (ref $val) ?  @{$val} : ($val);
@temp = map { $_='CoverDisplayDate='.$_ } @temp; # Change This
return(@temp ? \@temp :undef);
},
},
ValueConv => q{
my @HSList = ref $val[0] eq 'ARRAY' ? @{$val[0]} : (defined $val[0] ?( $val[0] ):());
my @Filtered = grep {m/^CoverDisplayDate=/ } @HSList; # Change This
@Filtered = map {s/^CoverDisplayDate=// ; $_} @Filtered ; # Change This
return @Filtered ? \@Filtered :undef;
},
},
#---------------------------
########
},
);

#------------------------------------------------------------------------------
1;  #end
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).