>>2028
Oh, boy.
#!/usr/bin/env python2
import os
import subprocess
import sys
import json
import random
import sets
import logging
import traceback
TAGS = ['XPKeywords', 'Keywords', 'Subject', 'LastKeywordIPTC', 'LastKeywordXMP']
def main():
print("Script start in \"%s\"." % os.getcwd())
os.chdir(os.path.dirname(os.path.realpath(__file__)))
print("Change working directory to \"%s\"." % os.getcwd())
logging.basicConfig(filename="rename.log", level=logging.DEBUG)
logger = logging.getLogger('rename')
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(message)s'))
logger.addHandler(ch)
logger.info("Starting...")
if len(sys.argv) < 2:
raise Exception("Need a valid argument.")
raw = subprocess.check_output(['exiftool', '-j', '-r', sys.argv[1]])
if not raw or len(raw) <= 0:
raise Exception("exiftool didn't return anything?")
data = json.loads(raw)
for img in data:
source = img['SourceFile']
name = "%s;%%s.%s" % (os.path.splitext(os.path.basename(source))[0], img['FileTypeExtension'])
file_tags = sets.Set()
for tag in TAGS:
if tag in img:
if isinstance(img[tag], basestring):
file_tags.update(img[tag].split(';'))
else:
file_tags.update(img[tag])
name = name % ';'.join(file_tags)
logger.info("Renaming \"%s\" to \"%s\"" % (img['FileName'], name))
os.rename(source, img['Directory'] + os.sep + name)
logger.info("Ended.")
if __name__ == "__main__":
try:
main()
except:
print(traceback.format_exc())
raw_input()
I hope you have python2 installed, and I would be careful with this as I wrote it fairly fast with not a lot of sanity checks. If you do have python2 installed it should work in a similar way as the batch scripts, as long as it has exiftool in the same directory or in windows PATH with it you can drag an image or folder onto it and it *should* rename every file to `<filename>;<tag;>.<ext>`. Save it as `whatever.py` or whatever.
This doesn't scrub any tags so you'll just have to run the scrubbing scripts afterwards.
I would post this as a "compiled" exe but that'd be shady as fuck and kinda dumb as it relies on exiftool.
I didn't realize how handy exiftool is until after writing this it provides a `-j` flag for json output which is way nice and even reads file formats other than jpeg/jfif.
Good luck!~