Using flickcurl in a script

Tags: , , , , , , , , ,

I’ve recently started using Flickr more than I have before, where my workflow consisted of using Lightroom to sort out the photos, process them and to give them a rating, export from lightroom, watermark, upload all the files to my photostream, and then add the photos I’d rated with at least 4 stars to a particular photo pool. These steps were not as seamless to me as they could have been, so I started looking for ways to automate the process. flickcurl came up as an obvious candidate, so I put together the following script.

Pre-requisites for this script to run are

You should be able to install all the pre-requisites on a Debian-based system using apt:

sudo apt-get install flickcurl-utils jhead imagemagick xmlstarlet

And now for the script:

#!/bin/bash
if [ ! -d to_upload ]
then
  mkdir to_upload
fi
 
POOL_ID="1234567@N89"
FLICKCURL="/home/roshan/progs/flickcurl/bin/flickcurl"
WATERMARK="/home/roshan/graphics/watermark.png"
 
for img in `ls *.tif | sort -r`
do 
  imgbase="${img/.tif/}"
  echo "Photo $imgbase"
  target="to_upload/${imgbase}.jpg"
  xmpfile="to_upload/${imgbase}.xmp"
  logfile="to_upload/${imgbase}.log"
  echo "  Watermarking"
  composite -gravity SouthWest "$WATERMARK" "$img" "$target"
  jhead -v "$target" 2> /dev/null | sed -n -e '/xmpmeta/,/xmpmeta/p' > "$xmpfile" 
  rating=`xmlstarlet sel -N xap="http://ns.adobe.com/xap/1.0/" -t -m "//xap:Rating" -v . $xmpfile`
  echo "  Rating: $rating"
  echo "  Uploading"
  $FLICKCURL upload "$target" public 2> "$logfile"
  PHOTO_ID=`sed -n -e '/Photo ID/{s/^.*: //;p}' "$logfile"`
  echo "  Uploaded as Photo ID $PHOTO_ID"
  if [ $rating -gt 3 ]
  then
    echo "  Adding $imgbase to pool"
    $FLICKCURL groups.pools.add $PHOTO_ID $POOL_ID 2> "$logfile.zrh"
  fi
done

I found that flickcurlutils 1.3 available through the Ubuntu Jaunty repositories would consistently segfault while trying to upload any photo which I wanted to mark public. The latest code (1.14) available on the flickcurl page doesn’t have this problem, so you might want to download and compile that yourself.

The script itself is relatively straightforward. It sets up a few constants (adjust to suit your system), creates a working directory, and then starts looping over all TIFF files in the current directory. For every TIFF file, it creates a watermarked JPG file, and extracts the XMP information that Lightroom has embedded in the image. The XMP file is an XML file, and among the information stored in it is the image rating which we get at using XMLStarlet. Upload the image, and depending on the rating given to the image, also add it to the pool.

It’s a relatively simple script, with no error-checking at all, but it does what I need.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
Loading Facebook Comments ...

Leave a Reply