Uploadr.py: Send a folder’s photos to Flickr via the command line

I'm trying to learn some more command line stuff lately, mostly because I think it makes me look badass -- in much the same way as smoking or bear claws makes one look badass. After the recent announcement of GoogleCL that allows you to do a bunch of Google-related stuff on the command line, I found this explanation on Lifehacker of how to upload a folder of photos to Picasa.

 

While Picasa looks nice, I didn't think the storage upgrade options are as good as Flickr's unlimited storage with a pro account which I'm planning to buy instead. 

So I set out to see if anyone had figured out a way to upload a folder full o' fotos to Flickr using the command line. That brought me to this 2007 Lifehacker article about a python script called 'Uploadr'. Some deeper digging brought me to a more recent version on Github from Martin Kleppmann. This is the one that worked for me.

I proceeded to pick through the instructions of the afore-mentioned resources, both of which are not entirely straightforward if you're not so technically minded. So I'll try to summarize here below in plain English.

Step 1: Drop the uploader.py and XMLtramp.py files (from Kleppmann's repository) into a folder of your choice. I like to drag a shortcut to this folder to the top of my Mac's Finder window for quick access.

Wicked handy tip: Now rather than just send one folder's photos to Flickr, I thought I'd actually set up one folder for public images and one for private images. If you'd like to control whether images are public or private, you can perform this sequence once for each folder.

Step2: Using your favorite text editor, specify the image directory and fill out the Flickr settings. Below are the settings that I filled out for my public folder. If you're not sure of yours, just drag that folder into Terminal (assuming you're on a Mac). Note that if you want photos kept private, fill in a '0' after 'is public'. Multiple tags can be added with commas.

 Step 3: Get a Flickr API key and input it just below the "You shouldn't need to modify anything below here" line. Yes, really... And follow the syntax you see below too, because the syntax in the original file didn't fly for me. I've redacted my key, because I really wanted to use the word 'redacted' in a sentence...

Step 4: From the command line, run uploadr.py. If you're using terminal, just navigate to the folder you specified (using 'cd' to change directories) and type 'python uploadr.py'. Windows users see Lifehacker for steps. This step will launch Flickr in the browser prompting you to give uploadr.py access to your account. Go ahead and grant it. When you run uploadr.py the next time, any photos that you have in that folder will be uploaded to Flickr automatically.

Bonus Step 5: Create an Applescript to run uploadr.py in terminal. Lifehacker mentioned something about an Applescript in their article, but the link was unfortunately dead. So I whipped up the following Applescript that I can access from my menubar.

tell application "Terminal" do script "python /Users/rickmartin/Pictures/FlickrPublic/uploadr.py" end tell

You can copy it and throw it into the AppleScript Editor, save it to the Scripts folder (perhaps under a new 'Flickr' subfolder?) and run it from the menu bar whenever you've added new photos. Be sure to replace my file path with your own. As you can see below, I made two scripts: one to trigger uploads from my public folder and one for my private folder. I'm not sure if all these steps are the best way to pull this off, so if anyone has suggested improvements drop me a line in the comments. I did get a "DeprecationWarning: the md5 module is deprecated; use hashlib instead" warning, but nothing 'sploded so I'm ok.

Update: Takaaki asks "Can you make it automatic using a folder action? http://bit.ly/aMXFa3". This is something I'll definitely have to check out. It certainly seems like an improvement on the Applescript.

Related reading: Unix command cheat sheet

Comments

new life for uploadr script

Here is a tool that is being actively developed that uses uploadr script. 

I set it up as a cron job and every night my pictures are synced with flickr and organized in sets autamatically.

You may like this too...

http://code.google.com/p/folders2flickr/

Found a solution to my

Found a solution to my earlier comment about having each image with seperate title, descriptions, and tags. My goal was to have this script run after each image is downloaded/inserted into the directory and not as a daemon.

Anyway, not a python programmer but the following changes work. Also the script was missing a few lines which added the titles and descriptions.

Lines 44-49 , change this:

<b>FLICKR = {"title": "",
        "description": "",
        "tags": "auto-upload",
        "is_public": "1",
        "is_friend": "0",
        "is_family": "0" }</b>

to this:

<b>FLICKR = {"title": sys.argv[1],
        "description": sys.argv[2],
        "tags": sys.argv[3],
        "is_public": "1",
        "is_friend": "0",
        "is_family": "0" }</b>

Lines 295-300 change this:

<b>d = {
                    api.token : str(self.token),
                    api.perms : str(self.perms),
                    "tags" : str( FLICKR["tags"] ),
                    "is_public" : str( FLICKR["is_public"] ),
                    "is_friend" : str( FLICKR["is_friend"] ),
                    "is_family" : str( FLICKR["is_family"] )
                }</b>

to this:

<b>d = {
                    api.token   : str(self.token),
                    api.perms   : str(self.perms),
            "title"      : str( FLICKR["title"] ),
            "description":  str( FLICKR["description"] ),
                    "tags"      : str( FLICKR["tags"] ),
                    "is_public" : str( FLICKR["is_public"] ),
                    "is_friend" : str( FLICKR["is_friend"] ),
                    "is_family" : str( FLICKR["is_family"] )
                }</b>

Example Usage:  python uploadr.py "New Title" "This is the new description" "test1,test2,test3"

Run once script:

wget -P images/ <HTTP PATH TO IMAGE>
python uploadr.py <Title> <Desc> <Tags>

Thanks again.

THANK YOU for this. Wish

THANK YOU for this. Wish there was a way to individually tags each uploaded picture but other then that it's perfect for my needs.