please allow users to get and set tags by ID instead of just by name

Started by dae65, July 24, 2020, 02:01:11 AM

Previous topic - Next topic

dae65

Quote from: Phil Harvey on July 29, 2020, 06:47:57 AM
Did you see the GetTagID() function?

I did. The GetTagID() function, however, seems unable to disambiguate tag names such as Album.

Edit: nonsense removed by myself.

Phil Harvey

Quote from: dae65 on July 31, 2020, 06:40:11 AM
I did. The GetTagID() function, however, seems unable to disambiguate tag names such as Album.

It takes a tag key as an argument.  Use the tag keys returned by ImageInfo().  These are not ambiguous.

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

dae65

Great! Thanks. :) Now it works.

And I'd like to share, if it's okay with you, the following piece of code that generates a hash reference from groups and IDs to values:


my $by_id;
foreach my $group ( @groups ) {
  my $by_name = $et->ImageInfo ( $file, { Group1 => $group } ) or next;
  $by_id->{$group}->{ $et->GetTagID ($_) } = $by_name->{$_} for keys %$by_name;
}


Someone might find that helpful in the future. And I'm going to delete all nonsense from my previous message so as not to mislead others.

Thank you, Phil, for going into the trouble of replying to my posts, and especially of coding all this.

Phil Harvey

Great.  Glad you've got things working now.

- Phil

Edit:  Just one comment:  Instead of calling ImageInfo() repeatedly, it would be faster to call ExtractInfo() once, then GetInfo() for each group.  This way the file is only processed once, rather than for each group.
...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 ($).

dae65

Nice! It's indeed faster:


my $by_id;
if ( $et->ExtractInfo ( $file ) ) {
  foreach my $group ( @groups ) {
    my $by_name = $et->GetInfo ( { Group1 => $group } ) or next;
    $by_id->{$group}->{ $et->GetTagID ($_) } = $by_name->{$_} for keys %$by_name;
  }
}


Thanks!

Phil Harvey

For the benefit of others reading this thread:

See this thread for some questions and answers about the new family 7 group names.

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