barasher / go-exiftool

Golang wrapper for Exiftool : extract as much metadata as possible (EXIF, ...) from files (pictures, pdf, office documents, ...)
GNU General Public License v3.0
250 stars 44 forks source link

Filename including Non-ASCII character isn't supported in Windows #65

Closed WindLi001 closed 1 year ago

WindLi001 commented 1 year ago

I try to use go-exiftool to get exif from the JPEG file in Windows environment.

When I call ExtractMetadata(), if the parameter files includes non-ASCII character, for example, fileInfos := et.ExtractMetadata("D:\\测试数据\\IMG_20220102_202220.jpg") the calling is failed, with the error message like

failed: failed to parse exif data: error during unmarshaling (Error: File not found - D:/测试数据/IMG_20220102_202220.jpg
): invalid character 'E' looking for beginning of value)

But if the parameter files includes only ASCII character, for example, fileInfos := et.ExtractMetadata("D:\\test-data\\IMG_20220102_202220.jpg") everything is OK.

And I found this page [https://exiftool.org/exiftool_pod.html#WINDOWS-UNICODE-FILE-NAMES] in exiftool documentation. So, I think maybe go-exiftool should add the option -charset filename=utf8 to solve the problem.

I try to change the code of go-exiftool. In detail, I change var initArgs = []string{"-stay_open", "True", "-@", "-"} to var initArgs = []string{"-charset", "filename=utf8", "-stay_open", "True", "-@", "-"} And it's really worked in Windows. But I'm not sure if it has side effect in other OS. I'll create a pull request soon.

barasher commented 1 year ago

Hi @WindLi001

First of all, thanks for the issue and the PR ! As you told, setting by default a specific charset might introduce side effects on go-exiftool clients and I don't want to risk that.

I had already introduced an option to specify a charset when initializing go-exiftool: Charset.

You should initialize go-exiftool that way:

e, err := NewExiftool(Charset("filename=utf8"))

I'll close the issue but re-open if if my hint does not fix your problem.

WindLi001 commented 1 year ago

Thank you for your reply. I should read the document before raising this issue.

I change my code to

    et, err := exiftool.NewExiftool(exiftool.Charset("filename=utf8"))
    fileInfos := et.ExtractMetadata("D:\\测试数据\\IMG_20220102_202220.jpg")

, and it's worked.