Created
August 18, 2010 23:13
-
-
Save eikes/536497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Python script for downloading all images from dropbox a gallery into a folder. | |
# use it like this: | |
# python dropbox_gallery_downloader.py https://www.dropbox.com/gallery/3104986/1//Processing?h=ea3455&p=0 | |
import urllib, urllib2, re, os, json, sys | |
if (len(sys.argv) == 1): | |
print "Please provide the dropbox gallery URL as a command line argument. \nA sceond argument may be provided for a folder name, if none is given the dropbox name will be used." | |
exit() | |
# first determine directory name, create it and change into it | |
url = sys.argv[1] | |
if (len(sys.argv) == 3): | |
dir = sys.argv[2] | |
else: | |
dir = re.search("/([^/]*)\?",url).group(1) | |
dir = urllib.unquote(dir) | |
if (not os.path.isdir(dir)): | |
os.mkdir(dir) | |
os.chdir(dir) | |
# second read dropbox gallery html, find photos-array JavaScript, use it as json and download. | |
html = urllib2.urlopen(url).read() | |
photos = re.findall("photos.push\(([^\)]*)\)", html, re.S) | |
for p in photos: | |
p = p.replace("'",'"') | |
photo = json.loads(p) | |
print "downloading: " + photo["filename"] | |
urllib.urlretrieve(photo["original"], photo["filename"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment