Skip to content

Instantly share code, notes, and snippets.

@derekphilipau
Created April 17, 2020 03:15
Show Gist options
  • Save derekphilipau/238881f419f474a9ac0e3af98cbd405f to your computer and use it in GitHub Desktop.
Save derekphilipau/238881f419f474a9ac0e3af98cbd405f to your computer and use it in GitHub Desktop.
just a small hack to rename a file based on its iptc caption
from PIL import Image, IptcImagePlugin
import os
from urllib.parse import urlparse
path1 = "./out/"
listing = os.listdir(path1)
for file in listing:
im = Image.open(path1 + file)
iptc = IptcImagePlugin.getiptcinfo(im)
if iptc:
caption = iptc.get((2,105)).decode()
if caption:
print(caption)
domain = urlparse(caption).netloc
if domain:
print(domain)
os.rename(path1 + file, path1 + domain + "_" + file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment