Adding Flickr comments to JPEG files with ExifTool

Started by hightype, March 22, 2013, 12:27:06 PM

Previous topic - Next topic

hightype

Hi, I'm new to the forum (and to ExifTool aswell) and as I wasn't able to find any information on this I thought I'd ask it on the forum.

I would like to embed Flickr's own metadata to pictures saved from Flickr, such as image title, username etc. which is stored on Flickr.
Although there are applications that do this - Flickr Downloadr and the like - but they are very unstable and have lots of bugs (the usable ones such as Bulkr are expensive and they aren't even stable).
As I'm not an expert in programming or scripting, I wasn't able to work with Python or Perl scripts (belive me I tried but I gave up shortly).

I have found out that Flickr has the ability to generate an .xml file to a given photo stored on its servers, including all the Flickr metadata (creator, picture title, uploading date and so on):
http://www.flickr.com/services/api/flickr.photos.getInfo.html

...which generates an .xml file in the following format:

<?xml version="1.0" encoding="utf-8" ?>
<photo id="2733" secret="123456" server="12" isfavorite="0" license="3" rotation="90" originalsecret="1bc09ce34a" originalformat="png">
  <owner nsid="12037949754@N01" username="Bees" realname="Cal Henderson" location="Bedford, UK" />
  <title>orford_castle_taster</title>
  <description>hello!</description>
  <visibility ispublic="1" isfriend="0" isfamily="0" />
  <dates posted="1100897479" taken="2004-11-19 12:51:19" takengranularity="0" lastupdate="1093022469" />
  <permissions permcomment="3" permaddmeta="2" />
  <editability cancomment="1" canaddmeta="1" />
  <comments>1</comments>
  <notes>
    <note id="313" author="12037949754@N01" authorname="Bees" x="10" y="10" w="50" h="50">foo</note>
  </notes>
  <tags>
    <tag id="1234" author="12037949754@N01" raw="woo yay">wooyay</tag>
    <tag id="1235" author="12037949754@N01" raw="hoopla">hoopla</tag>
  </tags>
  <urls>
    <url type="photopage">http://www.flickr.com/photos/bees/2733/</url>
  </urls>
</photo>


However - the tags and attributes used in this output .xml aren't valid EXIF or XMP tags and attributes.

The aforementioned downloaders work around this issue by importing these 'non-valid' Flickr tags into valid EXIF, XMP and IPTC tags, such as...
- the Flickr <owner> tag contents go into <IFD0:XPAuthor>, <XMP-dc:Creator>,  <IPTC:By-line> etc...
- the Flickr <title> tag contents go into <IFD0:ImageDescription>, <IFD0:XPTitle>, <IPTC:ObjectName> etc...
- the Flickr <description> tag contents go into <IFD0:XPComment>, <ExifIFD:UserComment>, <XMP-exif:UserComment>, <IPTC:Caption-Abstract> etc....

Now - I would like to ask that if I have a JPG file saved from Flickr and an XML file that was generated by FlickrAPI, is this the proper way to go to embed Flickr title, creator and comment (and everything else), and if yes, can someone please help me with configuring ExifTool to do this - or, is there already some kind of script or solution that does this with ExifTool?

Thank you in advance!

Phil Harvey

The only trick here is to figure out where you want to put the Flickr information.  Take a look at the files in the "args_files" directory of the main distribution.  These files contain exiftool arguments to map between different types of metadata.  What you want is essentially a "flickr2xmp.args" file, or something similar.

The steps are:

1) Run "exiftool -s flickr.xml" on your Flickr XML file.

2) Figure out where you want to store each piece of information, and for each one, add a line like this to the argfile:  -xmp:title<phototitle

3) Run "exiftool -tagsfromfile flickr.xml -@ flickr2xmp.args flickr.jpg" to transfer the Flickr XML information to your JPG.  Or you can do an entire directory all at once like this:

    exiftool -tagsfromfile %d%f.xml -@ flickr2xmp.args -ext jpg DIR

4) After you are happy with your .args file, post it here so others may take advantage of your hard work.

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

hightype

Thanks for the quick reply!
Duh... I was hoping that I won't have to figure out which valid XMP/IPTC/IFD0 tags are suitable to import the Flickr tags into - because I'm no expert on XMP/IPTC tag usage so I'll have to ask for help of someone who does have an experience (or I'll try to ask around on Flickr).
Anyhow, I'll try to come up with something and post here if there's some advancement...

hightype

While I'm asking 'Flickr gurus' advice on this, I would like to ask another question.

Since regular EXIF/IPTC tags aren't really suitable for storing certain info from Flickr (such as user comments) - there was a suggestion that the whole Flickr XML sidecar file could be stored in the JPEG file (a backup and a futureproof solution) and the best field to store it would be the JPEG Comment.

I have been experimenting with ExifTool to import the whole XML into the Comment field with the following command:
exiftool "-Comment<=sidecar.xml" dst.jpg
...which imports the file perfectly, but I wasn't able to figure out how to extract it again.

Using the example Flickr XML file in the previous post, when I import it into a JPEG as Comment and try to extract it with this command:
exiftool -Comment dst.jpg > extracted.xml
...I get the following garbled result:

Comment                         : <?xml version="1.0" encoding="utf-8" ?>..<photo id="2733" secret="123456" server="12" isfavorite="0" license="3" rotation="90" originalsecret="1bc09ce34a" originalformat="png">..  <owner nsid="12037949754@N01" username="Bees" realname="Cal Henderson" location="Bedford, UK" />..  <title>orford_castle_taster</title>..  <description>hello!</description>..  <visibility ispublic="1" isfriend="0" isfamily="0" />..  <dates posted="1100897479" taken="2004-11-19 12:51:19" takengranularity="0" lastupdate="1093022469" />..  <permissions permcomment="3" permaddmeta="2" />..  <editability cancomment="1" canaddmeta="1" />..  <comments>1</comments>..  <notes>..    <note id="313" author="12037949754@N01" authorname="Bees" x="10" y="10" w="50" h="50">foo</note>..  </notes>..  <tags>..    <tag id="1234" author="12037949754@N01" raw="woo yay">wooyay</tag>..    <tag id="1235" author="12037949754@N01" raw="hoopla">hoopla</tag>..  </tags>..  <urls>..    <url type="photopage">http://www.flickr.com/photos/bees/2733/</url>..  </urls>..</photo>

Notice that the line breaks were replaced by two dots (although they were perfectly embedded in the JPEG file) and now the whole XML stands from a single line.
I wonder if this an issue with the output file's format... anyone could give any hint pls?
Thanks!

Phil Harvey

Close.  You just need to add the -b option to extract as binary data:

exiftool -comment -b dst.jpg > extracted.xml

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

hightype

Thank you, works perfectly! If nothing else, this is already a step in Flickr-archiving. I hope I'll be able to find someone who can help with organizing the Flickr tags into EXIF/IPTC. It is possible that I'll have more noob questions then...