Search and replace in array of composite tag

Started by Teo_, December 06, 2016, 09:20:40 AM

Previous topic - Next topic

Teo_

I have files with a specific name format and if I set a Composite tag in my ExifTool_config like this

NameIT => {
    Require => 'FileName',
      ValueConv => q{
         my $name = $val[0];
         $name =~ s{.*--(.*)_-_(.*)}{$1};   
         $name =~ s/[\-]/. /g;
         return $name;     
      },
},
NameEN => {
    Require => 'FileName',
      ValueConv => q{
         my $name = $val[0];
         $name =~ s{.*--(.*)_-_(.*)\.[a-z]*}{$2};
         $name =~ s/[\-]/. /g;
         return $name;     
      },
},


I can easily get multiple search and replace, so as example:
$ exiftool -filename 01a--Name1it-Name2-Other\ name3-10X_-_Name1en-Name2-Other\ name3-10X.psd
File Name                       : 01a--Name1it-Name2-Other name3-10X_-_Name1en-Name2-Other name3-10X.psd
$ exiftool -NameIT 01a--Name1it-Name2-Other\ name3-10X_-_Name1en-Name2-Other\ name3-10X.psd
Name IT                         : Name1it. Name2. Other name3. 10X
$ exiftool -NameEN 01a--Name1it-Name2-Other\ name3-10X_-_Name1en-Name2-Other\ name3-10X.psd
Name EN                         : Name1en. Name2. Other name3. 10X


My question is: can I search and replace in an array like in a string?
My files have:
$ exiftool -LayerUnicodeNames 01a--Name1it-Name2-Other\ name3-10X_-_Name1en-Name2-Other\ name3-10X.psd
Layer Unicode Names             : Sfondo, </Layer group>, </Layer group>, Test layer lang 2, Test other lang utf-8 èàü...<, Another text layer it language, IT, </Layer group>, Test layer lang 1, Test utf-8 èàü...< lang 1, Another text layer, EN, </Layer group>, Forma 9, , Ellisse 1, Shapes, Definitions

I need to export the part between "</Layer group>, </Layer group>, " and ", IT" in as KeyIT and the part between "IT, </Layer group>, " and ", EN" as KeyEN.
Looking around I can find search and replace in a value but not in a full array.
My stub is:
KeyIT => {
    Require => 'LayerUnicodeNames',
      ValueConv => q{
                my $key = $val[0];
                $key =~ s{.*group\>(.*?)\, IT.*}{$1};
                return $key;   
      },
},



Attached a sample file.

Phil Harvey

I think this might be what you want:

KeyIT => {
    Require => 'LayerUnicodeNames',
      ValueConv => q{
            my $key = ref $val eq 'ARRAY' ? join(', ', @$val) : $val;
            return $key =~ s{.*group\>, (.*?)\, IT.*}{$1} ? $key : undef;
      },
},


For List-type tags $val may be an array reference, but it seems like you need a concatenated string, so I join-ed it for you.

I also made a couple of other changes that seemed appropriate.

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

Teo_

It is exactly what I need, so adding


KeyEN => {
    Require => 'LayerUnicodeNames',
ValueConv => q{
            my $key = ref $val eq 'ARRAY' ? join(', ', @$val) : $val;
            return $key =~ s{.*group\>, (.*?)\, EN.*}{$1} ? $key : undef;
},
},

I get:

$ exiftool -KeyIT -KeyEN 01a--Name1it-Name2-Other\ name3-10X_-_Name1en-Name2-Other\ name3-10X.psd
Key IT                          : Test layer lang 2, Test other lang utf-8 èàü...<, Another text layer it language
Key EN                          : Test layer lang 1, Test utf-8 èàü...< lang 1, Another text layer
Thank you very much  :)