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

Sequoia edited fix 1687 #1689

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions osxphotos/cli/import_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@

assert_macos()

import makelive
try:
# makelive does not work on macOS <= 10.15.x
import makelive
except ImportError:
makelive = None

from photoscript import Photo, PhotosLibrary

import osxphotos.sqlite3_datetime as sqlite3_datetime
Expand Down Expand Up @@ -601,7 +606,8 @@ def get_help(self, ctx):
"When --auto-live is used, a photo and a video with same base name, "
"for example 'IMG_1234.JPG' and 'IMG_1234.mov', in the same directory will be converted to Live Photos. "
"*NOTE*: Using this feature will modify the metadata in the files prior to import. "
"Ensure you have a backup of the original files if you want to preserve unmodified versions.",
"Ensure you have a backup of the original files if you want to preserve unmodified versions. "
"*NOTE*: this option does not work on macOS < 11.0.",
)
@click.option(
"--parse-date",
Expand Down Expand Up @@ -989,8 +995,9 @@ def import_main(

Thus the "Imports" album in Photos will show a new import group for each photo imported.

Exception: Live photos (photo+video pair), burst photos, edited photos, and RAW+JPEG pairs
will be imported together so that Photos processes them correctly.
Exception: On macOS >= 11.0, Live photos (photo+video pair), burst photos, edited photos,
and RAW+JPEG pairs will be imported together so that Photos processes them correctly.
Automatic grouping of live photos and burst photos is not supported on macOS <= 10.15.

Edited Photos:

Expand Down Expand Up @@ -2823,7 +2830,7 @@ def sort_paths(paths: Iterable[pathlib.Path]) -> tuple[pathlib.Path, ...]:
def path_key(path: pathlib.Path) -> tuple[str, int, int, int, int]:
extension = path.suffix.lower()
is_aae = extension == ".aae"
is_mov = extension == ".mov"
is_mov = extension in (".mov", ".mp4")
base_name = path.stem.split("_")[0] # Extract the base name without suffixes
return (base_name, len(path.stem), is_aae, is_mov)

Expand Down Expand Up @@ -3188,6 +3195,10 @@ def import_files(
f"Converting to live photo pair: [filename]{files_to_import[0].name}[/], [filename]{files_to_import[1].name}[/]"
)
try:
if not makelive:
raise RuntimeError(
"makelive not compatible with this version of macOS"
)
makelive.make_live_photo(*files_to_import[:2])
except Exception as e:
echo(
Expand Down
31 changes: 26 additions & 5 deletions osxphotos/image_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@

assert_macos()

import cgmetadata
import makelive
try:
# won't be installed on macOS < 11
import cgmetadata
except ImportError:
cgmetadata = None

try:
# won't be installed on macOS < 11
import makelive
except ImportError:
makelive = None

import objc
from Foundation import NSURL, NSURLTypeIdentifierKey
from UniformTypeIdentifiers import UTType, UTTypeImage, UTTypeMovie
Expand Down Expand Up @@ -75,18 +85,23 @@ def is_raw_pair(filepath1: str | os.PathLike, filepath2: str | os.PathLike) -> b

def is_live_pair(filepath1: str | os.PathLike, filepath2: str | os.PathLike) -> bool:
"""Return True if photos are a live photo pair"""
if not makelive:
return False

if not is_image_file(filepath1) or not is_video_file(filepath2):
# expects live pairs to be image, video
return False

return makelive.is_live_photo_pair(filepath1, filepath2)


def is_possible_live_pair(
filepath1: str | os.PathLike, filepath2: str | os.PathLike
) -> bool:
"""Return True if photos could be a live photo pair (even if files lack the Content ID metadata"""
print(f"{filepath1=}, {filepath2=}")
if is_image_file(filepath1) and is_video_file(filepath2):
if (is_image_file(filepath1) and is_video_file(filepath2)) or (
is_video_file(filepath1) and is_image_file(filepath2)
):
return True
return False

Expand All @@ -96,6 +111,9 @@ def burst_uuid_from_path(path: pathlib.Path) -> str | None:
if not is_image_file(path):
return None

if not cgmetadata:
return None

md = cgmetadata.ImageMetadata(path)
with suppress(KeyError):
return md.properties["MakerApple"]["11"]
Expand All @@ -118,7 +136,10 @@ def load_aae_file(filepath: str | os.PathLike) -> dict[str, Any] | None:
def is_apple_photos_aae_file(filepath: str | os.PathLike) -> bool:
"""Return True if filepath is an AAE file containing Apple Photos adjustments; returns False is file contains adjustments for an external editor"""
if plist := load_aae_file(filepath):
if plist.get("adjustmentFormatIdentifier") in ["com.apple.photo", "com.apple.video", ]:
if plist.get("adjustmentFormatIdentifier") in [
"com.apple.photo",
"com.apple.video",
]:
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion osxphotos/photoinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def ismissing(self) -> bool:
@property
def hasadjustments(self) -> bool:
"""True if picture has adjustments / edits"""
return self._info["hasAdjustments"] == 1
return bool(self._info["hasAdjustments"])

@property
def adjustments_path(self) -> pathlib.Path | None:
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# On macOS < Monterey (12.0, platform_release = 21.x), pyobjc 9.0 is the last version that works, #1324
bitmath>=1.3.3.1,<1.4.0.0
bpylist2>=4.1.1,<5.0.0
cgmetadata>=0.1.6; sys_platform == 'darwin'
cgmetadata>=0.1.6; sys_platform == 'darwin' and platform_release >= "20.0.0" # not compatible on macOS <= 10.15.x
Click>=8.1.3,<9.0
mac-alias>=2.2.2,<3.0.0; sys_platform == 'darwin'
makelive>=0.5.0; sys_platform == 'darwin'
makelive>=0.5.0; sys_platform == 'darwin' and platform_release >= "20.0.0" # not compatible on macOS <= 10.15.x
Mako>=1.2.2,<1.3.0
more-itertools>=8.8.0,<9.0.0
objexplore>=1.6.3,<2.0.0
Expand Down Expand Up @@ -47,4 +47,4 @@ toml>=0.10.2,<0.11.0
wrapt>=1.14.1,<2.0.0
wurlitzer>=3.0.2,<4.0.0
xdg-base-dirs>=6.0.0; python_version >= '3.10'
xdg==5.1.1; python_version <= '3.9'
xdg==5.1.1; python_version <= '3.9'
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
install_requires=[
"bitmath>=1.3.3.1,<1.4.0.0",
"bpylist2>=4.1.1,<5.0.0",
"cgmetadata>=0.1.6; sys_platform == 'darwin'",
"cgmetadata>=0.1.6; sys_platform == 'darwin' and platform_release >= '20.0.0'", # not compatible on macOS <= 10.15.x
"Click>=8.1.3,<9.0",
"mac-alias>=2.2.2,<3.0.0; sys_platform == 'darwin'",
"makelive>=0.5.0; sys_platform == 'darwin'",
"makelive>=0.5.0; sys_platform == 'darwin' and platform_release >= '20.0.0'", # not compatible on macOS <= 10.15.x'",
"Mako>=1.2.2,<1.3.0",
"more-itertools>=8.8.0,<9.0.0",
"objexplore>=1.6.3,<2.0.0",
Expand Down
3 changes: 1 addition & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ A couple of tests require interaction with Photos and configuring a specific tes
- --timewarp: test `osxphotos timewarp` (pytest -vv --timewarp tests/test_cli_timewarp.py)
- --test-import: test `osxphotos import` (pytest -vv --test-import tests/test_cli_import.py)
- --test-sync: test `osxphotos sync` (pytest -vv --test-sync tests/test_cli_sync.py)
- --test-add-locations: test `osxphotos add-locations` (pytest -vv
--test-add-locations tests/test_cli_add_locations.py)
- --test-add-locations: test `osxphotos add-locations` (pytest -vv --test-add-locations tests/test_cli_add_locations.py)
- --test-batch-edit: test `osxphotos batch-edit` (pytest -vv --test-batch-edit -k batch)

## Test Photo Libraries
Expand Down
Loading