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.

4 Responses to “Flickr uploading in progress”

  1. Brett Terpstra says:

    This is sweet, and I’m looking forward to playing with it. If you’re looking for a solid, full-featured GUI for Flickr, though, I recommend Flickery.

  2. TJ Luoma says:

    1. If you use ‘sips’ don’t use ‘deleteProperty’ — or, if you do, be sure to test it thoroughly. It caused problems for me (I can’t remember what, it was awhile ago, under Snow Leopard). Setting rotation to 0 worked (IIRC).

    2. The last time I test it (which was awhile ago), Flickr seemed to be smart enough to automatically rotate images using the EXIF orientation tag. So you may not need to worry about it, if Flickr is the only reason that you were worried about it.

    ps - I sent this via email because I didn’t scroll down far enough to notice the comments box. D’oh.

  3. Stuart Dootson says:

    iPhoto + Flickr? Sam answer as Aperture + Flickr for me - Connected Flow’s FlickrExport plug-in. They’re pretty much rock-solid, give you options to add to existing sets, create new sets, add to groups, set privacy…loadsa things.

  4. Dr. Drang says:

    Does this mean if I wait long enough you’ll have a complete solution coded up and I won’t have to do any more?

    Thanks for the tip on deleteProperty. As for rotation, photos that appear as portrait on my Mac (in Preview, for example, or Quick Look) and that I’ve uploaded through the Flickr web interface, the Flickr Uploadr application, and my little script have all showed up as landscape in my photostream. My plan is for my script to read the EXIF Orientation tag for each photo and send the appropriate rotation command to Flickr.

    I should have been more specific. My disgust with iPhoto is not limited to its Flickr sync problems and has become so overwhelming that I just don’t want to use it at all. No matter how good Fraser Speirs’ plugin is—and everyone says it’s excellent—the only reason I’ll launch iPhoto again is to get my photos out of it.