From 661a573bf50353fb2393c604080ffe0790ade59c Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Thu, 6 Jan 2022 22:13:17 -0800 Subject: [PATCH] Fix for #570 --- osxphotos/photoinfo.py | 8 +++++--- osxphotos/photokit.py | 3 ++- osxphotos/uti.py | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/osxphotos/photoinfo.py b/osxphotos/photoinfo.py index 0d3864fc..e9c52eae 100644 --- a/osxphotos/photoinfo.py +++ b/osxphotos/photoinfo.py @@ -725,8 +725,10 @@ class PhotoInfo: self._uti_original = self.uti elif self._db._photos_ver >= 7: # Monterey+ - self._uti_original = get_uti_for_extension( - pathlib.Path(self.original_filename).suffix + # there are some cases with UTI_original is None (photo imported with no extension) so fallback to UTI and hope it's right + self._uti_original = ( + get_uti_for_extension(pathlib.Path(self.original_filename).suffix) + or self.uti ) else: self._uti_original = self._info["UTI_original"] @@ -1025,7 +1027,7 @@ class PhotoInfo: @property def israw(self): """returns True if photo is a raw image. For images with an associated RAW+JPEG pair, see has_raw""" - return "raw-image" in self.uti_original + return "raw-image" in self.uti_original if self.uti_original else False @property def raw_original(self): diff --git a/osxphotos/photokit.py b/osxphotos/photokit.py index 58f52285..4799ba26 100644 --- a/osxphotos/photokit.py +++ b/osxphotos/photokit.py @@ -520,7 +520,8 @@ class PhotoAsset: == Photos.PHAssetResourceTypeAlternatePhoto ): data = self._request_resource_data(resource) - ext = pathlib.Path(self.raw_filename).suffix[1:] + suffix = pathlib.Path(self.raw_filename).suffix + ext = suffix[1:] if suffix else "" break else: raise PhotoKitExportError( diff --git a/osxphotos/uti.py b/osxphotos/uti.py index 1ce7569a..10ad3e21 100644 --- a/osxphotos/uti.py +++ b/osxphotos/uti.py @@ -591,6 +591,9 @@ def get_preferred_uti_extension(uti): def get_uti_for_extension(extension): """get UTI for a given file extension""" + if not extension: + return None + # accepts extension with or without leading 0 if extension[0] == ".": extension = extension[1:]