sylikc/pyexiftool

Specifying Latin encoding for filenames due to accents on folder names

Closed this issue · 2 comments

Hi there,
Firstly thanks for this wrapper. Exiftool is so powerful and combined with Python is even better. I am using it to rename my entire digital photo collection dating back 20 years.
The problem I have atm is that in a folder full of photos from France, I have some folder names that have accents on some letters. With the active page set to CHCP 65001 (utf8), when I run exiftool normally in the cmd prompt, I get funky characters in the directory name (which i'm using in the rename) and a filename encoding not specified warning.
image
When I specify the charset to be Latin, it works properly.
exiftool -charset filename=Latin "D:\Processing\Paris Adventures\Day 03\Église St-Etienne-du-Mont\IMG_9251.jpg"
image
So my question is, how do i implement that equivalent in the python code when reading the initial metadata.
with exiftool.ExifToolHelper() as et: print(et.get_metadata(r"D:\Processing\Paris Adventures\Day 03\Église St-Etienne-du-Mont\IMG_9252.jpg", "File:Directory"))
I have tried adding the 'encoding' option to the exiftool executable line
with exiftool.ExifToolHelper(encoding='Latin') as et: print(et.get_metadata(r"D:\Processing\Paris Adventures\Day 03\Église St-Etienne-du-Mont\IMG_9252.jpg"))
but when it runs the Directory still has the funky character in it and is not decoded. I'm terrible at interpreting API documentation, so I"m not sure what I'm doing wrong exactly.
Am I better off using the execute_json method so i can specify the 'charset' argument instead of the 'get_metadata' method (I'm self-taught python so my terminology could be incorrect)?
Any help would be greatly appreciated and apologies if this is not the right place for this question or if further information is required.
Thank you so much in advance.

Sian Doherty

So there's definitely something going on with filename encoding. Btw, PH's Exiftool has an FAQ on issues like this I'm having problems with special characters on the Windows command line . It's hard problems but good that you got your charset param working on the command line.

There is a 3rd parameter to get_metadata

your code should be

with exiftool.ExifToolHelper() as et:
	print(et.get_metadata(
		r"D:\Processing\Paris Adventures\Day 03\Église St-Etienne-du-Mont\IMG_9252.jpg",
		"File:Directory",
		params=["-charset", "filename=Latin"])
	)

I'm going to close this issue because it's inactive. I think it's fixed, but feel free to reopen if you are having further problems.