Is it possible to create a user defined tag that can edit part of another, real tag?
As an example, I can create a user defined tag that will read a tag, match part of it, and return the match only. For example, if I put a pattern of "%%My Pseudo-Tag%%" in Description, this definition will return the text "My Pseudo-Tag".
MyPseudoTag => {
Require => 'Description',
ValueConv => q{
(my $tag) = ($val=~/%%(.*)%%/);
return ( (defined $tag) ? $tag : undef);
},
},
In this case, would it possible to make a user defined tag that would edit Description and replace just what was between the double percent signs or add them if they didn't exist.
I looked at WriteAlso but couldn't find any examples other than in the exiftool source code and this thread (https://exiftool.org/forum/index.php?topic=5640.0), and nothing that tried to edit the data before writing it to the tag.
This is mostly just a thought experiment. I'm not even sure I have a use for this ability if it is possible. It's just an idea I had as an alternate to creating a whole new tag for specific data. That way it could still be readable in most asset management programs but allow some flexibility in a workflow.
If I understand what you are asking, your new tag would need access to the existing value of Description when writing. Interesting, but there is no mechanism in ExifTool to allow this. I'll think about this a bit more when I get a chance, but I don't see a way to do this right now.
- Phil
No worries. It was just a thought and I couldn't figure out if it was possible or not.
I was thinking about this. Currently the only features that allow you to modify values in a single pass when writing are the "+=" and "-=" operators on the command line. I could see getting into some confusing situations if "=" modified existing values. This also raises new questions like what happens if two different Composite tags modify the same value?
I see what you were thinking, and it would be more convenient than the alternative of using the copy feature, which could look something like this:
exiftool "-description<newdescription" -userparam mypseudotag="new value" FILE
with this Composite tag definition:
NewDescription => {
Require => 'Description',
ValueConv => q{
my $str = $self->Options('UserParam', 'MyPseudoTag');
return undef unless defined $str;
$val =~ s/%%.*%%/%%$str%%/ or return undef;
return $val;
},
},
- Phil
Just for the fun of it, I have patched my working version of ExifTool to allow you to do this with the following UserDefined Composite tag definition:
MyPseudoTag => {
Require => 'Description',
ValueConv => q{
(my $tag) = ($val=~/%%(.*)%%/);
return ( (defined $tag) ? $tag : undef);
},
Writable => 1,
WriteAlso => {
Description => '$opts{Modify} = 1; "s/%%.*%%/%%$val%%/"',
},
},
So the command would be:
exiftool -MyPseudoTag="NEW VALUE" FILE
Adding this feature wasn't as difficult as I thought. I have also added the ability to modify any tag value on the command line with ~=, so this command would do the same thing:
exiftool "-description~=s/%%.*%%/%%NEW VALUE%%/" FILE
But I don't know if I want to include this feature in a release version. My biggest concern is the syntax. "~=" is confusing to me because the associated Perl operator is the other way around ("=~"). I can't use "=~" for ExifTool because that would break backward compatibility for anyone writing a value that begins with a tilde. I have to think about this. Any feedback would be appreciated.
- Phil
As I said, this was just a thought I had. I'm not even sure it would be something I would use and you brought up issues I didn't think about. Unless someone else has an actual use, I'd say don't bother unless you really want to. It just seems that in the long run it might introduce more problems that it would solve.
Good point. However I'm still having fun playing with this... for now. :P
- Phil
Yeah. I'm scrapping this mod. Turns out it is difficult to get it to work properly with list-type tags.
- Phil
Glad to have given you some entertainment.
I didn't even think about how to have it interface with lists.
Like a good book, I just couldn't put this down. :P
I've got lists working now. :)
Still lots more testing to do, but there is a chance now that this may make it into the release version. If it does, I'm not sure if I'll document it right away, or leave it as a hidden feature for a while.
- Phil
Encountered more problems with tags that have complex conversions. I'm scrapping this again until further notice.
- Phil