Friday, August 26, 2011

Mass download flickr albums

Is quite simple using the flickr API:

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import com.aetrion.flickr.Flickr;
import com.aetrion.flickr.REST;
import com.aetrion.flickr.photos.Photo;
import com.aetrion.flickr.photos.PhotoList;
import com.aetrion.flickr.photosets.PhotosetsInterface;

public class Backup {
    private Flickr flickr = null;

    public Backup() throws IOException, ParserConfigurationException {
        this.flickr = new Flickr("Put flickr api key here", "Put flickr api secret here", new REST());
    }

    public void doBackup(String photoSetId) throws Exception {
        PhotosetsInterface pi = flickr.getPhotosetsInterface();
        PhotoList pl = pi.getPhotos(photoSetId, 0, 0);
        for (Object po: pl) {
            Photo p = (Photo)po;
            System.out.println(p.getOriginalUrl());
        }
    }

    public static void main(String[] args) throws Exception {
        Backup bf = new Backup();
        bf.doBackup(args[0]);
    }
}

The above code will print the URLs of the original images in the album whose identifier you have to pass as command-line argument. And you'll need the flickrapi library for this. And you have to request a flickr API key+secret to have access to flickr's API (google on how to do this).

If you made this into a nice software, share it as a comment!

2 comments:

Wolfgang Nagele said...

Or you might just want to use FlickrEdit which supports this including to put the files into neat directory structures: http://sunkencity.org/flickredit

Ibi & Agoston said...

I've checked many applications, but all of them handled your own albums only. If you wanted to download somebody else's albums, you were on your own.