Skip to content

Commit

Permalink
Merge pull request #194 from jim-easterbrook/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
jim-easterbrook committed May 22, 2023
2 parents 339bf72 + c1be377 commit 0b143a4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.

Changes in v2023.5.1:
1/ Tab labels use two lines instead of eliding to fit width.
2/ Ignore NULL bytes in some phone images' Exif comment values.
3/ Italian localisation is complete.
4/ Other minor improvements and bug fixes.

Changes in v2023.5.0:
1/ Latitude & longitude values no longer have comma separator.
2/ All numeric values are localised, e.g. to use decimal comma.
Expand Down
2 changes: 1 addition & 1 deletion src/photini/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Full documentation is at https://photini.readthedocs.io/"""

__version__ = '2023.5.1'
build = '2719 (e80171b)'
build = '2722 (64e9222)'
38 changes: 23 additions & 15 deletions src/photini/exiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,33 @@ def get_exif_comment(self, tag, datum):
if charset != exiv2.CharsetId.undefined:
logger.warning('%s: %s: unknown charset', self._name, tag)
raw_value = data
result = None
for encoding in encodings:
result = self.decode_string(tag, raw_value, encoding)
if result:
return result
detector = chardet.universaldetector.UniversalDetector()
for i in range(0, len(raw_value), 100):
detector.feed(raw_value[i:i+100])
if detector.done:
break
detector.close()
encoding = detector.result['encoding']
if encoding:
result = self.decode_string(tag, raw_value, encoding)
if result:
return result
logger.error(
'%s: %s: %d bytes binary data will be deleted when metadata'
' is saved', self._name, tag, value.size())
return None
else:
detector = chardet.universaldetector.UniversalDetector()
for i in range(0, len(raw_value), 100):
detector.feed(raw_value[i:i+100])
if detector.done:
break
detector.close()
encoding = detector.result['encoding']
if encoding:
result = self.decode_string(tag, raw_value, encoding)
if result and '\0' in result:
# terminating NULLs are allowed
result = result.strip('\0')
if '\0' in result:
# NULLs within the string are not allowed
result = None
if not result:
logger.error(
'%s: %s: %d bytes binary data will be deleted when metadata'
' is saved', self._name, tag, value.size())
return None
return result

def get_exif_value(self, tag):
datum = self._exifData.findKey(exiv2.ExifKey(tag))
Expand Down
2 changes: 1 addition & 1 deletion src/photini/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ def get_type(cls, key, value):

@classmethod
def from_exiv2(cls, file_value, tag):
file_value = file_value or {}
if isinstance(file_value, (list, tuple)):
# "legacy" list of string values
file_value = dict(zip(cls.legacy_keys, file_value))
file_value = file_value or {}
for key, value in file_value.items():
file_value[key] = cls.get_type(key, value).from_exiv2(value, tag)
return cls(file_value)
Expand Down

0 comments on commit 0b143a4

Please sign in to comment.