add line of text file to metadata

Started by jacx, September 03, 2016, 02:24:09 PM

Previous topic - Next topic

jacx

Hey there,
just discovered this great tool but did not find a solution on the forum for my following question.


Could I add each line of a [text] file as a comment to an individual picture?
I want to use the ExifTool to add the url from where I downloaded each picture to its comments.

The number of lines in the text file and number of picture are identical.
The order of lines matches the pictures order.


Is it possible to achieve the desired results with only this tool or do I have to get an external "script" running?

BW,
jacx


StarGeek

#1
Directly from a text file as you describe, not without a script.  But it's possible to get the text file into a format that would work, such as a CSV file.

I would think the simplest way would be using a spreadsheet program.  Excel if you have it, otherwise Libre Office or Google Docs are free.  Load the text file into the spreadsheet so it's one url per line. 

Then you have to get a list of all the files with the full path.  This can vary by system.  On Windows, you can open a CMD and type dir /s /b C:\Path\To\PictureDirectory | Clip, replacing C:\Path\To\PictureDirectory with the actual path to the directory.  The | Clip at the end will save the whole thing to the clip board.  Insert a new column on the spreadsheet to the left of your URL list and paste the file list there.

Next, you need a header row to identify the columns.  Insert a new row at the top.  In the first cell, above the file names, put SourceFile.  In the second cell, put the name of the tag you want to write to.  Now save the spreadsheet as a CSV file.

You can now use this command to save all the data to the files:
exiftool -csv=C:\Path\To\CSV_File.csv C:\Path\To\PictureDirectory
Replace the paths as appropriate.

One thing you need to do is figure out what tag you want to use.  You say "Comment" that may not actually be what you want.  There is a Comment tag, but for the most part it's limited to jpgs and is easily overwritten.  Assuming Windows, if you mean the Comments property when you look at the Properties of a file, then Windows takes that from several different tags.  You would want to use one of these tags: EXIF:UserComment, XMP:UserComment, or EXIF:XPComment.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

jacx

Getting everything right into the excel sheet worked very well.
As you assumed I am working on windows.

The command did not work for me. I tried to replace the target tag with either one you suggested but got the same error message every time:
"Invalid tag name 'SourceFile;XMP:UserComment' in CSV file
No SourceFile 'C:/Users/.../dog.jpg' in imported CSV database
(full path: 'c:/.../dog.jpg')

I renamed the pictures when I downloaded them. Could this be an issue? Otherwise they would not be in the correct order.
Of course the names in the text file correspond to the newly given names.

Thank you so much for you fast reply,
I will try to also get a friend of mine on this topic.


Phil Harvey

Quote from: jacx on September 03, 2016, 06:07:33 PM
"Invalid tag name 'SourceFile;XMP:UserComment' in CSV file

The entries in a CSV file must be separated by commas, not semicolons (otherwise it would be an SSV file. :P )

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

jacx

Nice! Works fine now. also added the -overwrite_original to the line. Perfect!

Thank you so much!

jacx

finished my code for now and thought maybe it would be useful for some of you:

with this code you can add a downloaded pictures url to its description for referencing it with e.g. indesign.
if the picture allready contains some meta information in the specified field it does not work yet.

Set up the following folders:

-add_url_to_comment
  '--0_img
  '--1_url

place all pictures into > 0_img
place a file named url.csv into > 1_url; 1 url per line, ordered by the pictures names (a-z)

put exiftool in add_url_to_comment folder
and also place a .cmd containing the following code in the same folder.

:: write picture paths to csv
dir /s /b %cd%\0_img > %cd%\1_url\img.csv

:: add links to csv

@echo off
setlocal EnableDelayedExpansion

:: Input 1: File 1
:: Input 2: File 2
:: Input 3: Outputfile

set "file1=%cd%\1_url\img.csv"
set "file2=%cd%\1_url\url.csv"
set "fileout=%cd%\1_url\merged.csv"


< %file2% (
   for /F "delims=" %%a in (%file1%) do (
      set /P line2=
      echo %%a,!line2!
   )
) > %fileout%


:: add first row to csv
rem examine %cd%\1_url\merged.csv
type %cd%\1_url\merged.csv

@echo SourceFile,XMP:description>%cd%\1_url\fixed.csv
type %cd%\1_url\merged.csv >> %cd%\1_url\fixed.csv

rem examine %cd%\1_url\fixed file
type %cd%\1_url\fixed.csv
:: 'SourceFile,XMP:UserComment'
'SourceFile,XMP:description'

del %cd%\1_url\merged.csv
ren %cd%\1_url\fixed.csv merged.csv

exiftool -overwrite_original -csv=%cd%\1_url\merged.csv %cd%\0_img

::cleanup folder 1_url
del %cd%\1_url\img.csv
del %cd%\1_url\merged.csv


run the .cmd file to change the picture descriptions to their origin urls.

Thank you for your help!