Skip to content

Instantly share code, notes, and snippets.

@terrettaz
Last active December 8, 2019 20:15
Show Gist options
  • Save terrettaz/74a80e0cf0353136a37c4cf2205abfae to your computer and use it in GitHub Desktop.
Save terrettaz/74a80e0cf0353136a37c4cf2205abfae to your computer and use it in GitHub Desktop.
JPEG Keywords
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
__version__ = "$Revision: 0.1 $"
__author__ = "Pierrick Terrettaz"
__date__ = "2007-08-15"
import argparse, subprocess
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='JPEG Keywords')
parser.add_argument('-k', '--keywords', dest='keywords', metavar='K', nargs='+', help='Keyword list')
parser.add_argument('-R', '--recursive', dest='recursive', action='store_true', help='Recursive')
parser.add_argument('-a', '--append', dest='append', action='store_true', help='Append to existing keywords')
parser.add_argument('-r', '--remove', dest='remove', action='store_true', help='Remove from existing keywords')
parser.add_argument('-d', '--drop', dest='drop', action='store_true', help='Drop all existing keywords')
parser.add_argument('file', action='store', help='file or directory')
args = parser.parse_args()
exiftool = [
'exiftool',
'-sep', ",",
'-P',
'-overwrite_original_in_place']
if args.recursive:
exiftool.append('-r')
if args.drop:
exiftool.append('-Keywords=')
elif not args.keywords:
exiftool.append('-Keywords')
elif args.remove:
exiftool.append('-Keywords-=%s' % ','.join(args.keywords))
elif args.append:
exiftool.append('-Keywords+=%s' % ','.join(args.keywords))
else:
exiftool.append('-Keywords=%s' % ','.join(args.keywords))
exiftool.append(args.file)
subprocess.call(exiftool)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment