Last active
March 9, 2019 05:46
-
-
Save eviatarbach/a93df6ed597291a0a741 to your computer and use it in GitHub Desktop.
A Python script for downloading files from Flickr with EXIF metadata intact. This can already be done with images from Pro users who choose not to hide their original image; however, this will work for all others, downloading the largest image size possible. It has problems with photos that have numbered EXIF tags; this seems to be something Fli…
This file contains hidden or 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 urllib | |
| import os | |
| import argparse | |
| import flickrapi | |
| api_key = '367aed513876077c1cdcadb29d88ef02' | |
| api_secret = '9b6e223653519900' | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--auth', action='store_true') | |
| parser.add_argument('photos', nargs='+') | |
| args = parser.parse_args() | |
| flickr = flickrapi.FlickrAPI(api_key, api_secret) | |
| if args.__dict__['auth']: | |
| (token, frob) = flickr.get_token_part_one(perms='write') | |
| if not token: raw_input("Press ENTER after you authorized this program") | |
| flickr.get_token_part_two((token, frob)) | |
| for photo in args.__dict__['photos']: | |
| url = flickr.photos_getSizes(photo_id=photo).getiterator('size')[-1].attrib['source'] | |
| filename = '%s.'%photo + url.split('.')[-1].split('?')[0] | |
| urllib.urlretrieve(url, filename) | |
| tags = flickr.photos_getExif(photo_id=photo).getiterator('exif') | |
| with open('tags.xml', 'w') as tags_file: | |
| tags_file.write("<?xml version='1.0' encoding='UTF-8'?>\n<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n") | |
| for tag in tags: | |
| tags_file.write('<%s:%s>%s</%s:%s>\n'%(tag.attrib['tagspace'], tag.attrib['tag'], tag.getchildren()[0].text.strip().encode('utf-8'), tag.attrib['tagspace'], tag.attrib['tag'])) | |
| tags_file.write('</rdf:RDF>\n') | |
| os.system('exiftool -overwrite_original -tagsfromfile tags.xml %s'%filename) | |
| os.remove('tags.xml') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment