Alexandre Rossi wrote:
Hi,



Okay all is good now, I can build an album with all your pictures.
This is fixed for the next version.
Thanks. I tried the darcs version and it works.
But there a problem for IMG_0870_exiftool_usercomment_unicode.JPG : the exif is in big endian format. And it this case it seems it is UTF-16BE that should be used.

Also the .strip('\0') is finaly not correct : it is what eat the Traling zero for UTF-16LE. I attach a posible fix.


Matthieu

diff -rN -u old-lazygal/lazygal/metadata.py new-lazygal/lazygal/metadata.py
--- old-lazygal/lazygal/metadata.py	2008-06-17 23:27:47.000000000 +0200
+++ new-lazygal/lazygal/metadata.py	2008-06-17 23:27:47.000000000 +0200
@@ -148,7 +148,7 @@
         is not found.
         '''
         try:
-            return str(self[name]).strip('\0')
+            return str(self[name])
         except (IndexError, ValueError, KeyError):
             return ''
 
@@ -193,18 +193,8 @@
         except KeyError:
             return ''
 
-    def get_comment(self):
-        try:
-            ret = self.get_exif_string('Exif.Photo.UserComment')
-            if ret == '':
-                raise ValueError
-        except (ValueError, KeyError):
-            try:
-                ret = self.get_exif_string('Exif.Image.ImageDescription')
-                if ret == '':
-                    raise ValueError
-            except (ValueError, KeyError):
-                ret = self.get_jpeg_comment()
+    def get_exif_usercomment(self):
+        ret = self.get_exif_string('Exif.Photo.UserComment')
         # This field can contain charset information
         if ret.startswith('charset='):
             tokens = ret.split(' ')
@@ -213,9 +203,8 @@
             ignore, cset = csetfield.split('=')
             cset = cset.strip('"')
             if cset == 'Unicode':
-                encoding = 'utf-16'
-                # Traling zero is lost somewhere
-                text += '\x00'
+                #XXX check little or big endian
+                encoding = 'UTF-16'
             elif cset == 'Ascii':
                 encoding = 'ascii'
             elif cset == 'Jis':
@@ -228,7 +217,23 @@
             try:
                 ret = text.decode(encoding)
             except UnicodeDecodeError:
+                print "retry"
                 ret = text.decode(encoding, 'replace')
+
+        return ret.strip('\0')
+
+    def get_comment(self):
+        try:
+            ret = self.get_exif_usercomment()
+            if ret == '':
+                raise ValueError
+        except (ValueError, KeyError):
+            try:
+                ret = self.get_exif_string('Exif.Image.ImageDescription')
+                if ret == '':
+                    raise ValueError
+            except (ValueError, KeyError):
+                ret = self.get_jpeg_comment()
         return ret
 
     def get_flash(self):

Reply via email to