Keywords Truncating From CSV

Started by James Penner, May 14, 2014, 04:37:16 PM

Previous topic - Next topic

James Penner

Hello,

I'm suddenly having difficulty writing keywords to images from a CSV file.

The keywords as they appear in the CSV file (MetaDataIn.csv) are: "Vancouver" "Cone Zone" "Vancouver Police Department" "CVSE" "Burrard Street Bridge"
They are separated by quotes and spaces, as Flickr seems to prefer this format.

However, when I use: exiftool -csv="MetaDataIn.csv" *

The keywords that are written to the images are truncated to: "Vancouver" "Cone Zone" "Vancouver Police Department" "CVSE" "Bu

Up till now, it's been working fine, so I'm at a loss as to what the problem might be.

Any insight would be greatly appreciated.

Thank you for your time.

James Penner

I think I understand what's happening. The way the keywords are currently formatted, it's looking at the string all as one keyword and truncating at the 64 character limit. Is there a way to use ExifTool to specify that the quotes are meant as separators?

Or, would I be better off returning to using a comma to separate keywords and trying to figure out a second process to convert to a Flickr-friendly version? Are there any suggestions as to how I can store keywords so they'll be recognized as separate by both Flickr and more conventional systems?

James Penner

Ok, I think I've solved my problem after seeing this thread:  :) https://exiftool.org/forum/index.php?topic=4053.0

I'm now using: exiftool -csv="MetaDataIn.csv" -IgnoreMinorErrors *

And it seems to write the tags in quotes without issue.

I'm continuing to research the topic, but offhand, are there any obvious issues with formatting the tags primarily for Flickr (using quotes and spaces to separate keywords)?

Thanks,

Phil Harvey

But it seems you are still writing the keywords as a single string, which is wrong.  You can use the -sep option to separate them into individual keywords when writing, but you need to have a fixed separator string.  -sep '" "' comes close (if you are on Mac or Linux... the quoting in Windows would be trickier), but you will still wind up with a quote at the start of the first keyword and at the end of the last.

See FAQ 17 for a related discussion.

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

James Penner

Phil, thank you very much for following up on this. I thought I had it figured out, so I really appreciate you pointing out that there's still a problem with my approach.

I've read through FAQ 17, and I think I have an understanding of what's required to write the keywords as separate terms.

I am on a Windows machine, and I'm now using: exiftool -csv="MetaDataIn.csv" -IgnoreMinorErrors -overwrite_original -sep """ """ *

It appears to work. Windows is separating the terms with semi-colons when I view the image property details, and Flickr seem to see them as individual keywords, too.

When I generate a CSV, I see the keywords are recorded as: , Vancouver,  , Cone Zone


This doesn't seem like a very clean way of doing it, but it does seem to work for our purposes.

Is there anything obviously wrong with this approach?

We've got a lot of images to process, and I want to make sure I get things right  :)

Thank you again for your time and assistance.

Phil Harvey

I'm not happy yet because I don't think your keywords are clean.  Another way is to do this in 2 steps, which would allow us to use ExifTool's advanced formatting feature in the second step:

1) exiftool -csv="MetaDataIn.csv" -IgnoreMinorErrors -overwrite_original *

2) exiftool "-keywords<${keywords;s/"" ""/xxx/g;tr/""//d}" -sep xxx *

Here I have doubled the quote characters as you showed me how to do in a quoted Windows argument.

The second command replaces quote-space-quote with xxx, then removes the remaining quotes from the string, and writes this back into itself using  xxx as the separator.  Tricky, but I tried it and I think it does what you want.  (Make sure you don't run the second command on a file with properly separated keywords because it would combine them back together again.)

In the end I wound up with this from your example input:

> exiftool a.jpg -keywords -sep /
Keywords                        : Vancouver/Cone Zone/Vancouver Police Department/CVSE/Burrard Street Bridge


which looks good to me.

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

James Penner

That works really well to clean things up, and Flickr recognizes the separate keywords, which is great. However, Windows seems to now be viewing all the keywords as one string (individual "tags" are separated with semicolons, but none are shown in the attached image). That said, I tried a search in Windows Explorer, and it seemed to work when I did a search for one tag AND another, so I don't know if this is an issue or not, or if it'll cause issues with other programs down the road.

Assuming we do process our images this way, how could I modify  exiftool -keywords<${keywords;s/"" ""/xxx/g;tr/""//d}" -sep xxx *

to change keywords from:

"Test 1" "Test 2" "Test 3"

to

Test 1; Test 2; Test 3

(or to some other more commonly-recognized format). 

I've tried a couple variations, but I still don't quite understand how to write the argument properly.  ???

Phil Harvey

Telling me what Windows shows doesn't help me much.

What is the output of this command for your image?: exiftool -keywords -sep /

If there are slashes separating the keywords in this output, then they are stored separately as they should.

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

James Penner

There aren't any slashes returned. I tried uploading a screenshot of what I see after running the command, but I'm getting an error: "Your attachment has failed security checks..."

Here's a link to the image from my dropbox, if that helps:

https://dl.dropboxusercontent.com/u/32701452/test3.jpg

Phil Harvey

Hi James,

I can't use dropbox from here, but there must be something different going on from what I did in my example.  Can't you just cut and paste the ExifTool output as text?  It would be useful to see this output after each command from my earlier post.

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

James Penner

Hi Phil,

I don't have my files from work, so unfortunately I can't check them to see what I was doing differently or where I was going wrong. I'm going through things step-by-step at home to try to recreate the problem. I've copy/pasted directly from the command prompt and included the keywords as they appeared when I exported them to a CSV, so hopefully that makes things easier to understand. Strangely, I now seem to be having a problem with the formatting command, exiftool "-keywords<${keywords;s/"" ""/xxx/g;tr/""//d}" -sep xxx * which I'm sure was working fine before. At any rate, here's what I've got:

Keywords as originally entered into CSV:
   "Test Keyword 1" "Test Keyword 2" "Test Keyword 3" "Test Keyword 4" "Test Keyword 5"

C:\test>exiftool -csv="MetaDataIn.csv" -IgnoreMinorErrors -overwrite_original -sep """ """ *

C:\test>exiftool -keywords -sep / "c:\test\test.jpg"
Keywords                        : /Test Keyword 1/ /Test Keyword 2/ /Test Keyword 3/ /Test Keyword 4/ /Test Keyword 5


Keywords as they appear when exported to CSV:
, Test Keyword 1,  , Test Keyword 2,  , Test Keyword 3,  , Test Keyword 4,  , Test Keyword 5

Here comes the problem I mentioned. I enter the formatting command you provided, and get "No file specified."
C:\test>exiftool "-keywords<${keywords;s/"" ""/xxx/g;tr/""//d}" -sep xxx *
No file specified


I'm guessing this may have something to do with the quotes. I changed the number of them, and it found the file, but it didn't reformat the keywords as expected"
C:\test>exiftool "-keywords<${keywords;s/""" """/xxx/g;tr/"""//d}" -sep xxx *
    1 image files updated

C:\test>exiftool -keywords -sep / "c:\test\test.jpg"
Keywords                        : /Test Keyword 1/ /Test Keyword 2/ /Test Keyword 3/ /Test Keyword 4/ /Test Keyword 5


Keywords as they appear when exported to CSV:
, Test Keyword 1,  , Test Keyword 2,  , Test Keyword 3,  , Test Keyword 4,  , Test Keyword 5



I'm going to try looking at this more tomorrow. I'm probably missing something really obvious, but it's getting late, and the screen is getting blurry.

Phil Harvey

Please try the 2 commands I gave (numbered 1 and 2 in an earlier post).  Note that command number 1 does not have a -sep option.

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

James Penner

... Well that's embarrassing. I was so focused on the second command, I didn't even notice that mistake. Trying again:  :-[

C:\test>exiftool -csv="MetaDataIn.csv" -IgnoreMinorErrors -overwrite_original *
    1 image files updated

C:\test>exiftool -keywords -sep / "c:\test\test.jpg"
Keywords                        : "Test Keyword 1" "Test Keyword 2" "Test Keyword 3" "Test Keyword 4" "Test Keyword 5"



Here I had the same problem as before with not being able to find the file.

C:\test>exiftool "-keywords<${keywords;s/"" ""/xxx/g;tr/""//d}" -sep xxx *
No file specified


But if I changed the quotes to:

exiftool "-keywords<${keywords;s/""" """/xxx/g;tr/"""//d}" -sep xxx *
    1 image files updated


Everything seems to work perfectly.

C:\test>exiftool -keywords -sep / "c:\test\test.jpg"
Keywords                        : Test Keyword 1/Test Keyword 2/Test Keyword 3/Test Keyword 4/Test Keyword 5


Keywords in CSV
Test Keyword 1, Test Keyword 2, Test Keyword 3, Test Keyword 4, Test Keyword 5

So it seems like the keywords are being stored separately, and both Windows and Flickr see them properly. Awesome! ;D I can't wait to try this out at work on a batch of images.

Thank you very much for your patience, Phil, I really appreciate your help.

Phil Harvey

Hi James,

Excellent!  I can't say I understand the Windows quoting, but it looks like everything is working correctly for you now.

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