Skip to Content »

Tech Life of Recht » SmugMug uploader

 SmugMug uploader

  • October 3rd, 2007
  • 12:10 am

Some time ago I bought an account with SmugMug for my pictures. SmugMug is pretty nice, and has more or less the features I need.
I quickly ran into a problem with uploading a lot of pictures. There are different tools for it, but nothing which really fit my needs: Execute a script with a list of files as arguments, print a list of available albums, enter the correct album, and upload the images (with a progress meter).
Luckily, there's the SmugMug API, which is a nice REST interface, and it didn't take long to hack a shell-script together using curl and the other usual suspects like grep and sed. I've now polished the script a little so it does some error handling, so now it's available here as smugup.sh. It requires curl, sed and grep, probably in the GNU versions.

Username and password can be set as arguments with -u and -p, but they can also be set in ~/.smugup like this:

CODE:
  1. EMAIL="recht@somewhere"
  2. PASSWORD="passhere"

The script is used by simply giving the pictures to be uploaded as argument to the command:

CODE:
  1. smugup.sh /data/pictures/*.jpg

The script will then print a list of available albums and expect the selected album ID as input, and then it will begin uploading.

11 People had this to say...

Gravatar
  • Mark
  • October 15th, 2007
  • 10:51 pm

Trying to use your script to upload a bunch of images that were in gallery2. Not getting far. Here are the steps I tried…

1) sh smugup.sh -u [email] -p [pass] *.jpg

It came back with the response that no password was given.

Hard coded my email and password in the script (lines 13 & 16).

2) sh smugup.sh *.jpg

Same response. Password not given.

Removed the test statements.

3) sh smugup.sh *.jpg

Received “unable to login”.

Any idea(s)?

TIA!

Gravatar
  • recht
  • October 16th, 2007
  • 6:31 pm

First of all, what are you running the script on? Are you using bash as your shell?

Gravatar
  • Mark
  • October 17th, 2007
  • 4:26 pm

Yes I am. I’m trying to use your script to upload photos from my gallery2 website to smugmug. By running the script on the web server, I can use the server’s higher bandwidth to push it to smugmug. I know enough to make me dangerous. =) I am using GNU bash (redhat linux).

Gravatar
  • Gary
  • October 18th, 2007
  • 3:21 pm

Recht and Mark,

I tried using the script today for the first time (Mac OS X), and also got the “unable to login” message. I added the -v verbose option to curl as well as on the script itself. It turned up some error relating to the certificate. The bottom line is that by adding the -k option (don’t verify certificate) to curl, the script runs fine and uploaded a photo. Of course I would like to let curl authenticate the certificate (sans -k option), so have you any idea how to fix??? The error message follows. Thanks.

* About to connect() to api.smugmug.com port 443
* Trying 63.81.134.23… * connected
* Connected to api.smugmug.com (63.81.134.23) port 443
* successfully set certificate verify locations:
* CAfile: /usr/share/curl/curl-ca-bundle.crt
CApath: none
* SSL connection using DES-CBC3-SHA
* Server certificate:
* subject: /C=US/postalCode=94043/ST=California/L=Mountain View/streetAddress=248 Walker Drive, #8/O=modgods, inc./OU=web services/OU=Comodo PremiumSSL Wildcard/CN=*.smugmug.com
* start date: 2006-09-08 00:00:00 GMT
* expire date: 2009-10-13 23:59:59 GMT
* common name: *.smugmug.com (matched)
* issuer: /C=US/ST=UT/L=Salt Lake City/O=The USERTRUST Network/OU=http://www.usertrust.com/CN=UTN-USERFirst-Hardware
* SSL certificate verify result: error number 1 (20), continuing anyway.

Gravatar
  • recht
  • October 18th, 2007
  • 7:41 pm

You need to add the root certificate to your ca-bundle. I think the relevant certificate is here: http://www.positivessl.com/ssl-certificate-support/cert_installation/UTN-USERFirst-Hardware.crt

Gravatar
  • Bala
  • October 29th, 2007
  • 3:06 pm

Hi,

Thanks!! This is a great script.. I have been thinking about writing one for a long time, but was lazy..

I was able to upload my photos after changing the first line from /bin/sh to /bin/bash

this worked on a clean (un-customized) install of ubuntu gutsy 7.10

Bala

Gravatar

I’ve modified your script to download instead of upload. Useful to make a backup of your site.

Gravatar
  • Georges
  • January 2nd, 2008
  • 7:20 pm

@ Jesse DeFer

How did you do that? I am interested. Thanks.

Gravatar
  • Andreas Jaeger
  • February 9th, 2008
  • 6:30 pm

Thanks for a really usefull skript.

I just noticed today that after the changes for keys (see
http://blogs.smugmug.com/don/2008/02/08/big-privacy-changes-at-smugmug/, the script does not work anymore.

I added an extra “N” to the sed command that outputs the Album IDs to make it work. But I fear it will not work with new galleries that require keys.

Andreas

[...] 11:35 pm I got a comment that my SmugMug uploader script had broken after the last upgrade. It turned out that my XML parsing with sed wasn’t exactly resistant to change, so the wrong field was printed from the returned XML. I’ve changed the XML parsing to use awk instead, hopefully in a way that’s a little more resistant to changes in the format (although it’s not exactly perfect, but I don’t want to involve a real XML parser). The new version is 1.1, and can be downloaded here. [...]

Gravatar
  • recht
  • February 10th, 2008
  • 11:36 pm

Thanks, Andreas, I’ve created a new version which fixes the problem. The new version can be found at http://braindump.dk/tech/2008/02/10/updated-smugupsh-script/

Want your say?

* Required fields. Your e-mail address will not be published on this site

You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>