Get part of filename (that could be absent) and write as keyword

Started by Teo_, November 28, 2016, 05:49:51 PM

Previous topic - Next topic

Teo_

I have files with this name structure
Foto 123a the file name 10X.psd
Foto 122b the file name 100X.psd

but sometimes there are file with the missing last code like:
Foto 123 the file name.psd

and I'd like to set the code in bold as keyword after all the other keywords added in the same command.

My actual solution that works when there is the bold code is:
exiftool -charset exiftool=UTF8 -sep '/' '-keywords+<${directory;s/[0-9]+ //g}' -addTagsFromFile @ '-title<${basename;s/(Foto[ \t]+).*?[ \t]+//g}' '-keywords+<${basename;s/(Foto[ \t]+).*?[ \t]+//g;s/ (\d{1,})X//g}' '-keywords<TextLayerText' '-keywords<${basename;s/.*\s(\d+X)/$1/}' -r -overwrite_original_in_place DIR
How can I ignore the command portion
'-keywords<${basename;s/.*\s(\d+X)/$1/}' when there isn't the bold code in the filename?


Teo_

Just to be clearer:


$ find DIR
DIR
DIR/SUBDIR 1
DIR/SUBDIR 1/Foto 122b the file name 100X.psd
DIR/SUBDIR 1/Foto 123a the file name 10X.psd
DIR/SUBDIR 2
DIR/SUBDIR 2/Foto 123 the file name.psd



Attached the sample files.


With the command posted before I get this results

$ exiftool -keywords -r DIR
======== DIR/SUBDIR 1/Foto 122b the file name 100X.psd
Keywords                        : DIR, SUBDIR 1, the file name, Text layer sample 1, Text layer sample 2, Another text to place as keyword, 100X
======== DIR/SUBDIR 1/Foto 123a the file name 10X.psd
Keywords                        : DIR, SUBDIR 1, the file name, Text layer sample 1, Text layer sample 2, Another text to place as keyword, 10X
======== DIR/SUBDIR 2/Foto 123 the file name.psd
Keywords                        : DIR, SUBDIR 2, the file name, Text layer sample 1, Text layer sample 2, Another text to place as keyword, Foto 123 the file name


I have to ignore the last keyword (Foto 123 the file name) added when there isn't a " ##X" code at the end of the file name.

Hayo Baan

It's a bit tricky as you want it done in one command, but after a fair bit of puzzling I got something that works for the keywords:
exiftool -sep '##' '-keywords<${directory; my @k = split(/##/, $self->GetValue("Keywords")); my $t = $self->GetValue("Directory"); $t =~ s/[0-9]+ //g; push(@k, split(/\//, $t)); my $bn = $self->GetValue("FileName"); $bn =~ s/\..{3}$//; $t = $bn; $t =~ s/(Foto[ \t]+).*?[ \t]+//g; $t =~ s/ \d+X//g; push(@k, $t); $t = $bn; if ($t =~ s/.*\s(\d+X)/$1/) { push(@k, $t) }; $_ = join("##", @k);}'
Hope you can see what I'm doing, if not, let me know :)
(Note: I use directory as (dummy) starting point instead of the more obvious tag keywords as keywords might not already have some data causing the command to fail.)

There might be even smarter ways to do this, but this at least works :D
Hayo Baan – Photography
Web: www.hayobaan.nl

Teo_

Quote from: Hayo Baan on November 29, 2016, 09:06:26 AM
Hope you can see what I'm doing, if not, let me know :)


Thanks for your help. I understand only a little of this long line but as an Apple user, is enough – at now – a «It just works»  ;D
I've added the other write functions (from layers and to title) an is still working. Thanks again!