abentele/PhotosExporter

Only items in albums are exported

teoteo opened this issue · 5 comments

I’ve created a small library for testing with 8 images.
01-library

3 of them are in Album0; 1 of them is Album1
02-albums

I’ve exported the library and only 4 images are exported.
03-exported

If is it by design, I suggest to write in Readme.md

An improvement could be also creating a folders structure to allow the export of all images.
I think something like

-year
--month
---day

but a custom structure could be placed in configuration file ~/Library/Application Support/PhotosExporter/PhotosExporter.yaml with something like this

%year%-%month%-%day%

or

%mediaType%-%year%-%month%

or

%keyword%-%year%

@teoteo I know I already mentioned osxphotos to you but will describe here how osxphotos handles this as something similar might be useful for PhotosExporter:

osxphotos includes a full templating system that allows user to specify directory, filename, and metadata (such as keywords) with templates similar to what you describe.

For example, the examples you gave can be executed in osxphotos thusly:
osxphotos export /path/to/export --directory "{created.year}/{created.month}/{created.dd}"

osxphotos export /path/to/export --directory "{media_type}/{created.year}/{created.month}"

You can even specify custom values for the media types:
osxphotos export /path/to/export --directory "{media_type,photo=foto;video=vidéo;time_lapse=vidéo_accélérée}/{created.year}/{created.month}"

osxphotos export /path/to/export --directory "{keyword}/{created.year}"

You can also specify default values, for example, for photos that have no keyword:

osxphotos export /path/to/export --directory "{keyword,NoKeyword}/{created.year}"
In this case, any photos that don't have keywords go to the "NoKeyword" directory.

osxphotos also exports all images, not just those in albums, and works on any photos library even if it's not the system library.

This system can also be used for specifying the filename and also for configuring exported metadata (e.g. embedding metadata into the EXIF data of the exported image or the Finder tags)

For example, add the word "Favorite" to all photos which are favorites and use exiftool to apply all metadata (keywords, persons, etc) from the Photos library to the exported image's EXIF data:

osxphotos export /path/to/export --directory "{created.year}/{created.month}/{created.dd}" --filename "{favorite?Favorite-{original_name},{original_name}}" --exiftool

I'm focused on developing osxphotos so don't have time to contribute to PhotosExporter but if the developer is interested, they can look at the grammar for the "mini language" osxphotos uses here. I've put a lot of thought into making the template system very flexible.

If you're interested in doing something similar for PhotosExporter, I recommend a PEG parser as it's very flexible. I initially implemented the osxphotos template engine using regular expressions but it was very cumbersome. I switched to textx which is a configurable PEG parser for python. There are similar options for Swift such as Patterns.

@teoteo yes, the current implementation only exports images that are in albums. The previous implementation which used the MLMediaLibrary API exported all photos. After switching to the PhotoKit API I simply ignored the photos which are not in any album. For me it's a known issue which should be fixed.

@teoteo, @RhetTbull regarding customization of directory structure: yes, it could be helpful for some people. But it's currently not on my personal wish list - my opinion is that it's sufficient to have a good default directory structure; also it would add additional complexity to configuration and implementation. Maybe I add some customization features in future. If you like this idea, please add another issue (I don't like tickets with more than one concern).

@RhetTbull Thanks for your suggestions.

now photos not assigned to any collection are also exported. Not yet implemented suggestion for configurable folder structure, because the current solution is sufficient for my workflow: I always assign photos to albums after they are imported.