Skip to content

Instantly share code, notes, and snippets.

@brandongalbraith
Forked from zmwangx/fr-set-down.py
Created February 20, 2018 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandongalbraith/6116c519a7381b420391df23980ff92c to your computer and use it in GitHub Desktop.
Save brandongalbraith/6116c519a7381b420391df23980ff92c to your computer and use it in GitHub Desktop.
Python script to download entire photosets (original quality) on Flickr. #flickr
#!/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