Created
September 16, 2015 10:15
-
-
Save saucecode/7b23ab136d45a1c957af to your computer and use it in GitHub Desktop.
This file contains 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
import urllib2, json, os, time | |
albumurl = raw_input('imgur album url: ') | |
foldername = albumurl.split('/')[-1].split('#')[0] | |
if not os.path.exists(foldername+'/'): os.mkdir(foldername+'/') | |
print 'downloading html...' | |
albumhtml = urllib2.urlopen(albumurl).read() | |
jdata = '{"count":'+albumhtml.split("{\"count\":")[1].split('\n')[0][:-1] | |
data = json.loads(jdata) | |
print 'going to download',len(data['items']),'images into folder:',foldername | |
for i in data['items']: | |
fname = i['hash']+i['ext'] | |
if os.path.exists(foldername+'/'+fname): | |
print fname,'exists - skipping...' | |
continue | |
print 'downloading',fname | |
while 1: | |
try: | |
with open(foldername+'/'+fname,'wb') as f: | |
f.write(urllib2.urlopen('http://i.imgur.com/'+fname).read()) | |
break | |
except: | |
print 'failed to get',fname,'- retrying in 3...' | |
time.sleep(3) | |
raw_input('Download complete.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment