Created
April 17, 2020 03:15
-
-
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
This file contains 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
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