Coredump

Work, play, and everything in-between.

Downloading Flickr photos

with 2 comments

Flickr leech

Flickr Leech is a cool web app. It displays all Flickr photos, including those already rendered invisible because of the 200-photo limit in free accounts. But I need more: I want to download these photos for backup.

After looking around, I found several tools that does the job. They didn’t quite work for me, so I decided to hack my own.

Using the Flickr API and a Python wrapper, I came up with the following:

  1. Get flickr.py and manually add it to the host Python library.
  2. Get an API key from Flickr.
  3. Write the script:
    #!/usr/bin/python
     
    import flickr
    import urllib
     
    flickr.API_KEY = 'API key goes here'
    user = flickr.people_findByUsername(u'username')
    photos = flickr.people_getPublicPhotos(user.id, 500)
    total = 0
    for photo in photos:
       photoURL = "http://static.flickr.com/%s/%s_%s_o.jpg" % (photo.server, photo.id, photo.secret)
       photoFile = "%s_%s.jpg" % (photo.title, photo.id)
       data = urllib.urlretrieve(photoURL, photoFile)
       total = total + 1
       print "Downloading %s" % photoFile
    print "Done with %s photos." % total
  4. Make the script executable, create a directory where to download files, and execute the script from there.
  5. Rinse, dry, press.

I know, the script is very rudimentary. It’s my first Python script, and it needs a lot of work: there’s no exception-handling for one. But it worked perfectly for me.

Read more:

Written by Ian Dexter

March 21st, 2007 at 2:33 pm

Posted in Play

Tagged with , , , , ,

2 Responses to 'Downloading Flickr photos'

Subscribe to comments with RSS or TrackBack to 'Downloading Flickr photos'.

  1. Are you sure you can retrieve pass the 200 limit? I’ve tried the flickr api explorer and setting the per_page into 500. But the result came up always have “total=200″. Am I missing the essential trick here? :(

    Akhmad Fathonih

    22 Mar 08 at 7:54

  2. Back then, I was able to do that. Unfortunately, yes, you won’t be able to get past the 200-photo limit. I guess they have set this as a hard limit now.

    Ian Dexter

    30 Mar 08 at 12:38

Leave a Reply