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

Raise error if export() with missing asset #1598

Open
sg-s opened this issue Jun 25, 2024 · 6 comments
Open

Raise error if export() with missing asset #1598

sg-s opened this issue Jun 25, 2024 · 6 comments

Comments

@sg-s
Copy link

sg-s commented Jun 25, 2024

Describe the bug

I can't export photos to disk using photo.export(), and it does not do anything and no error is thrown

To Reproduce
Steps to reproduce the behavior:

import osxphotos

photosdb = osxphotos.PhotosDB()
photos = photosdb.photos()
photos[0].export("/tmp","photo_name.jpg")

Expected behavior

A jpg file to be created.

instead, nothing happens at all.

Screenshots

Screenshot 2024-06-25 at 11 54 07 AM

Desktop (please complete the following information):

  • OS: 14.5
  • osxphotos version (osxphotos --version)
osxphotos, version 0.68.2
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]
macOS 14.5.0, arm64

Additional context

However, I can "export" by reading photos.path_edited and simply copying that:

import shutil
shutil.copy(photo.path_edited,"/Users/srinivas/Desktop/test")

@RhetTbull
Copy link
Owner

Is the original image missing?

@RhetTbull
Copy link
Owner

If you don't set edited=True, it exports the original (it's one or the other). If original is missing it would export nothing (and return empty list). Perhaps it should raise FileNotFound but that's how it's implemented at the moment. Its incumbent on the user to ensure the original is present.

@sg-s
Copy link
Author

sg-s commented Jun 25, 2024

thank you so much @RhetTbull !

this worked:

photo.export("/Users/srinivas/Desktop/test","photo_name.jpg",edited=True,)

may i suggest changing the behavior to error out if no photo was exported?

@sg-s sg-s closed this as completed Jun 25, 2024
@RhetTbull RhetTbull reopened this Jun 25, 2024
@RhetTbull RhetTbull changed the title Unable to export photos using .export() Raise error if export() with missing asset Jun 25, 2024
@RhetTbull
Copy link
Owner

RhetTbull commented Jun 25, 2024

@sg-s you might also find PhotoExporter useful. This is the class that osxphotos export uses for export. It takes more configuration but gives you fine grained control over the export.

@sg-s
Copy link
Author

sg-s commented Jun 25, 2024

Do you want a PR?

@RhetTbull
Copy link
Owner

Sure, happy to accept a PR if you want to work on. If you implement this, do not change the behavior of PhotoExporter.export() as the osxphotos export code expects this to act the way it does (this returns much richer data than the plain PhotoInfo.export()).

The two places you'll need to modify are the return statements in iPhotoPhotoInfo.export() (iphoto.py) and PhotoInfo.export() (photoinfo.py).

Please add a test to verify the result (either in a new file or in tests/test_ventura_13_0_0.py

The photo with UUID A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C in tests/Test-13.0.0.photoslibrary is missing so that can be used to generate a test. Don't open the test library in Photos on your Mac as this could changes to the library (and will cause Photos on your Mac to try to update the library when photoanalysisd runs).

Unfortunately the iPhoto test library does not have a missing photo so a test cannot be created for iPhoto.

Please also update the API_README.md docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants