-
-
Save meta-ks/9c22ed350c546f1aa885a7eca544919d to your computer and use it in GitHub Desktop.
Python script to download entire photosets (original quality) on Flickr. #flickr
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
#!/usr/bin/env python | |
import subprocess | |
import sys | |
# pip install flickrapi | |
# project home: http://stuvel.eu/flickrapi | |
import flickrapi | |
api_key = '00000000000000000000000000000000' # obtain your api key at http://www.flickr.com/services | |
fr = flickrapi.FlickrAPI(api_key) | |
photoset_id = sys.argv[1] | |
photoset = fr.photosets_getInfo(photoset_id=photoset_id).find('photoset') | |
owner_nsid = photoset.attrib['owner'] | |
count = photoset.attrib['photos'] | |
index_len = len(count) | |
print '%s photos in total' % count | |
processes = [] | |
counter = 0 | |
for photo in fr.walk_set(photoset_id): | |
counter += 1 | |
label = 'flickr.com_' + owner_nsid + '-' + photoset_id + '-' + str(counter).zfill(index_len) | |
photo_id = photo.get('id') | |
sizes = fr.photos_getSizes(photo_id=photo_id) | |
photo_uri = sizes.find('sizes').findall('size')[-1].attrib['source'] # 'Original' is alwasy the last size | |
extension = photo_uri.split('.')[-1] | |
filename = label + '.' + extension | |
print 'wget -q %s -O %s' % (photo_uri, filename) | |
processes.append(subprocess.Popen(['wget', '-q', photo_uri, '-O', filename])) | |
returncode = 0 | |
for i in range(0, counter): | |
p = processes[i] | |
if p.wait() != 0: | |
returncode = 1 | |
label = str(i + 1).zfill(index_len) | |
print 'fr-set-down error: download # %s failed' % label | |
exit(returncode) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment