It is sometimes useful to download all photos from a group pool in one fell swoop. Rather than clicking through all the photos by hand in a web browser, we can use the Flickr API to grab the photos quickly. Using the flickrapi
python package, this looks something like the following:
#
# flickr_groupdump.py
# Download photos from the Flickr group pool in bulk
#
# Created by Jakob van Santen on 2008-09-07.
#
import flickrapi, os, re, urllib
# api key and secret
api_key = 'your api key'
api_secret = 'your api key secret'
flickr_username = 'your flickr (yahoo) username'
# the url of the group pool to be dumped
group_url = 'http://www.flickr.com/groups/876344@N22/pool/'
# initialize and get authentication token
flickr =
(token,frob) = (token, frob) =
if not token:
# look up the group
group =
group_id =
group_name = . .text
# get all the photos in the pool
page = 1
pages = page+1
group_list =
while page <= pages:
photos =
page =
pages =
print 'Got page', page, 'of', pages
page += 1
photolist = .photo
group_list +=
# classify the photo list by user
owners =
for photo in group_list:
o =
if :
.
else:
=
# for each user who uploaded photos to the pool:
for owner_name in :
.
target =
try:
except:
None
# dump every photo in the pool to a file
for index,photo in :
existing_fname =
if existing_fname == : #photo doesn't yet exist, so download it
sizes =
biggest = . .attrib
url =
format = .
fname = group_name + '/' + owner_name + '/' + '%s %s (%s).%s' % ( , ,owner_name,format)
if block_count == 0:
reporter.datasize = total_size
print , 'downloaded', '%.3f MB' % (reporter.datasize/2.0**20)
else: # rename the file for giggles
new_fname =
print , 'exists'
You’ll need to get your own API key from flickr and insert it at the top of the script. Next, paste in the URL of the group photo pool. On the first run, you’ll have to authorize the key to access your flickr account if you haven’t already done so.
The script looks up the group based on its URL and builds a list of all photos in the pool. Then, it classifies the photos by owner. For each photo, the script fetches the largest available size and downloads it. Photos from each user are put in a different subfolder. The file name for each photo includes the photo ID from flickr, so if the photo already exists, it is skipped. If you run the script multiple times, it will only fetch the newly-added photos from the group pool.
The photo-gathering section can easily be modified to download photos from a particular user or set instead of a group.
No comments:
Post a Comment