Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python, GExiv2, and unicode file names #7167

Closed
jim-easterbrook opened this issue Oct 24, 2020 · 5 comments · Fixed by #7303
Closed

Python, GExiv2, and unicode file names #7167

jim-easterbrook opened this issue Oct 24, 2020 · 5 comments · Fixed by #7303

Comments

@jim-easterbrook
Copy link

I've run into a problem using GExiv2 from Python and I'm not sure exactly where the problem lies. A short script shows the problem:

import sys

import gi
gi.require_version('GExiv2', '0.10')
from gi.repository import GExiv2

def main():
    print('GExiv2 version', GExiv2.MAJOR_VERSION, GExiv2.MINOR_VERSION,
          GExiv2.MICRO_VERSION)
    for path in sys.argv[1:]:
        print(path)
        md = GExiv2.Metadata()
        md.open_path(path)
        print(md.get_exif_tags())
    return 0

if __name__ == "__main__":
    sys.exit(main())

When run on a non-ascii file name this happens:

$ python gexiv2_test.py /c/Users/Jim/Pictures/fünny_name.JPG
GExiv2 version 0 12 1
C:/Users/Jim/Pictures/fünny_name.JPG
Traceback (most recent call last):
  File "gexiv2_test.py", line 20, in <module>
    sys.exit(main())
  File "gexiv2_test.py", line 15, in main
    md.open_path(path)
  File "C:/msys64/mingw64/lib/python3.8/site-packages/gi/overrides/GExiv2.py", line 44, in open_path
    super(Metadata, self).open_path(path)
gi.repository.GLib.Error: GExiv2: C:/Users/Jim/Pictures/fünny_name.JPG: Failed to open the data source: No such file or directory (errno = 2) (9)

Exiv2 opens the file without a problem:

$ exiv2 -pa /c/Users/Jim/Pictures/fünny_name.JPG
Error: Directory Canon with 6144 entries considered invalid; not read.
Exif.Image.ProcessingSoftware                Ascii      26  Photini editor v2020.10.0
Exif.Image.ImageDescription                  Ascii      78  Château-Gontier, France
Exif.Image.Make                              Ascii       6  Canon
Exif.Image.Model                             Ascii      25  Canon PowerShot A1100 IS
Exif.Image.Orientation                       Short       1  top, left
...

I've seen that #2837 fixes exiv2. Does gexiv2 need fixing?

@lazka
Copy link
Member

lazka commented Oct 24, 2020

From what I see exiv2 exposes extra unicode API using wstring when built with EXV_UNICODE_PATH. gexiv currently passes the paths using the glib path encoding (utf-8 on Windows) to the ANSI API which is wrong, and just happens to work with ASCII.

gexiv2 needs to convert paths from utf-8 to utf-16-le, then to wstring, and then pass it to the exiv unicode API. So yes, this needs work with gexiv2. I'd suggest filing a bug there.

@jim-easterbrook
Copy link
Author

I've found this GLib bug which appears to be related to the problem https://bugzilla.gnome.org/show_bug.cgi?id=795006. It's marked "resolved obsolete" though, as they expect to use streams rather than files in future. The Python interface to GExiv2 has a method to read from a stream but not to write to one.

@lazka
Copy link
Member

lazka commented Oct 24, 2020

yeah, LRN more or less comes to the same conclusion there.

@jim-easterbrook
Copy link
Author

Bug filed with GExiv2: https://gitlab.gnome.org/GNOME/gexiv2/-/issues/59

@lazka
Copy link
Member

lazka commented Oct 24, 2020

Thanks

lazka added a commit to lazka/MINGW-packages that referenced this issue Nov 20, 2020
umarcor pushed a commit to umarcor/MINGW-packages that referenced this issue Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants