ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: neebah on September 28, 2016, 10:36:25 PM

Title: transferring tags based on content
Post by: neebah on September 28, 2016, 10:36:25 PM
I would like to move some tags from xmp-subject to xmp-type based on whether the subject contains a specific term within a tag.  So I guess checking via a conditional.  So like if the subject contains a tag that contains a word then move it over to the type tag
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 07:21:38 AM
Something like this maybe?:

exiftool -if "$subject =~ /\bWORD\b/" -xmp:type=WORD DIR

or do you want to add the word to existing Type list, and also remove the word from the Subject?:

exiftool -if "$subject =~ /\bWORD\b/" -xmp:type+=WORD -xmp:subject-=WORD DIR

Do you want to match subject items containing the word, or just items that are exactly the word?  Probably an exact match makes more sense, because otherwise the -xmp:subject-=WORD won't work:

exiftool -if "$subject =~ /(^|, )WORD(, |$)/" -xmp:type+=WORD -xmp:subject-=WORD DIR

- Phil
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:06:15 AM
I would like to transfer the tag based on whether or not it contains a substring. 
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:14:34 AM
So if the subject tag contains "Digital:05:2005:001" and that's the only subject contain that contains the word digital I would like to move it based on it containing the word digital. 
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 08:24:10 AM
So if one subject item contains the string "Digital" and the Subject contains more than one item, do you want to move just that item, or all items?  And what happens if more than one item contains the string?

- Phil
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:38:04 AM
I'm handling that by being choosy on the substring :)  So no two subject tags will have the same substring. 
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:42:43 AM
So I just want to copy the item that contains the substring.  Or lets say the first item that contains the substring. 
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:49:15 AM
The tag can continue to exist in the subject structure. 
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 08:53:21 AM
OK, maybe this will do:

exiftool -if "$subject =~ /WORD/" "-xmp:type+<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}" DIR

If you want to also delete this item from the Subject list, add this to the command:

"-xmp:subject-<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}"

- Phil
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:54:04 AM
Thanks Phil.  I'll give it a try.   :)
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 08:58:56 AM
Okay mild hangup.  What should WORD be if I want to move the tag containing the word "Digital"  Should it just be digital in both spots?
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 09:05:09 AM
"Digital" in both spots.

Actually, you can do it like this too and avoid the -if:

exiftool "-xmp:type+<${subject;s/^(.*, )?(.*?Digital.*?)(, .*)?$/$2/ or $_=undef}" DIR

- Phil
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 09:25:26 AM
It transferred the entire contents of the subject tag over instead of the single tag. 
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 09:31:52 AM
What is the actual Subject that you started with?  (exiftool -subject FILE)

- Phil
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 09:32:14 AM
xmp subject
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 09:46:26 AM
I meant the value of the tag.  I want to be able to reproduce this.
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 09:47:15 AM
Oh I see. 

Subject                         : GPS/Manual, OriginalType/JPG, OwnerName/Name, Storage/Digital/06/2005/00001
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 09:51:11 AM
It worked fine for me (note my quoting is different because I'm on a Mac):

> exiftool a.jpg -subject="GPS/Manual, OriginalType/JPG, OwnerName/Name, Storage/Digital/06/2005/00001" -sep ', '
    1 image files updated
> exiftool a.jpg '-xmp:type+<${subject;s/^(.*, )?(.*?Digital.*?)(, .*)?$/$2/ or $_=undef}' -v2
======== a.jpg
Setting new values from a.jpg
Adding XMP-dc:Type
Rewriting a.jpg...
  Editing tags in: APP1 XMP
  Creating tags in: APP1 XMP
JPEG APP1 (310 bytes):
JPEG APP1 (5096 bytes):
  Rewriting XMP
    + XMP-dc:Type = 'Storage/Digital/06/2005/00001'
JPEG DQT (130 bytes):
JPEG SOF0:
JPEG DHT (73 bytes):
JPEG SOS
    1 image files updated


Could your problem perhaps be FAQ 17 (https://exiftool.org/faq.html#Q17)?

- Phil
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 10:06:28 AM
Got it.  Was attempting to use the exiftool direct option in exiftoolgui
Title: Re: transferring tags based on content
Post by: neebah on September 29, 2016, 10:09:19 AM
Two more questions on this.  How can I replace the tag with another value (once its found) and how can i simultaneously delete it from the subject tag
Title: Re: transferring tags based on content
Post by: Phil Harvey on September 29, 2016, 10:15:47 AM
Replace it in XMP:Subject or XMP:Type?

If you want to copy the existing item to XMP:Type, then replace it in XMP:Subject, the command is:

exiftool -if "$subject =~ /WORD/" "-xmp:type+<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}" "-xmp:subject-<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}" "-xmp:subject+=SOMETHING ELSE" DIR

- Phil