RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
2.17k stars 100 forks source link

empty directories from iCloud shared folders #394

Open garz75 opened 3 years ago

garz75 commented 3 years ago

With this command line

osxphotos export .  --update  --convert-to-jpeg --jpeg-quality 0.95 --directory "{folder_album,NoAlbum}"  \ 
 --person-keyword --keyword-template "{label}" --skip-original-if-edited --exiftool  \
 --filename "{created.strftime,%Y-%m-%d-%H%M%S}"

osxphotos creates empty directories named after all my shared albums from iCloud in the output directory. Is this normal ?

RhetTbull commented 3 years ago

No this shouldn't happen. What I think is happening is that the shared photos aren't on the local machine (and you're not using --download-missing) but because you're using --directory "{folder_album,NoAlbum}", osxphotos creates the directory before it attempts to export the picture but then doesn't export any of those photos as there's not a copy on the local machine (this is normal for shared iCloud photos--Photos doesn't keep a copy locally unless you open the image in Photos at which time it downloads the original from iCloud).

Edit: this could happen with other albums as well if images weren't in the local library cache. I'll have to add a check to the export code that checks to see if any files were actually exported, and if not, delete the empty directory.

RhetTbull commented 3 years ago

Until I can get a fix for this, you could try adding --cleanup to your export command. This deletes any files or directories that weren't part of the export. I just did a test and was able to replicate the behavior you saw with a shared album and --cleanup removed the empty folder when the export was complete.

osxphotos export ~/Desktop/export --directory "{folder_album,None}" --uuid 75F7B0D6-AC55-4628-AA86-760EBA452A11 -V --cleanup
...
Exporting 1 photo to /Users/rhet/Desktop/export...
Exporting 75F7B0D6-AC55-4628-AA86-760EBA452A11.JPG (75F7B0D6-AC55-4628-AA86-760EBA452A11.JPG) as 75F7B0D6-AC55-4628-AA86-760EBA452A11.JPG
Skipping missing photo 75F7B0D6-AC55-4628-AA86-760EBA452A11.JPG (75F7B0D6-AC55-4628-AA86-760EBA452A11)
Cleaning up /Users/rhet/Desktop/export
Deleting /Users/rhet/Desktop/export/.DS_Store
Deleting empty directory /Users/rhet/Desktop/export/Thanksgiving 2017
Deleted: 1 file, 1 directory
Processed: 1 photo, exported: 0, missing: 1, error: 0
garz75 commented 3 years ago

No this shouldn't happen. What I think is happening is that the shared photos aren't on the local machine (and you're not using --download-missing) but because you're using --directory "{folder_album,NoAlbum}", osxphotos creates the directory before it attempts to export the picture but then doesn't export any of those photos as there's not a copy on the local machine (this is normal for shared iCloud photos--Photos doesn't keep a copy locally unless you open the image in Photos at which time it downloads the original from iCloud).

I moved to a new Mac and I did not realise that the Photo Library was NOT configured with "Download originals to this Mac". Is this a new behaviour of osxphotos ? because IIRC, on my last export of the same library (November 2020) on my old mac, I used the same options and osxphotos would completely ignore the Shared albums....

garz75 commented 3 years ago

Until I can get a fix for this, you could try adding --cleanup to your export command. This deletes any files or directories that weren't part of the export. I just did a test and was able to replicate the behavior you saw with a shared album and --cleanup removed the empty folder when the export was complete.

BarneyStinson:~/Desktop/out/osxphotos> ./export_all.sh
Using last opened Photos library: /Users/fgarzon/Pictures/Bibliothèque Photos.photoslibrary
Exporting 33792 photos to /Users/fgarzon/Desktop/out/osxphotos...
  [####################################]  100%
Cleaning up /Users/fgarzon/Desktop/out/osxphotos
Deleted: 7 files, 25 directories
Processed: 33792 photos, exported: 38, updated: 0, skipped: 33931, updated EXIF data: 42, missing: 544, error: 0
Elapsed time: 36.292 seconds

This fixed the empty directory issue, but also deleted the shell scripts I have in the directory to update the export : ./export_all.sh was one of the 7 files removed :-(... Luckily I have backups ;-)

I understand it is easier to implement the --cleanup with "remove all files/dirs that were not part of the export, but this should be documented... I moved my scripts elsewhere, no worries.

RhetTbull commented 3 years ago

I understand it is easier to implement the --cleanup with "remove all files/dirs that were not part of the export, but this should be documented... I moved my scripts elsewhere, no worries.

I'll update the documentation. Glad you had backups! Not sure how I'd implement a cleanup feature without deleting anything that's not part of the backup set. It might be possible for osxphotos to apply a special extended attribute to every file and only delete files that had this attribute -- for example, you changed the naming scheme so osxphotos would delete previously exported files. This could get complex very quickly though.

RhetTbull commented 3 years ago

Is this a new behaviour of osxphotos ? because IIRC, on my last export of the same library (November 2020) on my old mac, I used the same options and osxphotos would completely ignore the Shared albums....

I don't think so -- it's exported shared photos for a long time (but usually they're missing unless you use --download-missing)