Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import flickrapi
- import urllib2
- from optparse import OptionParser
- import sys
- api_key = 'THISISANAPIKEY' #get your own!
- userID='00000000@N06' #This is a user ID, you'll want to use your own
- setID=''
- parser = OptionParser()
- parser.add_option ("-s","--setid",type="string",dest="setID",help="The Set ID for the set to download.")
- parser.add_option ("-S" , "--size", type="string", dest="photoSize",default="b",help="The size of photo you want to download. Size must fit the following: s - 75x75, q - 150x150, t - 100 on the longest side, m - 240 on the longest side, n - 320 on the longest side, z - 640 on the longest side, c - 800 on the longest side, \nb - 1024 on the longest side (default), o - original")
- (options, args) = parser.parse_args()
- setID = options.setID
- photoSize = options.photoSize
- if options.setID is None:
- print "You must specify a photo set to download. \nSee python-download -h for examples."
- sys.exit()
- flickr = flickrapi.FlickrAPI(api_key)
- photoSet = flickr.photosets_getPhotos(photoset_id=setID)
- photoSet = photoSet[0]
- def download( url ):
- file_name = url.split('/')[-1]
- u = urllib2.urlopen(url)
- f = open(file_name, 'wb')
- meta = u.info()
- file_size = int(meta.getheaders("Content-Length")[0])
- print "Downloading: %s Bytes: %s" % (file_name, file_size)
- file_size_dl = 0
- block_sz = 8192
- while True:
- buffer = u.read(block_sz)
- if not buffer:
- break
- file_size_dl += len(buffer)
- f.write(buffer)
- status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
- status = status + chr(8)*(len(status)+1)
- print status,
- f.close()
- return
- for photo in photoSet:
- photoID = photo.attrib['id']
- photoInfo = flickr.photos_getInfo(photo_id=photoID)
- photoInfo = photoInfo[0]
- secret=photoInfo.attrib['secret']
- oSecret=photoInfo.attrib['originalsecret']
- if photoSize == "o":
- download("http://farm%s.static.flickr.com/%s/%s_%s_o.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'],oSecret))
- else:
- download("http://farm%s.static.flickr.com/%s/%s_%s_%s.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'],secret,photoSize))
Add Comment
Please, Sign In to add comment