Here's a tiny python script for downloading Picassa photo albums!
It requires two parameters: the album's RSS URL (there's
a link to this at the bottom of each album page) and the pathname
of the directory where the downloaded photos will be stored.
Enjoy :-)
It requires two parameters: the album's RSS URL (there's
a link to this at the bottom of each album page) and the pathname
of the directory where the downloaded photos will be stored.
Enjoy :-)
#!/usr/bin/env python
import urllib
import feedparser
import sys
import os
if len(sys.argv) != 3 :
print >> sys.stderr, (("usage: %s " +
"<picassa-album-rss> <local-dir>") % sys.argv[0])
sys.exit(1)
album_rss = sys.argv[1]
local_dir = sys.argv[2]
if not os.access(local_dir, os.W_OK | os.X_OK):
print >> sys.stderr , ("error: dir %s is not writable" %
local_dir)
sys.exit(1)
abs_dir = os.path.realpath(local_dir)
feed = feedparser.parse(album_rss)
total_items = len(feed.entries)
if total_items == 0:
print >> sys.stderr , ("error parsing url %s" % album_rss)
sys.exit(1)
for i in range(total_items):
# of course this breaks once Picassa change their rss format..
website = feed.entries[i]["enclosures"][0]["href"]
slash_pos = website.rindex("/")
pic_name = website[slash_pos+1:]
urllib.urlretrieve(website, "%s%s%s" % (abs_dir, os.path.sep,
pic_name))
print "downloaded: %s (%i/%i)" % (pic_name, i+1, total_items)
No comments:
Post a Comment