user19992089
user19992089

Reputation:

Change file description with python

I'm looking for a solution to adjust the file information "Tags", "Comments" with python. Example:

Example

There are over 3000 files in different files types like 'TIF', 'jpg', 'tif', 'JPG', 'JPEG', 'tiff', 'mp4', 'mov', 'MOV', 'wmv', 'MP4','xlsx', 'docx', 'doc', 'DOC', 'pptx' I have to change.

I can access the image data with the "exif" package, but I can't edit tags and comments. Is there a known package with which I can set this data.

Upvotes: 1

Views: 548

Answers (1)

Mariusz Malek
Mariusz Malek

Reputation: 112

You can start with this module: https://pypi.org/project/IPTCInfo3/

import iptcinfo3, os, sys, random, string

# Random string gennerator
rnd = lambda length=3 : ''.join(random.choices(list(string.ascii_letters), k=length))
# Path to the file, open a IPTCInfo object
path = os.path.join(sys.path[0], 'DSC_7960.jpg')
info = iptcinfo3.IPTCInfo(path)
# Show the keywords
print(info['keywords'])
# Add a keyword and save
info['keywords'] = [rnd()]
info.save()
# Remove the weird ghost file created after saving
os.remove(path + '~')

Upvotes: 1

Related Questions