This commit is contained in:
Rhet Turnbull
2022-01-06 22:13:17 -08:00
parent 0c9bd87602
commit 661a573bf5
3 changed files with 10 additions and 4 deletions

View File

@@ -725,8 +725,10 @@ class PhotoInfo:
self._uti_original = self.uti self._uti_original = self.uti
elif self._db._photos_ver >= 7: elif self._db._photos_ver >= 7:
# Monterey+ # Monterey+
self._uti_original = get_uti_for_extension( # there are some cases with UTI_original is None (photo imported with no extension) so fallback to UTI and hope it's right
pathlib.Path(self.original_filename).suffix self._uti_original = (
get_uti_for_extension(pathlib.Path(self.original_filename).suffix)
or self.uti
) )
else: else:
self._uti_original = self._info["UTI_original"] self._uti_original = self._info["UTI_original"]
@@ -1025,7 +1027,7 @@ class PhotoInfo:
@property @property
def israw(self): def israw(self):
"""returns True if photo is a raw image. For images with an associated RAW+JPEG pair, see has_raw""" """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 @property
def raw_original(self): def raw_original(self):

View File

@@ -520,7 +520,8 @@ class PhotoAsset:
== Photos.PHAssetResourceTypeAlternatePhoto == Photos.PHAssetResourceTypeAlternatePhoto
): ):
data = self._request_resource_data(resource) 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 break
else: else:
raise PhotoKitExportError( raise PhotoKitExportError(

View File

@@ -591,6 +591,9 @@ def get_preferred_uti_extension(uti):
def get_uti_for_extension(extension): def get_uti_for_extension(extension):
"""get UTI for a given file extension""" """get UTI for a given file extension"""
if not extension:
return None
# accepts extension with or without leading 0 # accepts extension with or without leading 0
if extension[0] == ".": if extension[0] == ".":
extension = extension[1:] extension = extension[1:]