Flickr uploading in progress

I wrote a short, crude, and thoroughly incomplete script today to upload photos to Flickr. I’ll try to turn it into something more useful over the next few weeks, but I figured I’d go ahead and post it in its larval state. With almost no features, it’s easy to read and understand.

I wrote the script because I had taken a bunch of photos this weekend, and

  1. I decided several weeks ago, for reasons I may explain in a later post, that I would never ever use iPhoto’s awful Flickr uploader again.
  2. There were too many photos to use Flickr’s web-based uploading tool.
  3. The Flickr Uploadr application crapped out in the middle of a batch upload, and I didn’t feel like fighting with it.

You might think that writing a script to do the uploading was an extreme reaction and more trouble than simply looking around for another uploader utility. But I had already written a script that uploaded images to Flickr (described here and here, and kept in this GitHub repository), and I knew that most of the work in “writing” a new script would consist of stripping out the unneeded parts of the old one.

Here’s source code of the bare-bones uploader, called up2flickr:

 1:  #!/usr/bin/python
 3:  from flickrapi import FlickrAPI
 4:  import sys
 6:  # Flickr parameters
 7:  fuser = 'user name'
 8:  key = 'get key and secret from the Flickr App Garden'
 9:  secret = 'at'
11:  # Upload the files on the command line.
12:  flickr = FlickrAPI(api_key=key, secret=secret)
14:  for fn in sys.argv[1:]:
15:    print "Uploading %s..." % fn
16:    response = flickr.upload(filename=fn, title=fn,\
17:              is_public=0, format='etree')
18:    photoID = response.find('photoid').text
19:    photoURL = '' % (fuser, photoID)
20:    print "  -> %s" % photoID

It uses Sybren Stüvel’s FlickrAPI library to do the real work in Line 16. The rest is just a bit of authorization code in Lines 7-9 (which I described how to set up in this post) and a simple loop to get the local filenames off the command line and give feedback as the upload progresses.

The typical use I envision for up2flickr is to cd to a directory with photos I want to upload and issue a command like this:

up2flickr *.jpg

While up2flickr works fine right now, what I really want to be able to do is create new photo sets, add to old sets, set permissions, etc. These functions should be easy to add, because they’re just additional parameters to the upload function in Line 16. More difficult will be rotating photos according to the EXIF orientation tag; I don’t know whether that’s best done through the Python Imaging Library or Apple’s sips command.

Update 10/10/11
For reasons I cannot explain, I didn’t have the “Auto-rotate your photos” setting turned on in my Flickr account settings. Maybe because it’s on the Privacy & Permissions page, which seems like an odd place to put it. Frankly, it’s weird that Flickr doesn’t have this setting turned on by default.

However it turns out, I’m looking forward to a time when I can upload a big set of photos with just a short command or two instead of launching a slow and buggy GUI program.