Compare commits

..

58 Commits

Author SHA1 Message Date
Rhet Turnbull
541c390b7b Added height, width, orientation, filesize, closes #163 2020-07-03 11:24:59 -07:00
Rhet Turnbull
6ab0ad7e86 Added GPS location to XMP sidecar, closes #175 2020-07-03 09:04:23 -07:00
Rhet Turnbull
e5755c6144 Updated CHANGELOG.md 2020-06-28 21:54:36 -07:00
Rhet Turnbull
7806e05673 Updated README.md 2020-06-28 21:53:50 -07:00
Rhet Turnbull
bb4bc8fd96 Added --description-template to CLI, closes #166 2020-06-28 20:10:38 -07:00
Rhet Turnbull
59507077ba Updated README.md 2020-06-28 13:50:12 -07:00
Rhet Turnbull
ff0328785f Added expand_inplace to PhotoTemplate.render 2020-06-28 13:46:35 -07:00
Rhet Turnbull
3693d65b82 Added --deleted, --deleted-only to CLI, closes #179 2020-06-28 10:02:36 -07:00
Rhet Turnbull
6a85bd215a Updated CHANGELOG.md 2020-06-27 19:21:27 -07:00
Rhet Turnbull
ab36264af0 Changed default to PhotosDB.photos(movies=True), closes #177 2020-06-27 12:57:46 -07:00
Rhet Turnbull
185483e1aa added intrash support for issue #179 2020-06-27 10:54:25 -07:00
Rhet Turnbull
c1d12047bd Removed pdf filter on process_database_4 2020-06-26 20:04:53 -07:00
Rhet Turnbull
46c87eeed5 Added test for issue #178 2020-06-23 22:12:32 -07:00
Rhet Turnbull
fd4c99032d Additional fix for issue #178 2020-06-23 12:21:46 -07:00
Rhet Turnbull
d6fee89fd9 version bump 2020-06-23 12:07:07 -07:00
Rhet Turnbull
b8618cf272 Bug fix for issue #178 2020-06-23 12:01:20 -07:00
Rhet Turnbull
6b7c5d07fd Updated CHANGELOG.md 2020-06-22 07:22:19 -07:00
Rhet Turnbull
bd5ba702aa Closes #174 2020-06-22 07:14:10 -07:00
Rhet Turnbull
c8d76a89e4 Added today to template system, closes #167 2020-06-21 21:58:18 -07:00
Rhet Turnbull
a8e996e660 Minor refactoring in photoinfo.py 2020-06-21 12:06:25 -07:00
Rhet Turnbull
c68a5ab39f Updated CHANGELOG.md 2020-06-21 09:01:15 -07:00
Rhet Turnbull
1ebf995833 Bug fix for issue #172 2020-06-21 08:42:19 -07:00
Rhet Turnbull
538bac7ade More PhotoInfo.albums refactoring, closes #169 2020-06-21 08:18:11 -07:00
Rhet Turnbull
32806c8459 Updated CHANGELOG.md 2020-06-20 17:44:18 -07:00
Rhet Turnbull
cfabd0dbea Refactored album code in photosdb to fix issue #169 2020-06-20 17:31:33 -07:00
Rhet Turnbull
a23259948c Updated CHANGELOG.md 2020-06-20 08:43:42 -07:00
Rhet Turnbull
1212fad4ad Fixed PhotoInfo.albums, album_info for issue #169 2020-06-20 08:36:03 -07:00
Rhet Turnbull
567abe3311 Updated CHANGELOG.md 2020-06-18 22:52:21 -07:00
Rhet Turnbull
5a832181f7 Fixed get_last_library_path and get_system_library_path to not raise KeyError 2020-06-18 22:16:11 -07:00
Rhet Turnbull
4da57a1cee Merge pull request #168 from dethi/thibault/fix-exception-when-SystemLibraryPath-is-not-present
Don't raise KeyError when SystemLibraryPath is absent
2020-06-18 21:38:53 -07:00
Thibault Deutsch
1fd0f96b14 Don't raise KeyError when SystemLibraryPath is absent 2020-06-18 23:43:55 +01:00
Rhet Turnbull
e98c3fe429 Added show() to photos_repl.py 2020-06-16 22:46:46 -07:00
Rhet Turnbull
d77e9747cd Added check for export db in directory branch, closes #164 2020-06-14 17:51:57 -07:00
Rhet Turnbull
43d28e78f3 Added OSXPhotosDB.get_db_connection() 2020-06-14 12:52:23 -07:00
Rhet Turnbull
00bc50490e Updated CHANGELOG.md 2020-06-14 08:44:55 -07:00
Rhet Turnbull
f8743c33bd Updated CHANGELOG.md 2020-06-14 08:41:36 -07:00
Rhet Turnbull
937da9e617 Added computed aesthetic scores, closes #141, closes #122 2020-06-14 08:09:37 -07:00
Rhet Turnbull
435868a0a7 Updated CHANGELOG.md 2020-06-13 19:46:55 -07:00
Rhet Turnbull
d9802247d9 Added --label to CLI, closes #157 2020-06-13 19:40:46 -07:00
Rhet Turnbull
f39a92a352 Updated CHANGELOG.md 2020-06-13 15:11:10 -07:00
Rhet Turnbull
40dc7d32f2 Extende --ignore-case to --person, --keyword, --album, closes #162 2020-06-13 15:06:27 -07:00
Rhet Turnbull
4cd6c8f617 Updated CHANGELOG.md 2020-06-13 11:32:48 -07:00
Rhet Turnbull
0004250e74 Updated README.md to document template system 2020-06-13 10:52:18 -07:00
Rhet Turnbull
868ee7737b Added hour, min, sec, strftime templates, closes #158 2020-06-13 10:32:04 -07:00
Rhet Turnbull
5387f8e2f9 Added hour, min, sec to template system, issue #158 2020-06-13 09:17:34 -07:00
Rhet Turnbull
73b499f405 Updated CHANGELOG.md 2020-06-13 09:04:23 -07:00
Rhet Turnbull
06fa1edcae Bug fix for issue #136 2020-06-13 08:52:23 -07:00
Rhet Turnbull
cf2615da62 Updated DatetimeFormatter to include hour/min/sec 2020-06-13 08:32:56 -07:00
Rhet Turnbull
4ba1982d74 Added test for issue #156 2020-06-09 23:03:30 -07:00
Rhet Turnbull
abd10b73e8 Updated help text for debug-dump 2020-06-07 14:32:49 -07:00
Rhet Turnbull
7cd7b51598 Added hidden debug-dump command to CLI 2020-06-07 14:17:08 -07:00
Rhet Turnbull
801dc62c4b Updated CHANGELOG.md 2020-06-07 08:29:48 -07:00
Rhet Turnbull
72f034ef85 Fix for bug in handling of deleted albums to address issue #156 2020-06-07 08:14:02 -07:00
Rhet Turnbull
cb993f2e5e Merge branch 'master' of https://github.com/RhetTbull/osxphotos 2020-06-06 12:12:05 -07:00
Rhet Turnbull
2271d89355 Partial fix for #155 2020-06-06 12:11:50 -07:00
Rhet Turnbull
62d096b5a1 Partial fix for #155 2020-06-06 12:09:51 -07:00
Rhet Turnbull
5c7a0c3a24 Refactoring with sourceryAI 2020-06-01 21:06:09 -07:00
Rhet Turnbull
ec727cc556 Updated CHANGELOG.md 2020-05-31 11:31:24 -07:00
103 changed files with 3604 additions and 602 deletions

View File

@@ -4,6 +4,144 @@ All notable changes to this project will be documented in this file. Dates are d
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### [v0.30.3](https://github.com/RhetTbull/osxphotos/compare/v0.30.2...v0.30.3)
> 29 June 2020
- Added --description-template to CLI, closes #166 [`#166`](https://github.com/RhetTbull/osxphotos/issues/166)
- Added expand_inplace to PhotoTemplate.render [`ff03287`](https://github.com/RhetTbull/osxphotos/commit/ff0328785f3ea14b1c8ae2b7d1a9b07e8aef0777)
- Updated README.md [`5950707`](https://github.com/RhetTbull/osxphotos/commit/59507077bafe39a17bc23babe6d6c52e1f502a53)
#### [v0.30.2](https://github.com/RhetTbull/osxphotos/compare/v0.30.1...v0.30.2)
> 28 June 2020
- Added --deleted, --deleted-only to CLI, closes #179 [`#179`](https://github.com/RhetTbull/osxphotos/issues/179)
#### [v0.30.1](https://github.com/RhetTbull/osxphotos/compare/v0.30.0...v0.30.1)
> 27 June 2020
- Changed default to PhotosDB.photos(movies=True), closes #177 [`#177`](https://github.com/RhetTbull/osxphotos/issues/177)
#### [v0.30.0](https://github.com/RhetTbull/osxphotos/compare/v0.29.30...v0.30.0)
> 27 June 2020
- added intrash support for issue #179 [`185483e`](https://github.com/RhetTbull/osxphotos/commit/185483e1aa9ed107402bfb178f264417e6926b46)
- Removed pdf filter on process_database_4 [`c1d1204`](https://github.com/RhetTbull/osxphotos/commit/c1d12047bde84740b96c8531110e7b2d2fe41f2e)
#### [v0.29.30](https://github.com/RhetTbull/osxphotos/compare/v0.29.29...v0.29.30)
> 24 June 2020
- Added test for issue #178 [`46c87ee`](https://github.com/RhetTbull/osxphotos/commit/46c87eeed56d5765317dec4992d2e16323c711ad)
- Additional fix for issue #178 [`fd4c990`](https://github.com/RhetTbull/osxphotos/commit/fd4c99032dbbedd6325aabacb0bc800b24ede413)
#### [v0.29.29](https://github.com/RhetTbull/osxphotos/compare/v0.29.28...v0.29.29)
> 23 June 2020
- version bump [`d6fee89`](https://github.com/RhetTbull/osxphotos/commit/d6fee89fd9dd07c4788562ed551d0a3f2b5d697d)
- Bug fix for issue #178 [`b8618cf`](https://github.com/RhetTbull/osxphotos/commit/b8618cf272efc174b7fa872f233b561bd9e7243e)
#### [v0.29.28](https://github.com/RhetTbull/osxphotos/compare/v0.29.26...v0.29.28)
> 22 June 2020
- Closes #174 [`#174`](https://github.com/RhetTbull/osxphotos/issues/174)
- Added today to template system, closes #167 [`#167`](https://github.com/RhetTbull/osxphotos/issues/167)
- Minor refactoring in photoinfo.py [`a8e996e`](https://github.com/RhetTbull/osxphotos/commit/a8e996e66072e94de93fd4ea78a456bc61831f52)
#### [v0.29.26](https://github.com/RhetTbull/osxphotos/compare/v0.29.25...v0.29.26)
> 21 June 2020
- Bug fix for issue #172 [`1ebf995`](https://github.com/RhetTbull/osxphotos/commit/1ebf99583397617f0d3a234c898beae1c14f5a63)
#### [v0.29.25](https://github.com/RhetTbull/osxphotos/compare/v0.29.24...v0.29.25)
> 21 June 2020
- More PhotoInfo.albums refactoring, closes #169 [`#169`](https://github.com/RhetTbull/osxphotos/issues/169)
#### [v0.29.24](https://github.com/RhetTbull/osxphotos/compare/v0.29.23...v0.29.24)
> 21 June 2020
- Refactored album code in photosdb to fix issue #169 [`cfabd0d`](https://github.com/RhetTbull/osxphotos/commit/cfabd0dbead62c8ab6a774899239e5da5bfe1203)
#### [v0.29.23](https://github.com/RhetTbull/osxphotos/compare/v0.29.22...v0.29.23)
> 20 June 2020
- Fixed PhotoInfo.albums, album_info for issue #169 [`1212fad`](https://github.com/RhetTbull/osxphotos/commit/1212fad4adde0b4c6b2887392eed829d8d96d61d)
#### [v0.29.22](https://github.com/RhetTbull/osxphotos/compare/v0.29.19...v0.29.22)
> 19 June 2020
- Don't raise KeyError when SystemLibraryPath is absent [`#168`](https://github.com/RhetTbull/osxphotos/pull/168)
- Added check for export db in directory branch, closes #164 [`#164`](https://github.com/RhetTbull/osxphotos/issues/164)
- Added OSXPhotosDB.get_db_connection() [`43d28e7`](https://github.com/RhetTbull/osxphotos/commit/43d28e78f394fa33f8d88f64b56b7dc7258cd454)
- Added show() to photos_repl.py [`e98c3fe`](https://github.com/RhetTbull/osxphotos/commit/e98c3fe42912ac16d13675bf14154981089d41ea)
- Fixed get_last_library_path and get_system_library_path to not raise KeyError [`5a83218`](https://github.com/RhetTbull/osxphotos/commit/5a832181f73e082927c80864f2063e554906b06b)
- Don't raise KeyError when SystemLibraryPath is absent [`1fd0f96`](https://github.com/RhetTbull/osxphotos/commit/1fd0f96b14f0bc38e47bddb4cae12e19406324fb)
#### [v0.29.19](https://github.com/RhetTbull/osxphotos/compare/v0.29.18...v0.29.19)
> 14 June 2020
- Added computed aesthetic scores, closes #141, closes #122 [`#141`](https://github.com/RhetTbull/osxphotos/issues/141) [`#122`](https://github.com/RhetTbull/osxphotos/issues/122)
#### [v0.29.18](https://github.com/RhetTbull/osxphotos/compare/v0.29.17...v0.29.18)
> 14 June 2020
- Added --label to CLI, closes #157 [`#157`](https://github.com/RhetTbull/osxphotos/issues/157)
#### [v0.29.17](https://github.com/RhetTbull/osxphotos/compare/v0.29.16...v0.29.17)
> 13 June 2020
- Extende --ignore-case to --person, --keyword, --album, closes #162 [`#162`](https://github.com/RhetTbull/osxphotos/issues/162)
- Updated README.md to document template system [`0004250`](https://github.com/RhetTbull/osxphotos/commit/0004250e74eacc19f7986742712225116530a67e)
#### [v0.29.16](https://github.com/RhetTbull/osxphotos/compare/v0.29.14...v0.29.16)
> 13 June 2020
- Added hour, min, sec, strftime templates, closes #158 [`#158`](https://github.com/RhetTbull/osxphotos/issues/158)
- Added hour, min, sec to template system, issue #158 [`5387f8e`](https://github.com/RhetTbull/osxphotos/commit/5387f8e2f970ff7fa1967ccad87b45a4f7e50d32)
#### [v0.29.14](https://github.com/RhetTbull/osxphotos/compare/v0.29.13...v0.29.14)
> 13 June 2020
- Updated DatetimeFormatter to include hour/min/sec [`cf2615d`](https://github.com/RhetTbull/osxphotos/commit/cf2615da62801f1fbde61c7905431963e121e2e9)
- Added test for issue #156 [`4ba1982`](https://github.com/RhetTbull/osxphotos/commit/4ba1982d745f0d532ead090177051d928465ed03)
- Bug fix for issue #136 [`06fa1ed`](https://github.com/RhetTbull/osxphotos/commit/06fa1edcae7139b543e17ec63810c37c18cc2780)
#### [v0.29.13](https://github.com/RhetTbull/osxphotos/compare/v0.29.12...v0.29.13)
> 7 June 2020
- Added hidden debug-dump command to CLI [`7cd7b51`](https://github.com/RhetTbull/osxphotos/commit/7cd7b5159845fce15d50a7bfc0ac50d122bee527)
#### [v0.29.12](https://github.com/RhetTbull/osxphotos/compare/v0.29.9...v0.29.12)
> 7 June 2020
- Fix for bug in handling of deleted albums to address issue #156 [`72f034e`](https://github.com/RhetTbull/osxphotos/commit/72f034ef85010544a158d8301b898b5d0d865b05)
- Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`cb993f2`](https://github.com/RhetTbull/osxphotos/commit/cb993f2e5e2df7e0a15b3b2fdb92b65a8de56974)
- Refactoring with sourceryAI [`5c7a0c3`](https://github.com/RhetTbull/osxphotos/commit/5c7a0c3a246cd5fec329b4fd4979d2b77352f916)
#### [v0.29.9](https://github.com/RhetTbull/osxphotos/compare/v0.29.8...v0.29.9)
> 31 May 2020
- Added --filename to CLI, closes #89 [`#89`](https://github.com/RhetTbull/osxphotos/issues/89)
#### [v0.29.8](https://github.com/RhetTbull/osxphotos/compare/v0.29.5...v0.29.8) #### [v0.29.8](https://github.com/RhetTbull/osxphotos/compare/v0.29.5...v0.29.8)
> 31 May 2020 > 31 May 2020
@@ -24,7 +162,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added --dry-run option to CLI export, closes #91 [`#91`](https://github.com/RhetTbull/osxphotos/issues/91) - Added --dry-run option to CLI export, closes #91 [`#91`](https://github.com/RhetTbull/osxphotos/issues/91)
- added created.dd and modified.dd to template system, closes #135 [`#135`](https://github.com/RhetTbull/osxphotos/issues/135) - added created.dd and modified.dd to template system, closes #135 [`#135`](https://github.com/RhetTbull/osxphotos/issues/135)
- Catch exception in folder processing to address #148 [`46fdc94`](https://github.com/RhetTbull/osxphotos/commit/46fdc94398c80b157048649434c7312074ce5c58) - Catch exception in folder processing to address #148 [`46fdc94`](https://github.com/RhetTbull/osxphotos/commit/46fdc94398c80b157048649434c7312074ce5c58)
- Updated CHANGELOG.md [`af750dd`](https://github.com/RhetTbull/osxphotos/commit/af750dd2e392be1a7163cf32497526405665ea70) - added created.dow (day of week) to template [`8df6d2c`](https://github.com/RhetTbull/osxphotos/commit/8df6d2c707caf4eb35696888282365a128b69569)
- Added test for DateTimeFormatter.dow [`09c7d18`](https://github.com/RhetTbull/osxphotos/commit/09c7d18901b61669d8b9242babd82eba6987c89a) - Added test for DateTimeFormatter.dow [`09c7d18`](https://github.com/RhetTbull/osxphotos/commit/09c7d18901b61669d8b9242babd82eba6987c89a)
#### [v0.29.2](https://github.com/RhetTbull/osxphotos/compare/v0.29.1...v0.29.2) #### [v0.29.2](https://github.com/RhetTbull/osxphotos/compare/v0.29.1...v0.29.2)
@@ -38,7 +176,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 23 May 2020 > 23 May 2020
- Catch illegal timestamp value [`#146`](https://github.com/RhetTbull/osxphotos/pull/146) - Catch illegal timestamp value [`#146`](https://github.com/RhetTbull/osxphotos/pull/146)
- Updated CHANGELOG.md [`1450b3c`](https://github.com/RhetTbull/osxphotos/commit/1450b3ccace326fe1c0ed810a1b40e781709acb3) - Catch illegal timestamp value [`441de71`](https://github.com/RhetTbull/osxphotos/commit/441de711dc664b244d599c81e3dd1bcd9b2e55a0)
#### [v0.29.0](https://github.com/RhetTbull/osxphotos/compare/v0.28.19...v0.29.0) #### [v0.29.0](https://github.com/RhetTbull/osxphotos/compare/v0.28.19...v0.29.0)
@@ -48,8 +186,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added --update to CLI export; reference issue #100 [`b1171e9`](https://github.com/RhetTbull/osxphotos/commit/b1171e96cc06362555725995bb311317eb163e49) - Added --update to CLI export; reference issue #100 [`b1171e9`](https://github.com/RhetTbull/osxphotos/commit/b1171e96cc06362555725995bb311317eb163e49)
- Added as_dict to PlaceInfo [`8c4fe40`](https://github.com/RhetTbull/osxphotos/commit/8c4fe40aa6850f166e526cffaa088550884399af) - Added as_dict to PlaceInfo [`8c4fe40`](https://github.com/RhetTbull/osxphotos/commit/8c4fe40aa6850f166e526cffaa088550884399af)
- Updated README.md [`11d368a`](https://github.com/RhetTbull/osxphotos/commit/11d368a69cbe67e909e64b020f0334fc09dd3ac4) - Updated README.md [`11d368a`](https://github.com/RhetTbull/osxphotos/commit/11d368a69cbe67e909e64b020f0334fc09dd3ac4)
- Updated CHANGELOG.md [`cafa483`](https://github.com/RhetTbull/osxphotos/commit/cafa483cfc228c651a03d3361d6d48a35deab1e8)
- version bump [`c06c230`](https://github.com/RhetTbull/osxphotos/commit/c06c230a469754691d11fff1034fb02daeeba649) - version bump [`c06c230`](https://github.com/RhetTbull/osxphotos/commit/c06c230a469754691d11fff1034fb02daeeba649)
- Test library update [`f416418`](https://github.com/RhetTbull/osxphotos/commit/f416418546a12bc6c1bda13f6b712758584d06dc)
#### [v0.28.19](https://github.com/RhetTbull/osxphotos/compare/v0.28.18...v0.28.19) #### [v0.28.19](https://github.com/RhetTbull/osxphotos/compare/v0.28.18...v0.28.19)
@@ -58,16 +196,15 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added label and label_normalized to template system, closes #130 [`#130`](https://github.com/RhetTbull/osxphotos/issues/130) - Added label and label_normalized to template system, closes #130 [`#130`](https://github.com/RhetTbull/osxphotos/issues/130)
- Revert "test library updates" [`48e9c32`](https://github.com/RhetTbull/osxphotos/commit/48e9c32add549e66c3ef8c65f8821f5033b55b11) - Revert "test library updates" [`48e9c32`](https://github.com/RhetTbull/osxphotos/commit/48e9c32add549e66c3ef8c65f8821f5033b55b11)
- test library updates [`d125854`](https://github.com/RhetTbull/osxphotos/commit/d125854f2a04e37747af3e0796370a565c1c9bd0) - test library updates [`d125854`](https://github.com/RhetTbull/osxphotos/commit/d125854f2a04e37747af3e0796370a565c1c9bd0)
- Updated CHANGELOG.md [`e228cfa`](https://github.com/RhetTbull/osxphotos/commit/e228cfab746055c8d6df428aebe0ed001fb6d4d0)
- version bump [`bd9d5a2`](https://github.com/RhetTbull/osxphotos/commit/bd9d5a26f3bfcbb33896a139fa86cdab46768103) - version bump [`bd9d5a2`](https://github.com/RhetTbull/osxphotos/commit/bd9d5a26f3bfcbb33896a139fa86cdab46768103)
- Update README.md [`85760dc`](https://github.com/RhetTbull/osxphotos/commit/85760dc4fe2274d826ed80494fd4e66866398609) - Update README.md [`85760dc`](https://github.com/RhetTbull/osxphotos/commit/85760dc4fe2274d826ed80494fd4e66866398609)
- Update README.md [`be07f90`](https://github.com/RhetTbull/osxphotos/commit/be07f90e5a8179e452730ea654e4c9627b1f6ebc)
#### [v0.28.18](https://github.com/RhetTbull/osxphotos/compare/v0.28.17...v0.28.18) #### [v0.28.18](https://github.com/RhetTbull/osxphotos/compare/v0.28.17...v0.28.18)
> 14 May 2020 > 14 May 2020
- Implemented PhotoInfo.exiftool [`a80dee4`](https://github.com/RhetTbull/osxphotos/commit/a80dee401c7eb959f6ad6d93a3272657ed28f521) - Implemented PhotoInfo.exiftool [`a80dee4`](https://github.com/RhetTbull/osxphotos/commit/a80dee401c7eb959f6ad6d93a3272657ed28f521)
- Updated CHANGELOG.md [`e67fce2`](https://github.com/RhetTbull/osxphotos/commit/e67fce28714cf4065b64202bb3b149ba5bec5be4)
#### [v0.28.17](https://github.com/RhetTbull/osxphotos/compare/v0.28.15...v0.28.17) #### [v0.28.17](https://github.com/RhetTbull/osxphotos/compare/v0.28.15...v0.28.17)
@@ -84,8 +221,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- added --export-as-hardlink option [`#126`](https://github.com/RhetTbull/osxphotos/pull/126) - added --export-as-hardlink option [`#126`](https://github.com/RhetTbull/osxphotos/pull/126)
- Added test for folder_names on 10.15.4, closes #119 [`#119`](https://github.com/RhetTbull/osxphotos/issues/119) - Added test for folder_names on 10.15.4, closes #119 [`#119`](https://github.com/RhetTbull/osxphotos/issues/119)
- Refactored photosdb and photoinfo to add SearchInfo and labels [`98b3f63`](https://github.com/RhetTbull/osxphotos/commit/98b3f63a92aa2105f8fa97af992fc6fe2d78b973) - Refactored photosdb and photoinfo to add SearchInfo and labels [`98b3f63`](https://github.com/RhetTbull/osxphotos/commit/98b3f63a92aa2105f8fa97af992fc6fe2d78b973)
- added --export-as-hardlink option [`5eb0876`](https://github.com/RhetTbull/osxphotos/commit/5eb0876e331beb020431bb037dee75fb7ae61c85)
- Added additional test for --export-as-hardlink [`57315d4`](https://github.com/RhetTbull/osxphotos/commit/57315d44497fde977956f76f667470208f11aa2d) - Added additional test for --export-as-hardlink [`57315d4`](https://github.com/RhetTbull/osxphotos/commit/57315d44497fde977956f76f667470208f11aa2d)
- added CHANGELOG.md [`00e1661`](https://github.com/RhetTbull/osxphotos/commit/00e16611fc86c05fb090d036084db9eb42444071)
- Updated a couple of tests to use pytest-mock [`397db0d`](https://github.com/RhetTbull/osxphotos/commit/397db0d72fb218669a9ecbff134fa9b392a14661) - Updated a couple of tests to use pytest-mock [`397db0d`](https://github.com/RhetTbull/osxphotos/commit/397db0d72fb218669a9ecbff134fa9b392a14661)
- added test for export using hardlinks, fixed a test that failed if users locale settings were different to en_US [`b0ec6c6`](https://github.com/RhetTbull/osxphotos/commit/b0ec6c6b36d8cfe05723d47b210d9d7c5aabdfe5) - added test for export using hardlinks, fixed a test that failed if users locale settings were different to en_US [`b0ec6c6`](https://github.com/RhetTbull/osxphotos/commit/b0ec6c6b36d8cfe05723d47b210d9d7c5aabdfe5)
@@ -109,7 +246,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 28 April 2020 > 28 April 2020
- Fixed implementation of use_albums_as_keywords and use_persons_as_keywords, closes #115 [`#115`](https://github.com/RhetTbull/osxphotos/issues/115) - Fixed implementation of use_albums_as_keywords and use_persons_as_keywords, closes #115 [`#115`](https://github.com/RhetTbull/osxphotos/issues/115)
- Updated CHANGELOG.md [`072a8d7`](https://github.com/RhetTbull/osxphotos/commit/072a8d795e5e15fa8ca8d8872aecf4cddd7837f7)
- Update README.md [`5cc98c3`](https://github.com/RhetTbull/osxphotos/commit/5cc98c338bcc19fd05bf293eb3afe24c07c8b380) - Update README.md [`5cc98c3`](https://github.com/RhetTbull/osxphotos/commit/5cc98c338bcc19fd05bf293eb3afe24c07c8b380)
- Updated README.md [`a800711`](https://github.com/RhetTbull/osxphotos/commit/a80071111f810a1d7d6e2d735839e85499091ea4) - Updated README.md [`a800711`](https://github.com/RhetTbull/osxphotos/commit/a80071111f810a1d7d6e2d735839e85499091ea4)
- Update README.md [`1c9d4f2`](https://github.com/RhetTbull/osxphotos/commit/1c9d4f282beea2ac12273c8d0f9453bad1255c2c) - Update README.md [`1c9d4f2`](https://github.com/RhetTbull/osxphotos/commit/1c9d4f282beea2ac12273c8d0f9453bad1255c2c)
@@ -120,7 +256,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added --album-keyword and --person-keyword to CLI, closes #61 [`#61`](https://github.com/RhetTbull/osxphotos/issues/61) - Added --album-keyword and --person-keyword to CLI, closes #61 [`#61`](https://github.com/RhetTbull/osxphotos/issues/61)
- Updated test libraries [`54d5d4b`](https://github.com/RhetTbull/osxphotos/commit/54d5d4b7ba99204f58e723231309ab6e306be28c) - Updated test libraries [`54d5d4b`](https://github.com/RhetTbull/osxphotos/commit/54d5d4b7ba99204f58e723231309ab6e306be28c)
- Updated CHANGELOG.md [`38137a1`](https://github.com/RhetTbull/osxphotos/commit/38137a1351cdb7ab72393ea03828933dac0b76b0)
- Updated tests/README.md [`56a0006`](https://github.com/RhetTbull/osxphotos/commit/56a000609f2f08d0f8800fec49cada2980c3bb9d) - Updated tests/README.md [`56a0006`](https://github.com/RhetTbull/osxphotos/commit/56a000609f2f08d0f8800fec49cada2980c3bb9d)
#### [v0.28.6](https://github.com/RhetTbull/osxphotos/compare/v0.28.5...v0.28.6) #### [v0.28.6](https://github.com/RhetTbull/osxphotos/compare/v0.28.5...v0.28.6)
@@ -128,7 +263,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 26 April 2020 > 26 April 2020
- Fixed locale bug in templates, closes #113 [`#113`](https://github.com/RhetTbull/osxphotos/issues/113) - Fixed locale bug in templates, closes #113 [`#113`](https://github.com/RhetTbull/osxphotos/issues/113)
- Updated CHANGELOG.md [`81d4e39`](https://github.com/RhetTbull/osxphotos/commit/81d4e392c39f0fe6f967a447c7d0c970bf224032) - Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`4b29a2e`](https://github.com/RhetTbull/osxphotos/commit/4b29a2e05fd1dac821d80781ae01a148d3d9c523)
- Updated test to avoid issue with GitHub workflow [`9be0f84`](https://github.com/RhetTbull/osxphotos/commit/9be0f849b73061d053d30274ff3295b79c88f0b6) - Updated test to avoid issue with GitHub workflow [`9be0f84`](https://github.com/RhetTbull/osxphotos/commit/9be0f849b73061d053d30274ff3295b79c88f0b6)
- Update pythonpackage.yml to remove older pythons [`ccb5f25`](https://github.com/RhetTbull/osxphotos/commit/ccb5f252d14e9335ae04a2e338a6d527b80c9a93) - Update pythonpackage.yml to remove older pythons [`ccb5f25`](https://github.com/RhetTbull/osxphotos/commit/ccb5f252d14e9335ae04a2e338a6d527b80c9a93)
@@ -142,7 +277,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Updated setup.py to resolve issue with bpylist2 on python < 3.8 [`8e4b88a`](https://github.com/RhetTbull/osxphotos/commit/8e4b88ad1fc18438f941e045bfc8aeac878914f9) - Updated setup.py to resolve issue with bpylist2 on python < 3.8 [`8e4b88a`](https://github.com/RhetTbull/osxphotos/commit/8e4b88ad1fc18438f941e045bfc8aeac878914f9)
- Added cli.py for use with pyinstaller [`cf28cb6`](https://github.com/RhetTbull/osxphotos/commit/cf28cb6452de17f2ef8d80435386e8d5a1aabd34) - Added cli.py for use with pyinstaller [`cf28cb6`](https://github.com/RhetTbull/osxphotos/commit/cf28cb6452de17f2ef8d80435386e8d5a1aabd34)
- added raw_is_original handling [`a337e79`](https://github.com/RhetTbull/osxphotos/commit/a337e79e13802b4824c2f088ce9db1c027d6f3c5) - added raw_is_original handling [`a337e79`](https://github.com/RhetTbull/osxphotos/commit/a337e79e13802b4824c2f088ce9db1c027d6f3c5)
- Updated CHANGELOG.md [`22f1e8f`](https://github.com/RhetTbull/osxphotos/commit/22f1e8f2a6478e0576f6bff53e348aad8680ae69) - Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`1c8eb76`](https://github.com/RhetTbull/osxphotos/commit/1c8eb764f53c3cc8b541667c858e462793ad8d1f)
#### [0.28.2](https://github.com/RhetTbull/osxphotos/compare/v0.28.1...0.28.2) #### [0.28.2](https://github.com/RhetTbull/osxphotos/compare/v0.28.1...0.28.2)
@@ -150,7 +285,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added folder support for Photos <= 4, closes #93 [`#93`](https://github.com/RhetTbull/osxphotos/issues/93) - Added folder support for Photos <= 4, closes #93 [`#93`](https://github.com/RhetTbull/osxphotos/issues/93)
- cleaned up SQL statements in _process_database4 [`6f28171`](https://github.com/RhetTbull/osxphotos/commit/6f281711e2001a63ffad076d7b9835272d5d09da) - cleaned up SQL statements in _process_database4 [`6f28171`](https://github.com/RhetTbull/osxphotos/commit/6f281711e2001a63ffad076d7b9835272d5d09da)
- Updated CHANGELOG.md [`1fa9583`](https://github.com/RhetTbull/osxphotos/commit/1fa9583ea689d54d2613a064f1ade25bcdfbf043)
- Fixed suffix check on export to be case insensitive [`4b30b3b`](https://github.com/RhetTbull/osxphotos/commit/4b30b3b4260e2c7409e18825e5b626efe646db16) - Fixed suffix check on export to be case insensitive [`4b30b3b`](https://github.com/RhetTbull/osxphotos/commit/4b30b3b4260e2c7409e18825e5b626efe646db16)
- test library update [`3bac106`](https://github.com/RhetTbull/osxphotos/commit/3bac106eb7a180e9e39643a89087d92bf2a437d0) - test library update [`3bac106`](https://github.com/RhetTbull/osxphotos/commit/3bac106eb7a180e9e39643a89087d92bf2a437d0)
@@ -168,7 +302,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added {folder_album} to template and --folder to CLI [`b7c7b9f`](https://github.com/RhetTbull/osxphotos/commit/b7c7b9f0664e69c743bdd8a228ad2936cf6b7600) - Added {folder_album} to template and --folder to CLI [`b7c7b9f`](https://github.com/RhetTbull/osxphotos/commit/b7c7b9f0664e69c743bdd8a228ad2936cf6b7600)
- Test library update [`21e7020`](https://github.com/RhetTbull/osxphotos/commit/21e7020fec406b0f3926d7adc8a1451bfe77e75a) - Test library update [`21e7020`](https://github.com/RhetTbull/osxphotos/commit/21e7020fec406b0f3926d7adc8a1451bfe77e75a)
- Updated CHANGELOG.md [`952741d`](https://github.com/RhetTbull/osxphotos/commit/952741d488d2fbbaf8a0c1d3781ad7c4205c068f)
#### [v0.27.3](https://github.com/RhetTbull/osxphotos/compare/v0.27.1...v0.27.3) #### [v0.27.3](https://github.com/RhetTbull/osxphotos/compare/v0.27.1...v0.27.3)
@@ -182,7 +315,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 12 April 2020 > 12 April 2020
- Changed AlbumInfo and FolderInfo interface to maintain backwards compatibility with PhotosDB.albums [`e09f0b4`](https://github.com/RhetTbull/osxphotos/commit/e09f0b40f1671d70ee399cdc519492b04fac8adc) - Changed AlbumInfo and FolderInfo interface to maintain backwards compatibility with PhotosDB.albums [`e09f0b4`](https://github.com/RhetTbull/osxphotos/commit/e09f0b40f1671d70ee399cdc519492b04fac8adc)
- Updated CHANGELOG.md [`b749681`](https://github.com/RhetTbull/osxphotos/commit/b749681c6d2545eacf653ab1b2a5d1384e3123eb)
#### [v0.27.0](https://github.com/RhetTbull/osxphotos/compare/v0.26.1...v0.27.0) #### [v0.27.0](https://github.com/RhetTbull/osxphotos/compare/v0.26.1...v0.27.0)
@@ -191,8 +323,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Update README.md [`#95`](https://github.com/RhetTbull/osxphotos/pull/95) - Update README.md [`#95`](https://github.com/RhetTbull/osxphotos/pull/95)
- Added tests and README for AlbumInfo and FolderInfo [`d6a22b7`](https://github.com/RhetTbull/osxphotos/commit/d6a22b765ab17f6ef1ba8c50b77946f090979968) - Added tests and README for AlbumInfo and FolderInfo [`d6a22b7`](https://github.com/RhetTbull/osxphotos/commit/d6a22b765ab17f6ef1ba8c50b77946f090979968)
- Added albuminfo.py for AlbumInfo and FolderInfo classes [`9636572`](https://github.com/RhetTbull/osxphotos/commit/96365728c2ff42abfb6828872ffac53b4c3c8024) - Added albuminfo.py for AlbumInfo and FolderInfo classes [`9636572`](https://github.com/RhetTbull/osxphotos/commit/96365728c2ff42abfb6828872ffac53b4c3c8024)
- Updated CHANGELOG.md [`cde56e9`](https://github.com/RhetTbull/osxphotos/commit/cde56e9d13baf3098ec85839cf1aaa33b4915ac9)
- Update README.md TOC [`8544667`](https://github.com/RhetTbull/osxphotos/commit/8544667c729ea0d7fe39671d909e09cda519e250) - Update README.md TOC [`8544667`](https://github.com/RhetTbull/osxphotos/commit/8544667c729ea0d7fe39671d909e09cda519e250)
- Update README.md [`1aa3838`](https://github.com/RhetTbull/osxphotos/commit/1aa3838c3866a18084ffe822de02df0eda464d71)
#### [v0.26.1](https://github.com/RhetTbull/osxphotos/compare/v0.26.0...v0.26.1) #### [v0.26.1](https://github.com/RhetTbull/osxphotos/compare/v0.26.0...v0.26.1)
@@ -200,7 +332,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Bug fix for PhotosDB.photos() query [`1c9da5e`](https://github.com/RhetTbull/osxphotos/commit/1c9da5ed6ffa21f0577906b65b7da08951725d1f) - Bug fix for PhotosDB.photos() query [`1c9da5e`](https://github.com/RhetTbull/osxphotos/commit/1c9da5ed6ffa21f0577906b65b7da08951725d1f)
- Updated test library [`d74f7f4`](https://github.com/RhetTbull/osxphotos/commit/d74f7f499bf59f37ec81cfa9d49cbbf3aafb5961) - Updated test library [`d74f7f4`](https://github.com/RhetTbull/osxphotos/commit/d74f7f499bf59f37ec81cfa9d49cbbf3aafb5961)
- Updated CHANGELOG.md [`c85bb02`](https://github.com/RhetTbull/osxphotos/commit/c85bb023042e072d6688060eb259156c2fa579b9)
#### [v0.26.0](https://github.com/RhetTbull/osxphotos/compare/v0.25.1...v0.26.0) #### [v0.26.0](https://github.com/RhetTbull/osxphotos/compare/v0.25.1...v0.26.0)
@@ -208,7 +339,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added test for 10.15.4 [`1820715`](https://github.com/RhetTbull/osxphotos/commit/182071584904d001a9b199eef5febfb79e00696e) - Added test for 10.15.4 [`1820715`](https://github.com/RhetTbull/osxphotos/commit/182071584904d001a9b199eef5febfb79e00696e)
- Changed PhotosDB albums interface as prep for adding folders [`3e50626`](https://github.com/RhetTbull/osxphotos/commit/3e5062684ab6d706d91d4abeb4e3b0ca47867b70) - Changed PhotosDB albums interface as prep for adding folders [`3e50626`](https://github.com/RhetTbull/osxphotos/commit/3e5062684ab6d706d91d4abeb4e3b0ca47867b70)
- Updated CHANGELOG.md [`a6ca3f4`](https://github.com/RhetTbull/osxphotos/commit/a6ca3f453ce0fae4e8d13c7c256ed69a16d2e3f2) - Update README.md [`626e460`](https://github.com/RhetTbull/osxphotos/commit/626e460aabb97b30af87cea2ec4f93e5fb925bec)
#### [v0.25.1](https://github.com/RhetTbull/osxphotos/compare/v0.25.0...v0.25.1) #### [v0.25.1](https://github.com/RhetTbull/osxphotos/compare/v0.25.0...v0.25.1)
@@ -227,7 +358,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added {album}, {keyword}, and {person} to template system [`507c4a3`](https://github.com/RhetTbull/osxphotos/commit/507c4a374014f999ca19789bce0df0c14332e021) - Added {album}, {keyword}, and {person} to template system [`507c4a3`](https://github.com/RhetTbull/osxphotos/commit/507c4a374014f999ca19789bce0df0c14332e021)
- Added places command to CLI [`fd5e748`](https://github.com/RhetTbull/osxphotos/commit/fd5e748dca759ea1c3a7329d447f363afe8418b7) - Added places command to CLI [`fd5e748`](https://github.com/RhetTbull/osxphotos/commit/fd5e748dca759ea1c3a7329d447f363afe8418b7)
- Updated export example [`01cd7fe`](https://github.com/RhetTbull/osxphotos/commit/01cd7fed6d7fc0c61c171a05319c211eb0a9f7c1) - Updated export example [`01cd7fe`](https://github.com/RhetTbull/osxphotos/commit/01cd7fed6d7fc0c61c171a05319c211eb0a9f7c1)
- Updated CHANGELOG.md [`daea30f`](https://github.com/RhetTbull/osxphotos/commit/daea30f1626a208209ab6854cbd3b12f4b0a3405) - Fixed typo in help text [`c02953e`](https://github.com/RhetTbull/osxphotos/commit/c02953ef5fe1aee219e0557bfd8c3322f1900a81)
#### [v0.24.2](https://github.com/RhetTbull/osxphotos/compare/v0.24.1...v0.24.2) #### [v0.24.2](https://github.com/RhetTbull/osxphotos/compare/v0.24.1...v0.24.2)
@@ -248,8 +379,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 22 March 2020 > 22 March 2020
- Added export_by_album.py to examples [`908fead`](https://github.com/RhetTbull/osxphotos/commit/908fead8a2fbcef3b4a387f34d83d88c507c5939) - Added export_by_album.py to examples [`908fead`](https://github.com/RhetTbull/osxphotos/commit/908fead8a2fbcef3b4a387f34d83d88c507c5939)
- Updated CHANGELOG.md [`072e894`](https://github.com/RhetTbull/osxphotos/commit/072e894e56c4dfe5522d073b202933fed0204ef5)
- Updated pathvalidate calls [`d066435`](https://github.com/RhetTbull/osxphotos/commit/d066435e3df4062be6a0a3d5fa7308f293e764d5) - Updated pathvalidate calls [`d066435`](https://github.com/RhetTbull/osxphotos/commit/d066435e3df4062be6a0a3d5fa7308f293e764d5)
- Updated example [`8f0307f`](https://github.com/RhetTbull/osxphotos/commit/8f0307fc24345ca0e87017ac76791c9bbe8db25e)
#### [v0.23.3](https://github.com/RhetTbull/osxphotos/compare/v0.23.1...v0.23.3) #### [v0.23.3](https://github.com/RhetTbull/osxphotos/compare/v0.23.1...v0.23.3)
@@ -264,15 +395,15 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 21 March 2020 > 21 March 2020
- Fixed requirements.txt for bplist2 [`cda5f44`](https://github.com/RhetTbull/osxphotos/commit/cda5f446933ea2272409d1f153e2a7811626ada6) - Fixed requirements.txt for bplist2 [`cda5f44`](https://github.com/RhetTbull/osxphotos/commit/cda5f446933ea2272409d1f153e2a7811626ada6)
- Updated CHANGELOG.md [`b8da976`](https://github.com/RhetTbull/osxphotos/commit/b8da9765b8949eb90852d249c2877eeb1806d987)
- Updated requirements.txt [`9da7ad6`](https://github.com/RhetTbull/osxphotos/commit/9da7ad6dcc021fdafe358d74e1c52f69dc49ade8) - Updated requirements.txt [`9da7ad6`](https://github.com/RhetTbull/osxphotos/commit/9da7ad6dcc021fdafe358d74e1c52f69dc49ade8)
- still trying to debug github actions fail [`960487f`](https://github.com/RhetTbull/osxphotos/commit/960487f2961f97f6b24d253472dcedf74dfc7797)
#### [v0.23.0](https://github.com/RhetTbull/osxphotos/compare/v0.22.23...v0.23.0) #### [v0.23.0](https://github.com/RhetTbull/osxphotos/compare/v0.22.23...v0.23.0)
> 21 March 2020 > 21 March 2020
- Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`21547a8`](https://github.com/RhetTbull/osxphotos/commit/21547a8eaad117b11bc5e4dddf95436a8244e9ba)
- Added PhotoInfo.place for reverse geolocation data [`b338b34`](https://github.com/RhetTbull/osxphotos/commit/b338b34d5055a7621e4ebe4fbbae12227d77af6d) - Added PhotoInfo.place for reverse geolocation data [`b338b34`](https://github.com/RhetTbull/osxphotos/commit/b338b34d5055a7621e4ebe4fbbae12227d77af6d)
- Updated CHANGELOG.md [`816b98e`](https://github.com/RhetTbull/osxphotos/commit/816b98e617c30d0bdb51bc2413f9915742c8592e)
- Update pythonpackage.yml [`92e5bdd`](https://github.com/RhetTbull/osxphotos/commit/92e5bdd2e986e5de2a710abf60ba0dc99c6a6730) - Update pythonpackage.yml [`92e5bdd`](https://github.com/RhetTbull/osxphotos/commit/92e5bdd2e986e5de2a710abf60ba0dc99c6a6730)
#### [v0.22.23](https://github.com/RhetTbull/osxphotos/compare/v0.22.21...v0.22.23) #### [v0.22.23](https://github.com/RhetTbull/osxphotos/compare/v0.22.21...v0.22.23)
@@ -288,7 +419,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Working on export edited bug for issue #78 [`8542e1a`](https://github.com/RhetTbull/osxphotos/commit/8542e1a97f6b640f287b37af9e50fd05f964ec4d) - Working on export edited bug for issue #78 [`8542e1a`](https://github.com/RhetTbull/osxphotos/commit/8542e1a97f6b640f287b37af9e50fd05f964ec4d)
- Fixed download-missing to only download when actually missing [`dd20b8d`](https://github.com/RhetTbull/osxphotos/commit/dd20b8d8ac3b16d3b72a26b97dcc620b11e3a7c0) - Fixed download-missing to only download when actually missing [`dd20b8d`](https://github.com/RhetTbull/osxphotos/commit/dd20b8d8ac3b16d3b72a26b97dcc620b11e3a7c0)
- Updated CHANGELOG.md [`cc9220e`](https://github.com/RhetTbull/osxphotos/commit/cc9220e0763816d784f2fd8377dfe14a99981622) - test library updates [`e99391a`](https://github.com/RhetTbull/osxphotos/commit/e99391a68e844adb63edde3efb921cffa3928aeb)
#### [v0.22.17](https://github.com/RhetTbull/osxphotos/compare/v0.22.16...v0.22.17) #### [v0.22.17](https://github.com/RhetTbull/osxphotos/compare/v0.22.16...v0.22.17)
@@ -303,18 +434,17 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- removed activate from --download-missing-photos Applescript, closes #69 [`#69`](https://github.com/RhetTbull/osxphotos/issues/69) - removed activate from --download-missing-photos Applescript, closes #69 [`#69`](https://github.com/RhetTbull/osxphotos/issues/69)
- Added media type specials to json and string output, closes #68 [`#68`](https://github.com/RhetTbull/osxphotos/issues/68) - Added media type specials to json and string output, closes #68 [`#68`](https://github.com/RhetTbull/osxphotos/issues/68)
- Fixed bug in --download-missing related to burst images [`1f13ba8`](https://github.com/RhetTbull/osxphotos/commit/1f13ba837fe36ff4eeb48cca02f5312a88a0a765)
- Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`dc87194`](https://github.com/RhetTbull/osxphotos/commit/dc87194eec252461d0cc0891b9ede4157125e828)
- Added query/export options for special media types [`2b7d84a`](https://github.com/RhetTbull/osxphotos/commit/2b7d84a4d103982ad874d875bafbc34d654d539a) - Added query/export options for special media types [`2b7d84a`](https://github.com/RhetTbull/osxphotos/commit/2b7d84a4d103982ad874d875bafbc34d654d539a)
- README.md update [`a27ce33`](https://github.com/RhetTbull/osxphotos/commit/a27ce33473df3260dfb7ed26e28295cbf87d1e78) - README.md update [`a27ce33`](https://github.com/RhetTbull/osxphotos/commit/a27ce33473df3260dfb7ed26e28295cbf87d1e78)
- Test library updates [`2d7d0b8`](https://github.com/RhetTbull/osxphotos/commit/2d7d0b86e0008cae043e314937504f36ad882990) - Test library updates [`2d7d0b8`](https://github.com/RhetTbull/osxphotos/commit/2d7d0b86e0008cae043e314937504f36ad882990)
- Fixed bug in --download-missing related to burst images [`1f13ba8`](https://github.com/RhetTbull/osxphotos/commit/1f13ba837fe36ff4eeb48cca02f5312a88a0a765)
- test library update [`acb6b9e`](https://github.com/RhetTbull/osxphotos/commit/acb6b9e72f7f6b8f4f1d64b46f270a4d3e984fef)
#### [v0.22.13](https://github.com/RhetTbull/osxphotos/compare/v0.22.12...v0.22.13) #### [v0.22.13](https://github.com/RhetTbull/osxphotos/compare/v0.22.12...v0.22.13)
> 8 March 2020 > 8 March 2020
- Added media type specials, closes #60 [`#60`](https://github.com/RhetTbull/osxphotos/issues/60) - Added media type specials, closes #60 [`#60`](https://github.com/RhetTbull/osxphotos/issues/60)
- Updated CHANGELOG.md [`08a9793`](https://github.com/RhetTbull/osxphotos/commit/08a9793651481e1984a4482794ffedd48e4367a2)
- Updated README.md [`1f8fd6e`](https://github.com/RhetTbull/osxphotos/commit/1f8fd6e929cc0edd3dd2f222416454d26955bf2a) - Updated README.md [`1f8fd6e`](https://github.com/RhetTbull/osxphotos/commit/1f8fd6e929cc0edd3dd2f222416454d26955bf2a)
#### [v0.22.12](https://github.com/RhetTbull/osxphotos/compare/0.22.10...v0.22.12) #### [v0.22.12](https://github.com/RhetTbull/osxphotos/compare/0.22.10...v0.22.12)
@@ -331,7 +461,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Fixed bug in --download-missing to fix issue #64 [`c654e3d`](https://github.com/RhetTbull/osxphotos/commit/c654e3dc61283382b37b6892dab1516ec517143a) - Fixed bug in --download-missing to fix issue #64 [`c654e3d`](https://github.com/RhetTbull/osxphotos/commit/c654e3dc61283382b37b6892dab1516ec517143a)
- removed commented out code [`69addc3`](https://github.com/RhetTbull/osxphotos/commit/69addc34649f992c6a4a0e0e334754a72530f0ba) - removed commented out code [`69addc3`](https://github.com/RhetTbull/osxphotos/commit/69addc34649f992c6a4a0e0e334754a72530f0ba)
- Updated CHANGELOG.md [`1e013b6`](https://github.com/RhetTbull/osxphotos/commit/1e013b6802e49e26ec5a94eb702e841b2eb68395) - Cleaned up comments and unneeded test code [`e3c40bc`](https://github.com/RhetTbull/osxphotos/commit/e3c40bcbaaf3560d53091cf46ed851d90ff82cfa)
#### [v0.22.9](https://github.com/RhetTbull/osxphotos/compare/v0.22.7...v0.22.9) #### [v0.22.9](https://github.com/RhetTbull/osxphotos/compare/v0.22.7...v0.22.9)
@@ -343,7 +473,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Test library updates [`6e563e2`](https://github.com/RhetTbull/osxphotos/commit/6e563e214c569ba7838f7464de9258c3bba5db23) - Test library updates [`6e563e2`](https://github.com/RhetTbull/osxphotos/commit/6e563e214c569ba7838f7464de9258c3bba5db23)
- Removed _tmp_file code that's no longer needed [`27994c9`](https://github.com/RhetTbull/osxphotos/commit/27994c9fd372303833a5794f1de9815f425c762e) - Removed _tmp_file code that's no longer needed [`27994c9`](https://github.com/RhetTbull/osxphotos/commit/27994c9fd372303833a5794f1de9815f425c762e)
- Updated photos_repl.py [`fdf636a`](https://github.com/RhetTbull/osxphotos/commit/fdf636ac8864ebb2cc324b1f9d3c6c82ee3910f9) - Updated photos_repl.py [`fdf636a`](https://github.com/RhetTbull/osxphotos/commit/fdf636ac8864ebb2cc324b1f9d3c6c82ee3910f9)
- Updated CHANGELOG.md [`f910124`](https://github.com/RhetTbull/osxphotos/commit/f910124fe1fbf75d44c09c79607374bf000733a1) - Added PhotosDB() behavior to open last library if no args passed but also added cautionary note to README [`46d3c7d`](https://github.com/RhetTbull/osxphotos/commit/46d3c7dbdaf848d5c340ce8a362ff296a36c552d)
#### [v0.22.7](https://github.com/RhetTbull/osxphotos/compare/v0.22.4...v0.22.7) #### [v0.22.7](https://github.com/RhetTbull/osxphotos/compare/v0.22.4...v0.22.7)
@@ -357,7 +487,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Added date_modified to PhotoInfo [`67b0ae0`](https://github.com/RhetTbull/osxphotos/commit/67b0ae0bf679815372d415c3064e21d46a5b8718) - Added date_modified to PhotoInfo [`67b0ae0`](https://github.com/RhetTbull/osxphotos/commit/67b0ae0bf679815372d415c3064e21d46a5b8718)
- Added date_modified to PhotoInfo [`4d36b3b`](https://github.com/RhetTbull/osxphotos/commit/4d36b3b31f3e0e74d9d111b6b691771e19f94086) - Added date_modified to PhotoInfo [`4d36b3b`](https://github.com/RhetTbull/osxphotos/commit/4d36b3b31f3e0e74d9d111b6b691771e19f94086)
- Updated CLI options with more descriptive metavar names [`e79cb92`](https://github.com/RhetTbull/osxphotos/commit/e79cb92693758c984dc789d5fa5d2e87e381e921) - Updated CLI options with more descriptive metavar names [`e79cb92`](https://github.com/RhetTbull/osxphotos/commit/e79cb92693758c984dc789d5fa5d2e87e381e921)
- CLI now looks for photos library to use if non specified by user [`50b7e69`](https://github.com/RhetTbull/osxphotos/commit/50b7e6920a694aa45f478d1131868525c9147919) - Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`898d3af`](https://github.com/RhetTbull/osxphotos/commit/898d3afc0892546ece6c3d675208dea216e20633)
#### [v0.22.4](https://github.com/RhetTbull/osxphotos/compare/v0.22.0...v0.22.4) #### [v0.22.4](https://github.com/RhetTbull/osxphotos/compare/v0.22.0...v0.22.4)
@@ -369,7 +499,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Implement from_date and to_date in PhotosDB as well as query and export command. Some refactoring of CLI as well. [`cfa2b4a`](https://github.com/RhetTbull/osxphotos/commit/cfa2b4a828facf0aff5bc19f777457ad776c4a05) - Implement from_date and to_date in PhotosDB as well as query and export command. Some refactoring of CLI as well. [`cfa2b4a`](https://github.com/RhetTbull/osxphotos/commit/cfa2b4a828facf0aff5bc19f777457ad776c4a05)
- Refactored _query. Still hairy, but less so. [`b9dee49`](https://github.com/RhetTbull/osxphotos/commit/b9dee4995c6d89fadb3d2482374b7098f2ab5ed9) - Refactored _query. Still hairy, but less so. [`b9dee49`](https://github.com/RhetTbull/osxphotos/commit/b9dee4995c6d89fadb3d2482374b7098f2ab5ed9)
- Updated README.md [`0aff83f`](https://github.com/RhetTbull/osxphotos/commit/0aff83ff21c20e293c0b75bacf2863090a0fb725) - Updated README.md [`0aff83f`](https://github.com/RhetTbull/osxphotos/commit/0aff83ff21c20e293c0b75bacf2863090a0fb725)
- Started adding tests for CLI [`f0b18c3`](https://github.com/RhetTbull/osxphotos/commit/f0b18c3d29b2141d348be0495013c51c072c6251) - Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`7150956`](https://github.com/RhetTbull/osxphotos/commit/7150956a488677d402a6d43443d04c4b11dc7be0)
#### [v0.22.0](https://github.com/RhetTbull/osxphotos/compare/v0.21.5...v0.22.0) #### [v0.22.0](https://github.com/RhetTbull/osxphotos/compare/v0.21.5...v0.22.0)
@@ -377,7 +507,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Refactored PhotosDB and CLI to require explicity passing the database to avoid non-deterministic behavior when last database can't be found. This may break existing code. [`ede56ff`](https://github.com/RhetTbull/osxphotos/commit/ede56ffc31cf98811b3d4d16e22406ac0eae0315) - Refactored PhotosDB and CLI to require explicity passing the database to avoid non-deterministic behavior when last database can't be found. This may break existing code. [`ede56ff`](https://github.com/RhetTbull/osxphotos/commit/ede56ffc31cf98811b3d4d16e22406ac0eae0315)
- Changed get_system_library_path to return None if could not get system library [`646ea4f`](https://github.com/RhetTbull/osxphotos/commit/646ea4f24ca1119b27280af1445e31adcd0690f0) - Changed get_system_library_path to return None if could not get system library [`646ea4f`](https://github.com/RhetTbull/osxphotos/commit/646ea4f24ca1119b27280af1445e31adcd0690f0)
- Updated CHANGELOG.md [`bd20388`](https://github.com/RhetTbull/osxphotos/commit/bd20388778dfa645277029601c63fc9835b7a406) - Fix to setup to specify versions of required packages [`de05323`](https://github.com/RhetTbull/osxphotos/commit/de05323a153fe49723b39e48b9038c1fb9535a72)
#### [v0.21.5](https://github.com/RhetTbull/osxphotos/compare/v0.21.0...v0.21.5) #### [v0.21.5](https://github.com/RhetTbull/osxphotos/compare/v0.21.0...v0.21.5)
@@ -392,8 +522,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 4 January 2020 > 4 January 2020
- Added live photo support for both Photos 4 & 5 [`d5eaff0`](https://github.com/RhetTbull/osxphotos/commit/d5eaff02f2a29a9d105ab72e9a9aeffbc9a3425b) - Added live photo support for both Photos 4 & 5 [`d5eaff0`](https://github.com/RhetTbull/osxphotos/commit/d5eaff02f2a29a9d105ab72e9a9aeffbc9a3425b)
- Added support for burst photos; added export-bursts to CLI [`593983a`](https://github.com/RhetTbull/osxphotos/commit/593983a09940e67fb9347bf345cfd7289465fa0a)
- Added live-photo option to CLI query and export [`6f6d37c`](https://github.com/RhetTbull/osxphotos/commit/6f6d37ceacf71a52a2c0216f0ad75afee244946a) - Added live-photo option to CLI query and export [`6f6d37c`](https://github.com/RhetTbull/osxphotos/commit/6f6d37ceacf71a52a2c0216f0ad75afee244946a)
- Initial support for live photos (Photos 5 only) [`1a89a18`](https://github.com/RhetTbull/osxphotos/commit/1a89a18a011a25616d7a18fb9bf1270b0b206fb4)
#### [v0.20.0](https://github.com/RhetTbull/osxphotos/compare/v0.19.0...v0.20.0) #### [v0.20.0](https://github.com/RhetTbull/osxphotos/compare/v0.19.0...v0.20.0)
@@ -407,9 +537,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
> 29 December 2019 > 29 December 2019
- Merge branch 'master' of https://github.com/RhetTbull/osxphotos [`51843fb`](https://github.com/RhetTbull/osxphotos/commit/51843fb46d6ce69456400271c97aa642466d5719)
- Added support for movies for Photos 5; fixed bugs in ismissing and path [`6f4d129`](https://github.com/RhetTbull/osxphotos/commit/6f4d129f07046c4a34d3d6cf6854c8514a594781) - Added support for movies for Photos 5; fixed bugs in ismissing and path [`6f4d129`](https://github.com/RhetTbull/osxphotos/commit/6f4d129f07046c4a34d3d6cf6854c8514a594781)
- Added support for movies for Photos 5; fixed bugs in ismissing and path [`b030966`](https://github.com/RhetTbull/osxphotos/commit/b030966051af93be380ff967ac047bf566e5d817) - Added support for movies for Photos 5; fixed bugs in ismissing and path [`b030966`](https://github.com/RhetTbull/osxphotos/commit/b030966051af93be380ff967ac047bf566e5d817)
- Initial support for movies [`dbe363e`](https://github.com/RhetTbull/osxphotos/commit/dbe363e4d754253a0405fb1df045677e8780d630)
#### [v0.18.0](https://github.com/RhetTbull/osxphotos/compare/v0.15.1...v0.18.0) #### [v0.18.0](https://github.com/RhetTbull/osxphotos/compare/v0.15.1...v0.18.0)
@@ -423,11 +553,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Moved PhotosDB attributes to properties instead of methods [`d95acdf`](https://github.com/RhetTbull/osxphotos/commit/d95acdf9f8764a1720bcba71a6dad29bf668eaf9) - Moved PhotosDB attributes to properties instead of methods [`d95acdf`](https://github.com/RhetTbull/osxphotos/commit/d95acdf9f8764a1720bcba71a6dad29bf668eaf9)
- changed interface for export, prepped for exiftool_json_sidecar [`1fe8859`](https://github.com/RhetTbull/osxphotos/commit/1fe885962e8a9a420e776bdd3dc640ca143224b2) - changed interface for export, prepped for exiftool_json_sidecar [`1fe8859`](https://github.com/RhetTbull/osxphotos/commit/1fe885962e8a9a420e776bdd3dc640ca143224b2)
#### [v0.15.1](https://github.com/RhetTbull/osxphotos/compare/v0.15.0...v0.15.1) #### [v0.15.1](https://github.com/RhetTbull/osxphotos/compare/v0.14.21...v0.15.1)
> 31 May 2020
#### [v0.15.0](https://github.com/RhetTbull/osxphotos/compare/v0.14.21...v0.15.0)
> 14 December 2019 > 14 December 2019

212
README.md
View File

@@ -17,6 +17,7 @@
+ [AlbumInfo](#albuminfo) + [AlbumInfo](#albuminfo)
+ [FolderInfo](#folderinfo) + [FolderInfo](#folderinfo)
+ [PlaceInfo](#placeinfo) + [PlaceInfo](#placeinfo)
+ [ScoreInfo](#scoreinfo)
+ [Template Substitutions](#template-substitutions) + [Template Substitutions](#template-substitutions)
+ [Utility Functions](#utility-functions) + [Utility Functions](#utility-functions)
* [Examples](#examples) * [Examples](#examples)
@@ -34,7 +35,7 @@ OSXPhotos provides the ability to interact with and query Apple's Photos.app lib
## Supported operating systems ## Supported operating systems
Only works on MacOS (aka Mac OS X). Tested on MacOS 10.12.6 / Photos 2.0, 10.13.6 / Photos 3.0, MacOS 10.14.5, 10.14.6 / Photos 4.0, MacOS 10.15.1 & 10.15.4 / Photos 5.0. Only works on MacOS (aka Mac OS X). Tested on MacOS 10.12.6 / Photos 2.0, 10.13.6 / Photos 3.0, MacOS 10.14.5, 10.14.6 / Photos 4.0, MacOS 10.15.1 - 10.15.5 / Photos 5.0.
Requires python >= 3.8. You can probably get this to run with Python 3.6 or 3.7 (see notes [below](#Installation-instructions)) but only 3.8+ is officially supported. Requires python >= 3.8. You can probably get this to run with Python 3.6 or 3.7 (see notes [below](#Installation-instructions)) but only 3.8+ is officially supported.
@@ -59,7 +60,7 @@ You can also install directly from [pypi](https://pypi.org/) but you must use py
This package will install a command line utility called `osxphotos` that allows you to query the Photos database. Alternatively, you can also run the command line utility like this: `python3 -m osxphotos` This package will install a command line utility called `osxphotos` that allows you to query the Photos database. Alternatively, you can also run the command line utility like this: `python3 -m osxphotos`
If you only care about the command line tool, I recommend installing with [pipx](https://github.com/pipxproject/pipx) If you only care about the command line tool, you can download an executable of the latest [release](https://github.com/RhetTbull/osxphotos/releases). Alternatively, I recommend installing with [pipx](https://github.com/pipxproject/pipx)
After installing pipx: After installing pipx:
`pipx install osxphotos` `pipx install osxphotos`
@@ -90,6 +91,7 @@ Commands:
help Print help; for help on commands: help <command>. help Print help; for help on commands: help <command>.
info Print out descriptive info of the Photos library database. info Print out descriptive info of the Photos library database.
keywords Print out keywords found in the Photos library. keywords Print out keywords found in the Photos library.
labels Print out image classification labels found in the Photos...
list Print list of Photos libraries found on the system. list Print list of Photos libraries found on the system.
persons Print out persons (faces) found in the Photos library. persons Print out persons (faces) found in the Photos library.
places Print out places found in the Photos library. places Print out places found in the Photos library.
@@ -125,13 +127,13 @@ Options:
-V, --verbose Print verbose output. -V, --verbose Print verbose output.
--keyword KEYWORD Search for photos with keyword KEYWORD. If --keyword KEYWORD Search for photos with keyword KEYWORD. If
more than one keyword, treated as "OR", e.g. more than one keyword, treated as "OR", e.g.
find photos match any keyword find photos matching any keyword
--person PERSON Search for photos with person PERSON. If --person PERSON Search for photos with person PERSON. If
more than one person, treated as "OR", e.g. more than one person, treated as "OR", e.g.
find photos match any person find photos matching any person
--album ALBUM Search for photos in album ALBUM. If more --album ALBUM Search for photos in album ALBUM. If more
than one album, treated as "OR", e.g. find than one album, treated as "OR", e.g. find
photos match any album photos matching any album
--folder FOLDER Search for photos in an album in folder --folder FOLDER Search for photos in an album in folder
FOLDER. If more than one folder, treated as FOLDER. If more than one folder, treated as
"OR", e.g. find photos in any FOLDER. Only "OR", e.g. find photos in any FOLDER. Only
@@ -146,11 +148,15 @@ Options:
geolocation info geolocation info
--no-place Search for photos with no associated place --no-place Search for photos with no associated place
name info (no reverse geolocation info) name info (no reverse geolocation info)
--label LABEL Search for photos with image classification
label LABEL (Photos 5 only). If more than
one label, treated as "OR", e.g. find photos
matching any label
--uti UTI Search for photos whose uniform type --uti UTI Search for photos whose uniform type
identifier (UTI) matches UTI identifier (UTI) matches UTI
-i, --ignore-case Case insensitive search for title, -i, --ignore-case Case insensitive search for title,
description, or place. Does not apply to description, place, keyword, person, or
keyword, person, or album. album.
--edited Search for photos that have been edited. --edited Search for photos that have been edited.
--external-edit Search for photos edited in external editor. --external-edit Search for photos edited in external editor.
--favorite Search for photos marked favorite. --favorite Search for photos marked favorite.
@@ -201,6 +207,10 @@ Options:
Search by end item date, e.g. Search by end item date, e.g.
2000-01-12T12:00:00 or 2000-12-31 (ISO 8601 2000-01-12T12:00:00 or 2000-12-31 (ISO 8601
w/o TZ). w/o TZ).
--deleted Include photos from the 'Recently Deleted'
folder.
--deleted-only Include only photos from the 'Recently
Deleted' folder.
--update Only export new or updated files. See notes --update Only export new or updated files. See notes
below on export and --update. below on export and --update.
--dry-run Dry run (test) the export but don't actually --dry-run Dry run (test) the export but don't actually
@@ -243,6 +253,16 @@ Options:
--keyword-template "{folder_album}" --keyword-template "{folder_album}"
--keyword-template "{created.year}" See --keyword-template "{created.year}" See
Templating System below. Templating System below.
--description-template TEMPLATE
For use with --exiftool, --sidecar; specify
a template string to use as description in
the form '{name,DEFAULT}' This is the same
format as --directory. For example, if you
wanted to append 'exported with osxphotos on
[today's date]' to the description, you
could specify --description-template
"{descr} exported with osxphotos on
{today.date}" See Templating System below.
--current-name Use photo's current filename instead of --current-name Use photo's current filename instead of
original filename for export. Note: original filename for export. Note:
Starting with Photos 5, all photos are Starting with Photos 5, all photos are
@@ -367,7 +387,8 @@ contain a brace symbol ('{' or '}').
If you do not specify a default value and the template substitution has no If you do not specify a default value and the template substitution has no
value, '_' (underscore) will be used as the default value. For example, in the value, '_' (underscore) will be used as the default value. For example, in the
above example, this would result in '2020/_/photoname.jpg' if address was null. above example, this would result in '2020/_/photoname.jpg' if address was
null.
Substitution Description Substitution Description
{name} Current filename of the photo {name} Current filename of the photo
@@ -391,6 +412,18 @@ Substitution Description
creation time creation time
{created.doy} 3-digit day of year (e.g Julian day) of file {created.doy} 3-digit day of year (e.g Julian day) of file
creation time, starting from 1 (zero padded) creation time, starting from 1 (zero padded)
{created.hour} 2-digit hour of the file creation time
{created.min} 2-digit minute of the file creation time
{created.sec} 2-digit second of the file creation time
{created.strftime} Apply strftime template to file creation
date/time. Should be used in form
{created.strftime,TEMPLATE} where TEMPLATE
is a valid strftime template, e.g.
{created.strftime,%Y-%U} would result in
year-week number of year: '2020-23'. If used
with no template will return null value. See
https://strftime.org/ for help on strftime
templates.
{modified.date} Photo's modification date in ISO format, {modified.date} Photo's modification date in ISO format,
e.g. '2020-03-22' e.g. '2020-03-22'
{modified.year} 4-digit year of file modification time {modified.year} 4-digit year of file modification time
@@ -406,6 +439,37 @@ Substitution Description
{modified.doy} 3-digit day of year (e.g Julian day) of file {modified.doy} 3-digit day of year (e.g Julian day) of file
modification time, starting from 1 (zero modification time, starting from 1 (zero
padded) padded)
{modified.hour} 2-digit hour of the file modification time
{modified.min} 2-digit minute of the file modification time
{modified.sec} 2-digit second of the file modification time
{today.date} Current date in iso format, e.g.
'2020-03-22'
{today.year} 4-digit year of current date
{today.yy} 2-digit year of current date
{today.mm} 2-digit month of the current date (zero
padded)
{today.month} Month name in user's locale of the current
date
{today.mon} Month abbreviation in the user's locale of
the current date
{today.dd} 2-digit day of the month (zero padded) of
current date
{today.dow} Day of week in user's locale of the current
date
{today.doy} 3-digit day of year (e.g Julian day) of
current date, starting from 1 (zero padded)
{today.hour} 2-digit hour of the current date
{today.min} 2-digit minute of the current date
{today.sec} 2-digit second of the current date
{today.strftime} Apply strftime template to current
date/time. Should be used in form
{today.strftime,TEMPLATE} where TEMPLATE is
a valid strftime template, e.g.
{today.strftime,%Y-%U} would result in year-
week number of year: '2020-23'. If used with
no template will return null value. See
https://strftime.org/ for help on strftime
templates.
{place.name} Place name from the photo's reverse {place.name} Place name from the photo's reverse
geolocation data, as displayed in Photos geolocation data, as displayed in Photos
{place.country_code} The ISO country code from the photo's {place.country_code} The ISO country code from the photo's
@@ -470,6 +534,10 @@ Example: export photos to file structure based on 4-digit year and full name of
`osxphotos export ~/Desktop/export --directory "{created.year}/{created.month}"` `osxphotos export ~/Desktop/export --directory "{created.year}/{created.month}"`
Example: export default library using 'country name/year' as output directory (but use "NoCountry/year" if country not specified), add persons, album names, and year as keywords, write exif metadata to files when exporting, update only changed files, print verbose ouput
`osxphotos export ~/Desktop/export --directory "{place.name.country,NoCountry}/{created.year}" --person-keyword --album-keyword --keyword-template "{created.year}" --exiftool --update --verbose`
## Example uses of the package ## Example uses of the package
@@ -807,8 +875,25 @@ photosdb.db_version
Returns the version number for Photos library database. You likely won't need this but it's provided in case needed for debugging. PhotosDB will print a warning to `sys.stderr` if you open a database version that has not been tested. Returns the version number for Photos library database. You likely won't need this but it's provided in case needed for debugging. PhotosDB will print a warning to `sys.stderr` if you open a database version that has not been tested.
#### `get_db_connection()`
Returns tuple of (connection, cursor) for the working copy of the Photos database. This is useful for debugging or prototyping new features.
#### ` photos(keywords=None, uuid=None, persons=None, albums=None, images=True, movies=False, from_date=None, to_date=None)` ```python
photosdb = osxphotos.PhotosDB()
conn, cursor = photosdb.get_db_connection()
results = conn.execute(
"SELECT ZUUID FROM ZGENERICASSET WHERE ZFAVORITE = 1;"
).fetchall()
for row in results:
# do something
pass
conn.close()
```
#### ` photos(keywords=None, uuid=None, persons=None, albums=None, images=True, movies=True, from_date=None, to_date=None, intrash=False)`
```python ```python
# assumes photosdb is a PhotosDB object (see above) # assumes photosdb is a PhotosDB object (see above)
@@ -829,7 +914,8 @@ photos = photosdb.photos(
images = bool, images = bool,
movies = bool, movies = bool,
from_date = datetime.datetime, from_date = datetime.datetime,
to_date = datetime.datetime to_date = datetime.datetime,
intrash = bool,
) )
``` ```
@@ -838,9 +924,10 @@ photos = photosdb.photos(
- ```persons```: list of one or more persons. Returns only photos containing the person(s). If more than one person provided, returns photos that match any of the persons (e.g. treated as "or") - ```persons```: list of one or more persons. Returns only photos containing the person(s). If more than one person provided, returns photos that match any of the persons (e.g. treated as "or")
- ```albums```: list of one or more album names. Returns only photos contained in the album(s). If more than one album name is provided, returns photos contained in any of the albums (.e.g. treated as "or") - ```albums```: list of one or more album names. Returns only photos contained in the album(s). If more than one album name is provided, returns photos contained in any of the albums (.e.g. treated as "or")
- ```images```: bool; if True, returns photos/images; default is True - ```images```: bool; if True, returns photos/images; default is True
- ```movies```: bool; if True, returns movies/videos; default is False - ```movies```: bool; if True, returns movies/videos; default is True
- ```from_date```: datetime.datetime; if provided, finds photos where creation date >= from_date; default is None - ```from_date```: datetime.datetime; if provided, finds photos where creation date >= from_date; default is None
- ```to_date```: datetime.datetime; if provided, finds photos where creation date <= to_date; default is None - ```to_date```: datetime.datetime; if provided, finds photos where creation date <= to_date; default is None
- ```intrash```: if True, finds only photos in the "Recently Deleted" or trash folder, if False does not find any photos in the trash; default is False
If more than one of (keywords, uuid, persons, albums,from_date, to_date) is provided, they are treated as "and" criteria. E.g. If more than one of (keywords, uuid, persons, albums,from_date, to_date) is provided, they are treated as "and" criteria. E.g.
@@ -883,15 +970,11 @@ photos2 = photosdb.photos(keywords=["Kids"])
photos3 = [p for p in photos2 if p not in photos1] photos3 = [p for p in photos2 if p not in photos1]
``` ```
By default, photos() only returns images, not movies. To also get movies, pass movies=True:
```python
photos_and_movies = photosdb.photos(movies=True)
```
To get only movies: To get only movies:
```python ```python
movies = photosdb.photos(images=False, movies=True) movies = photosdb.photos(images=False, movies=True)
``` ```
**Note** PhotosDB.photos() may return a different number of photos than Photos.app reports in the GUI. This is because photos() returns [hidden](#hidden) photos, [shared](#shared) photos, and for [burst](#burst) photos, all selected burst images even if non-selected burst images have not been deleted. Photos only reports 1 single photo for each set of burst images until you "finalize" the burst by selecting key photos and deleting the others using the "Make a selection" option. **Note** PhotosDB.photos() may return a different number of photos than Photos.app reports in the GUI. This is because photos() returns [hidden](#hidden) photos, [shared](#shared) photos, and for [burst](#burst) photos, all selected burst images even if non-selected burst images have not been deleted. Photos only reports 1 single photo for each set of burst images until you "finalize" the burst by selecting key photos and deleting the others using the "Make a selection" option.
For example, in my library, Photos says I have 19,386 photos and 474 movies. However, PhotosDB.photos() reports 25,002 photos. The difference is due to 5,609 shared photos and 7 hidden photos. (*Note* Shared photos only valid for Photos 5). Similarly, filtering for just movies returns 625 results. The difference between 625 and 474 reported by Photos is due to 151 shared movies. For example, in my library, Photos says I have 19,386 photos and 474 movies. However, PhotosDB.photos() reports 25,002 photos. The difference is due to 5,609 shared photos and 7 hidden photos. (*Note* Shared photos only valid for Photos 5). Similarly, filtering for just movies returns 625 results. The difference between 625 and 474 reported by Photos is due to 151 shared movies.
@@ -965,6 +1048,27 @@ Returns the absolute path to the edited photo on disk as a string. If the photo
**Note**: will also return None if the edited photo is missing on disk. **Note**: will also return None if the edited photo is missing on disk.
#### `height`
Returns height of the photo in pixels. If image has been edited, returns height of the edited image, otherwise returns height of the original image. See also [original_height](#original_height).
#### `width`
Returns width of the photo in pixels. If image has been edited, returns width of the edited image, otherwise returns width of the original image. See also [original_width](#original_width).
#### `orientation`
Returns EXIF orientation value of the photo as integer. If image has been edited, returns orientation of the edited image, otherwise returns orientation of the original image. See also [original_orientation](#original_orientation).
#### `original_height`
Returns height of the original photo in pixels. See also [height](#height).
#### `original_width`
Returns width of the original photo in pixels. See also [width](#width).
#### `original_orientation`
Returns EXIF orientation value of the original photo as integer. See also [orientation](#orientation).
#### `original_filesize`
Returns size of the original photo in bytes as integer.
#### `ismissing` #### `ismissing`
Returns `True` if the original image file is missing on disk, otherwise `False`. This can occur if the file has been uploaded to iCloud but not yet downloaded to the local library or if the file was deleted or imported from a disk that has been unmounted and user hasn't enabled "Copy items to the Photos library" in Photos preferences. **Note**: this status is computed based on data in the Photos library and `ismissing` does not verify if the photo is actually missing. See also [path](#path). Returns `True` if the original image file is missing on disk, otherwise `False`. This can occur if the file has been uploaded to iCloud but not yet downloaded to the local library or if the file was deleted or imported from a disk that has been unmounted and user hasn't enabled "Copy items to the Photos library" in Photos preferences. **Note**: this status is computed based on data in the Photos library and `ismissing` does not verify if the photo is actually missing. See also [path](#path).
@@ -980,6 +1084,9 @@ Returns `True` if the picture has been marked as a favorite, otherwise `False`
#### `hidden` #### `hidden`
Returns `True` if the picture has been marked as hidden, otherwise `False` Returns `True` if the picture has been marked as hidden, otherwise `False`
#### `intrash`
Returns `True` if the picture is in the trash ('Recently Deleted' folder), otherwise `False`
#### `location` #### `location`
Returns latitude and longitude as a tuple of floats (latitude, longitude). If location is not set, latitude and longitude are returned as `None` Returns latitude and longitude as a tuple of floats (latitude, longitude). If location is not set, latitude and longitude are returned as `None`
@@ -1128,7 +1235,12 @@ photo.exiftool.setvalue("XMP:Title", "Title of photo")
photo.exiftool.addvalues("IPTC:Keywords", "vacation", "beach") photo.exiftool.addvalues("IPTC:Keywords", "vacation", "beach")
``` ```
**Caution**: I caution against writing new EXIF data to photos in the Photos library because this will overwrite the original copy of the photo and could adversely affect how Photos behaves. `exiftool.as_dict()` is useful for getting access to all the photos information but if you want to write new EXIF data, I recommend you export the photo first then write the data. [PhotoInfo.export()](#export) does this if called with `exiftool=True`. **Caution**: I caution against writing new EXIF data to photos in the Photos library because this will overwrite the original copy of the photo and could adversely affect how Photos behaves. `exiftool.as_dict()` is useful for getting access to all the photos information but if you want to write new EXIF data, I recommend you export the photo first then write the data. [PhotoInfo.export()](#export) does this if called with `exiftool=True`.
#### `score`
Returns a [ScoreInfo](#scoreinfo) data class object which provides access to the computed aesthetic scores for each photo.
**Note**: Valid only for Photos 5; returns None for earlier Photos versions.
#### `json()` #### `json()`
Returns a JSON representation of all photo info Returns a JSON representation of all photo info
@@ -1175,11 +1287,13 @@ If overwrite=False and increment=False, export will fail if destination file alr
#### <a name="rendertemplate">`render_template()`</a> #### <a name="rendertemplate">`render_template()`</a>
`render_template(template_str, none_str = "_", path_sep = None)` `render_template(template_str, none_str = "_", path_sep = None, expand_inplace = False, inplace_sep = None)`
Render template string for photo. none_str is used if template substitution results in None value and no default specified. Render template string for photo. none_str is used if template substitution results in None value and no default specified.
- `template_str`: str in form "{name,DEFAULT}" where name is one of the values in table below. The "," and default value that follows are optional. If specified, "DEFAULT" will be used if "name" is None. This is useful for values which are not always present, for example reverse geolocation data. - `template_str`: str in form "{name,DEFAULT}" where name is one of the values in table below. The "," and default value that follows are optional. If specified, "DEFAULT" will be used if "name" is None. This is useful for values which are not always present, for example reverse geolocation data.
- `none_str`: optional str to use as substitution when template value is None and no default specified in the template string. default is "_". - `none_str`: optional str to use as substitution when template value is None and no default specified in the template string. default is "_".
- `path_sep`: optional character to use as path separator, default is os.path.sep - `path_sep`: optional character to use as path separator, default is os.path.sep
- `expand_inplace`: expand multi-valued substitutions in-place as a single string instead of returning individual strings
- `inplace_sep`: optional string to use as separator between multi-valued keywords with expand_inplace; default is ','
Returns a tuple of (rendered, unmatched) where rendered is a list of rendered strings with all substitutions made and unmatched is a list of any strings that resembled a template substitution but did not match a known substitution. E.g. if template contained "{foo}", unmatched would be ["foo"]. Returns a tuple of (rendered, unmatched) where rendered is a list of rendered strings with all substitutions made and unmatched is a list of any strings that resembled a template substitution but did not match a known substitution. E.g. if template contained "{foo}", unmatched would be ["foo"].
@@ -1374,11 +1488,49 @@ PostalAddress(street='3700 Wailea Alanui Dr', sub_locality=None, city='Kihei', s
>>> photo.place.address.postal_code >>> photo.place.address.postal_code
'96753' '96753'
``` ```
### ScoreInfo
[PhotoInfo.score](#score) returns a ScoreInfo object that exposes the computed aesthetic scores for each photo (**Photos 5 only**). I have not yet reverse engineered the meaning of each score. The `overall` score seems to the most useful and appears to be a composite of the other scores. The following score properties are currently available:
```python
overall: float
curation: float
promotion: float
highlight_visibility: float
behavioral: float
failure: float
harmonious_color: float
immersiveness: float
interaction: float
interesting_subject: float
intrusive_object_presence: float
lively_color: float
low_light: float
noise: float
pleasant_camera_tilt: float
pleasant_composition: float
pleasant_lighting: float
pleasant_pattern: float
pleasant_perspective: float
pleasant_post_processing: float
pleasant_reflection: float
pleasant_symmetry: float
sharply_focused_subject: float
tastefully_blurred: float
well_chosen_subject: float
well_framed_subject: float
well_timed_shot: float
```
Example: find your "best" photo of food
```python
>>> import osxphotos
>>> photos = osxphotos.PhotosDB().photos()
>>> best_food_photo = sorted([p for p in photos if "food" in p.labels_normalized], key=lambda p: p.score.overall, reverse=True)[0]
```
### Template Substitutions ### Template Substitutions
The following substitutions are availabe for use with `PhotoInfo.render_template()` The following substitutions are availabe for use with `PhotoInfo.render_template()`
| Substitution | Description | | Substitution | Description |
|--------------|-------------| |--------------|-------------|
|{name}|Current filename of the photo| |{name}|Current filename of the photo|
@@ -1392,7 +1544,12 @@ The following substitutions are availabe for use with `PhotoInfo.render_template
|{created.month}|Month name in user's locale of the file creation time| |{created.month}|Month name in user's locale of the file creation time|
|{created.mon}|Month abbreviation in the user's locale of the file creation time| |{created.mon}|Month abbreviation in the user's locale of the file creation time|
|{created.dd}|2-digit day of the month (zero padded) of file creation time| |{created.dd}|2-digit day of the month (zero padded) of file creation time|
|{created.dow}|Day of week in user's locale of the file creation time|
|{created.doy}|3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)| |{created.doy}|3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)|
|{created.hour}|2-digit hour of the file creation time|
|{created.min}|2-digit minute of the file creation time|
|{created.sec}|2-digit second of the file creation time|
|{created.strftime}|Apply strftime template to file creation date/time. Should be used in form {created.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. {created.strftime,%Y-%U} would result in year-week number of year: '2020-23'. If used with no template will return null value. See https://strftime.org/ for help on strftime templates.|
|{modified.date}|Photo's modification date in ISO format, e.g. '2020-03-22'| |{modified.date}|Photo's modification date in ISO format, e.g. '2020-03-22'|
|{modified.year}|4-digit year of file modification time| |{modified.year}|4-digit year of file modification time|
|{modified.yy}|2-digit year of file modification time| |{modified.yy}|2-digit year of file modification time|
@@ -1401,6 +1558,22 @@ The following substitutions are availabe for use with `PhotoInfo.render_template
|{modified.mon}|Month abbreviation in the user's locale of the file modification time| |{modified.mon}|Month abbreviation in the user's locale of the file modification time|
|{modified.dd}|2-digit day of the month (zero padded) of the file modification time| |{modified.dd}|2-digit day of the month (zero padded) of the file modification time|
|{modified.doy}|3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)| |{modified.doy}|3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)|
|{modified.hour}|2-digit hour of the file modification time|
|{modified.min}|2-digit minute of the file modification time|
|{modified.sec}|2-digit second of the file modification time|
|{today.date}|Current date in iso format, e.g. '2020-03-22'|
|{today.year}|4-digit year of current date|
|{today.yy}|2-digit year of current date|
|{today.mm}|2-digit month of the current date (zero padded)|
|{today.month}|Month name in user's locale of the current date|
|{today.mon}|Month abbreviation in the user's locale of the current date|
|{today.dd}|2-digit day of the month (zero padded) of current date|
|{today.dow}|Day of week in user's locale of the current date|
|{today.doy}|3-digit day of year (e.g Julian day) of current date, starting from 1 (zero padded)|
|{today.hour}|2-digit hour of the current date|
|{today.min}|2-digit minute of the current date|
|{today.sec}|2-digit second of the current date|
|{today.strftime}|Apply strftime template to current date/time. Should be used in form {today.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. {today.strftime,%Y-%U} would result in year-week number of year: '2020-23'. If used with no template will return null value. See https://strftime.org/ for help on strftime templates.|
|{place.name}|Place name from the photo's reverse geolocation data, as displayed in Photos| |{place.name}|Place name from the photo's reverse geolocation data, as displayed in Photos|
|{place.country_code}|The ISO country code from the photo's reverse geolocation data| |{place.country_code}|The ISO country code from the photo's reverse geolocation data|
|{place.name.country}|Country name from the photo's reverse geolocation data| |{place.name.country}|Country name from the photo's reverse geolocation data|
@@ -1421,7 +1594,6 @@ The following substitutions are availabe for use with `PhotoInfo.render_template
|{label}|Image categorization label associated with a photo (Photos 5 only)| |{label}|Image categorization label associated with a photo (Photos 5 only)|
|{label_normalized}|All lower case version of 'label' (Photos 5 only)| |{label_normalized}|All lower case version of 'label' (Photos 5 only)|
### Utility Functions ### Utility Functions
The following functions are located in osxphotos.utils The following functions are located in osxphotos.utils

View File

@@ -7,6 +7,7 @@
# If you run this using python from command line, do so with -i flag: # If you run this using python from command line, do so with -i flag:
# python3 -i examples/photos_repl.py # python3 -i examples/photos_repl.py
import os
import sys import sys
import time import time
@@ -17,14 +18,27 @@ import osxphotos
from osxphotos.__main__ import get_photos_db, _list_libraries from osxphotos.__main__ import get_photos_db, _list_libraries
def show(photo):
""" open image with default image viewer
Note: This is for debugging only -- it will actually open any filetype which could
be very, very bad.
Args:
photo: PhotoInfo object or a path to a photo on disk
"""
photopath = photo.path if isinstance(photo, osxphotos.PhotoInfo) else photo
if not os.path.isfile(photopath):
return f"'{photopath}' does not appear to be a valid photo path"
os.system(f"open '{photopath}'")
def main(): def main():
db = None db = None
if len(sys.argv) > 1: db = sys.argv[1] if len(sys.argv) > 1 else get_photos_db()
db = sys.argv[1]
else:
db = get_photos_db()
if db: if db:
print("loading database") print("loading database")
tic = time.perf_counter() tic = time.perf_counter()

View File

@@ -3,14 +3,9 @@ import logging
from ._version import __version__ from ._version import __version__
from .photoinfo import PhotoInfo from .photoinfo import PhotoInfo
from .photosdb import PhotosDB from .photosdb import PhotosDB
from .utils import _set_debug, _debug, _get_logger from .phototemplate import PhotoTemplate
from .utils import _debug, _get_logger, _set_debug
# TODO: find edited photos: see https://github.com/orangeturtle739/photos-export/blob/master/extract_photos.py
# TODO: Add test for imageTimeZoneOffsetSeconds = None # TODO: Add test for imageTimeZoneOffsetSeconds = None
# TODO: Fix command line so multiple --keyword, etc. are AND (instead of OR as they are in .photos())
# Or fix the help text to match behavior
# TODO: Add test for __str__ and to_json # TODO: Add test for __str__ and to_json
# TODO: fix docstrings
# TODO: Add special albums and magic albums # TODO: Add special albums and magic albums
# TODO: cleanup os.path and pathlib code (import pathlib and also from pathlib import Path)

View File

@@ -7,6 +7,7 @@ import logging
import os import os
import os.path import os.path
import pathlib import pathlib
import pprint
import sys import sys
import time import time
@@ -235,6 +236,25 @@ JSON_OPTION = click.option(
) )
def deleted_options(f):
o = click.option
options = [
o(
"--deleted",
is_flag=True,
help="Include photos from the 'Recently Deleted' folder.",
),
o(
"--deleted-only",
is_flag=True,
help="Include only photos from the 'Recently Deleted' folder.",
),
]
for o in options[::-1]:
f = o(f)
return f
def query_options(f): def query_options(f):
o = click.option o = click.option
options = [ options = [
@@ -244,7 +264,7 @@ def query_options(f):
default=None, default=None,
multiple=True, multiple=True,
help="Search for photos with keyword KEYWORD. " help="Search for photos with keyword KEYWORD. "
'If more than one keyword, treated as "OR", e.g. find photos match any keyword', 'If more than one keyword, treated as "OR", e.g. find photos matching any keyword',
), ),
o( o(
"--person", "--person",
@@ -252,7 +272,7 @@ def query_options(f):
default=None, default=None,
multiple=True, multiple=True,
help="Search for photos with person PERSON. " help="Search for photos with person PERSON. "
'If more than one person, treated as "OR", e.g. find photos match any person', 'If more than one person, treated as "OR", e.g. find photos matching any person',
), ),
o( o(
"--album", "--album",
@@ -260,7 +280,7 @@ def query_options(f):
default=None, default=None,
multiple=True, multiple=True,
help="Search for photos in album ALBUM. " help="Search for photos in album ALBUM. "
'If more than one album, treated as "OR", e.g. find photos match any album', 'If more than one album, treated as "OR", e.g. find photos matching any album',
), ),
o( o(
"--folder", "--folder",
@@ -310,6 +330,13 @@ def query_options(f):
is_flag=True, is_flag=True,
help="Search for photos with no associated place name info (no reverse geolocation info)", help="Search for photos with no associated place name info (no reverse geolocation info)",
), ),
o(
"--label",
metavar="LABEL",
multiple=True,
help="Search for photos with image classification label LABEL (Photos 5 only). "
'If more than one label, treated as "OR", e.g. find photos matching any label',
),
o( o(
"--uti", "--uti",
metavar="UTI", metavar="UTI",
@@ -321,7 +348,7 @@ def query_options(f):
"-i", "-i",
"--ignore-case", "--ignore-case",
is_flag=True, is_flag=True,
help="Case insensitive search for title, description, or place. Does not apply to keyword, person, or album.", help="Case insensitive search for title, description, place, keyword, person, or album.",
), ),
o("--edited", is_flag=True, help="Search for photos that have been edited."), o("--edited", is_flag=True, help="Search for photos that have been edited."),
o( o(
@@ -442,6 +469,81 @@ def cli(ctx, db, json_, debug):
ctx.obj = CLI_Obj(db=db, json=json_, debug=debug) ctx.obj = CLI_Obj(db=db, json=json_, debug=debug)
@cli.command(hidden=True)
@DB_OPTION
@DB_ARGUMENT
@click.option(
"--dump",
metavar="ATTR",
help="Name of PhotosDB attribute to print; "
+ "can also use albums, persons, keywords, photos to dump related attributes.",
multiple=True,
)
@click.option(
"--uuid",
metavar="UUID",
help="Use with '--dump photos' to dump only certain UUIDs",
multiple=True,
)
@click.pass_obj
@click.pass_context
def debug_dump(ctx, cli_obj, db, photos_library, dump, uuid):
""" Print out debug info """
db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None:
click.echo(cli.commands["debug-dump"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries()
return
start_t = time.perf_counter()
print(f"Opening database: {db}")
photosdb = osxphotos.PhotosDB(dbfile=db)
stop_t = time.perf_counter()
print(f"Done; took {(stop_t-start_t):.2f} seconds")
for attr in dump:
if attr == "albums":
print("_dbalbums_album:")
pprint.pprint(photosdb._dbalbums_album)
print("_dbalbums_uuid:")
pprint.pprint(photosdb._dbalbums_uuid)
print("_dbalbum_details:")
pprint.pprint(photosdb._dbalbum_details)
print("_dbalbum_folders:")
pprint.pprint(photosdb._dbalbum_folders)
print("_dbfolder_details:")
pprint.pprint(photosdb._dbfolder_details)
elif attr == "keywords":
print("_dbkeywords_keyword:")
pprint.pprint(photosdb._dbkeywords_keyword)
print("_dbkeywords_uuid:")
pprint.pprint(photosdb._dbkeywords_uuid)
elif attr == "persons":
print("_dbfaces_person:")
pprint.pprint(photosdb._dbfaces_person)
print("_dbfaces_uuid:")
pprint.pprint(photosdb._dbfaces_uuid)
elif attr == "photos":
if uuid:
for uuid_ in uuid:
print(f"_dbphotos['{uuid_}']:")
try:
pprint.pprint(photosdb._dbphotos[uuid_])
except KeyError:
print(f"Did not find uuid {uuid_} in _dbphotos")
else:
print("_dbphotos:")
pprint.pprint(photosdb._dbphotos)
else:
try:
val = getattr(photosdb, attr)
print(f"{attr}:")
pprint.pprint(val)
except:
print(f"Did not find attribute {attr} in PhotosDB")
@cli.command() @cli.command()
@DB_OPTION @DB_OPTION
@JSON_OPTION @JSON_OPTION
@@ -451,7 +553,9 @@ def cli(ctx, db, json_, debug):
def keywords(ctx, cli_obj, db, json_, photos_library): def keywords(ctx, cli_obj, db, json_, photos_library):
""" Print out keywords found in the Photos library. """ """ Print out keywords found in the Photos library. """
db = get_photos_db(*photos_library, db, cli_obj.db) # below needed for to make CliRunner work for testing
cli_db = cli_obj.db if cli_obj is not None else None
db = get_photos_db(*photos_library, db, cli_db)
if db is None: if db is None:
click.echo(cli.commands["keywords"].get_help(ctx), err=True) click.echo(cli.commands["keywords"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ", err=True) click.echo("\n\nLocated the following Photos library databases: ", err=True)
@@ -475,7 +579,9 @@ def keywords(ctx, cli_obj, db, json_, photos_library):
def albums(ctx, cli_obj, db, json_, photos_library): def albums(ctx, cli_obj, db, json_, photos_library):
""" Print out albums found in the Photos library. """ """ Print out albums found in the Photos library. """
db = get_photos_db(*photos_library, db, cli_obj.db) # below needed for to make CliRunner work for testing
cli_db = cli_obj.db if cli_obj is not None else None
db = get_photos_db(*photos_library, db, cli_db)
if db is None: if db is None:
click.echo(cli.commands["albums"].get_help(ctx), err=True) click.echo(cli.commands["albums"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ", err=True) click.echo("\n\nLocated the following Photos library databases: ", err=True)
@@ -502,7 +608,9 @@ def albums(ctx, cli_obj, db, json_, photos_library):
def persons(ctx, cli_obj, db, json_, photos_library): def persons(ctx, cli_obj, db, json_, photos_library):
""" Print out persons (faces) found in the Photos library. """ """ Print out persons (faces) found in the Photos library. """
db = get_photos_db(*photos_library, db, cli_obj.db) # below needed for to make CliRunner work for testing
cli_db = cli_obj.db if cli_obj is not None else None
db = get_photos_db(*photos_library, db, cli_db)
if db is None: if db is None:
click.echo(cli.commands["persons"].get_help(ctx), err=True) click.echo(cli.commands["persons"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ", err=True) click.echo("\n\nLocated the following Photos library databases: ", err=True)
@@ -517,6 +625,32 @@ def persons(ctx, cli_obj, db, json_, photos_library):
click.echo(yaml.dump(persons, sort_keys=False)) click.echo(yaml.dump(persons, sort_keys=False))
@cli.command()
@DB_OPTION
@JSON_OPTION
@DB_ARGUMENT
@click.pass_obj
@click.pass_context
def labels(ctx, cli_obj, db, json_, photos_library):
""" Print out image classification labels found in the Photos library. """
# below needed for to make CliRunner work for testing
cli_db = cli_obj.db if cli_obj is not None else None
db = get_photos_db(*photos_library, db, cli_db)
if db is None:
click.echo(cli.commands["labels"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries()
return
photosdb = osxphotos.PhotosDB(dbfile=db)
labels = {"labels": photosdb.labels_as_dict}
if json_ or cli_obj.json:
click.echo(json.dumps(labels))
else:
click.echo(yaml.dump(labels, sort_keys=False))
@cli.command() @cli.command()
@DB_OPTION @DB_OPTION
@JSON_OPTION @JSON_OPTION
@@ -533,43 +667,40 @@ def info(ctx, cli_obj, db, json_, photos_library):
_list_libraries() _list_libraries()
return return
pdb = osxphotos.PhotosDB(dbfile=db) photosdb = osxphotos.PhotosDB(dbfile=db)
info = {} info = {"database_path": photosdb.db_path, "database_version": photosdb.db_version}
info["database_path"] = pdb.db_path photos = photosdb.photos(movies=False)
info["database_version"] = pdb.db_version
photos = pdb.photos()
not_shared_photos = [p for p in photos if not p.shared] not_shared_photos = [p for p in photos if not p.shared]
info["photo_count"] = len(not_shared_photos) info["photo_count"] = len(not_shared_photos)
hidden = [p for p in photos if p.hidden] hidden = [p for p in photos if p.hidden]
info["hidden_photo_count"] = len(hidden) info["hidden_photo_count"] = len(hidden)
movies = pdb.photos(images=False, movies=True) movies = photosdb.photos(images=False, movies=True)
not_shared_movies = [p for p in movies if not p.shared] not_shared_movies = [p for p in movies if not p.shared]
info["movie_count"] = len(not_shared_movies) info["movie_count"] = len(not_shared_movies)
if pdb.db_version > _PHOTOS_4_VERSION: if photosdb.db_version > _PHOTOS_4_VERSION:
shared_photos = [p for p in photos if p.shared] shared_photos = [p for p in photos if p.shared]
info["shared_photo_count"] = len(shared_photos) info["shared_photo_count"] = len(shared_photos)
shared_movies = [p for p in movies if p.shared] shared_movies = [p for p in movies if p.shared]
info["shared_movie_count"] = len(shared_movies) info["shared_movie_count"] = len(shared_movies)
keywords = pdb.keywords_as_dict keywords = photosdb.keywords_as_dict
info["keywords_count"] = len(keywords) info["keywords_count"] = len(keywords)
info["keywords"] = keywords info["keywords"] = keywords
albums = pdb.albums_as_dict albums = photosdb.albums_as_dict
info["albums_count"] = len(albums) info["albums_count"] = len(albums)
info["albums"] = albums info["albums"] = albums
if pdb.db_version > _PHOTOS_4_VERSION: if photosdb.db_version > _PHOTOS_4_VERSION:
albums_shared = pdb.albums_shared_as_dict albums_shared = photosdb.albums_shared_as_dict
info["shared_albums_count"] = len(albums_shared) info["shared_albums_count"] = len(albums_shared)
info["shared_albums"] = albums_shared info["shared_albums"] = albums_shared
persons = pdb.persons_as_dict persons = photosdb.persons_as_dict
info["persons_count"] = len(persons) info["persons_count"] = len(persons)
info["persons"] = persons info["persons"] = persons
@@ -633,10 +764,11 @@ def places(ctx, cli_obj, db, json_, photos_library):
@cli.command() @cli.command()
@DB_OPTION @DB_OPTION
@JSON_OPTION @JSON_OPTION
@deleted_options
@DB_ARGUMENT @DB_ARGUMENT
@click.pass_obj @click.pass_obj
@click.pass_context @click.pass_context
def dump(ctx, cli_obj, db, json_, photos_library): def dump(ctx, cli_obj, db, json_, deleted, deleted_only, photos_library):
""" Print list of all photos & associated info from the Photos library. """ """ Print list of all photos & associated info from the Photos library. """
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
@@ -646,8 +778,20 @@ def dump(ctx, cli_obj, db, json_, photos_library):
_list_libraries() _list_libraries()
return return
pdb = osxphotos.PhotosDB(dbfile=db) # check exclusive options
photos = pdb.photos(movies=True) if deleted and deleted_only:
click.echo("Incompatible dump options", err=True)
click.echo(cli.commands["dump"].get_help(ctx), err=True)
return
photosdb = osxphotos.PhotosDB(dbfile=db)
if deleted or deleted_only:
photos = photosdb.photos(movies=True, intrash=True)
else:
photos = []
if not deleted_only:
photos += photosdb.photos(movies=True)
print_photo_info(photos, json_ or cli_obj.json) print_photo_info(photos, json_ or cli_obj.json)
@@ -703,6 +847,7 @@ def _list_libraries(json_=False, error=True):
@DB_OPTION @DB_OPTION
@JSON_OPTION @JSON_OPTION
@query_options @query_options
@deleted_options
@click.option("--missing", is_flag=True, help="Search for photos missing from disk.") @click.option("--missing", is_flag=True, help="Search for photos missing from disk.")
@click.option( @click.option(
"--not-missing", "--not-missing",
@@ -788,6 +933,9 @@ def query(
has_raw, has_raw,
place, place,
no_place, no_place,
label,
deleted,
deleted_only,
): ):
""" Query the Photos database using 1 or more search options; """ Query the Photos database using 1 or more search options;
if more than one option is provided, they are treated as "AND" if more than one option is provided, they are treated as "AND"
@@ -808,6 +956,7 @@ def query(
has_raw, has_raw,
from_date, from_date,
to_date, to_date,
label,
] ]
exclusive = [ exclusive = [
(favorite, not_favorite), (favorite, not_favorite),
@@ -828,9 +977,12 @@ def query(
(selfie, not_selfie), (selfie, not_selfie),
(panorama, not_panorama), (panorama, not_panorama),
(any(place), no_place), (any(place), no_place),
(deleted, deleted_only),
] ]
# print help if no non-exclusive term or a double exclusive term is given # print help if no non-exclusive term or a double exclusive term is given
if not any(nonexclusive + [b ^ n for b, n in exclusive]): if any(all(bb) for bb in exclusive) or not any(
nonexclusive + [b ^ n for b, n in exclusive]
):
click.echo("Incompatible query options", err=True) click.echo("Incompatible query options", err=True)
click.echo(cli.commands["query"].get_help(ctx), err=True) click.echo(cli.commands["query"].get_help(ctx), err=True)
return return
@@ -903,6 +1055,9 @@ def query(
has_raw=has_raw, has_raw=has_raw,
place=place, place=place,
no_place=no_place, no_place=no_place,
label=label,
deleted=deleted,
deleted_only=deleted_only,
) )
# below needed for to make CliRunner work for testing # below needed for to make CliRunner work for testing
@@ -914,6 +1069,7 @@ def query(
@DB_OPTION @DB_OPTION
@click.option("--verbose", "-V", "verbose_", is_flag=True, help="Print verbose output.") @click.option("--verbose", "-V", "verbose_", is_flag=True, help="Print verbose output.")
@query_options @query_options
@deleted_options
@click.option( @click.option(
"--update", "--update",
is_flag=True, is_flag=True,
@@ -990,6 +1146,18 @@ def query(
'--keyword-template "{created.year}" ' '--keyword-template "{created.year}" '
"See Templating System below.", "See Templating System below.",
) )
@click.option(
"--description-template",
metavar="TEMPLATE",
multiple=False,
default=None,
help="For use with --exiftool, --sidecar; specify a template string to use as "
"description in the form '{name,DEFAULT}' "
"This is the same format as --directory. For example, if you wanted to append "
"'exported with osxphotos on [today's date]' to the description, you could specify "
'--description-template "{descr} exported with osxphotos on {today.date}" '
"See Templating System below.",
)
@click.option( @click.option(
"--current-name", "--current-name",
is_flag=True, is_flag=True,
@@ -1104,6 +1272,7 @@ def export(
person_keyword, person_keyword,
album_keyword, album_keyword,
keyword_template, keyword_template,
description_template,
current_name, current_name,
sidecar, sidecar,
only_photos, only_photos,
@@ -1136,6 +1305,9 @@ def export(
place, place,
no_place, no_place,
no_extended_attributes, no_extended_attributes,
label,
deleted,
deleted_only,
): ):
""" Export photos from the Photos database. """ Export photos from the Photos database.
Export path DEST is required. Export path DEST is required.
@@ -1174,8 +1346,9 @@ def export(
(export_by_date, directory), (export_by_date, directory),
(export_as_hardlink, exiftool), (export_as_hardlink, exiftool),
(any(place), no_place), (any(place), no_place),
(deleted, deleted_only),
] ]
if any([all(bb) for bb in exclusive]): if any(all(bb) for bb in exclusive):
click.echo("Incompatible export options", err=True) click.echo("Incompatible export options", err=True)
click.echo(cli.commands["export"].get_help(ctx), err=True) click.echo(cli.commands["export"].get_help(ctx), err=True)
return return
@@ -1186,11 +1359,6 @@ def export(
not x for x in [skip_edited, skip_bursts, skip_live, skip_raw] not x for x in [skip_edited, skip_bursts, skip_live, skip_raw]
] ]
# though the command line option is current_name, internally all processing
# logic uses original_name which is the boolean inverse of current_name
# because the original code used --original-name as an option
original_name = not current_name
# verify exiftool installed an in path # verify exiftool installed an in path
if exiftool: if exiftool:
try: try:
@@ -1219,13 +1387,32 @@ def export(
return return
# open export database and assign copy/link/unlink functions # open export database and assign copy/link/unlink functions
export_db_path = os.path.join(dest, OSXPHOTOS_EXPORT_DB)
# check that export isn't in the parent or child of a previously exported library
other_db_files = find_files_in_branch(dest, OSXPHOTOS_EXPORT_DB)
if other_db_files:
click.echo(
"WARNING: found other export database files in this destination directory branch. "
+ "This likely means you are attempting to export files into a directory "
+ "that is either the parent or a child directory of a previous export. "
+ "Proceeding may cause your exported files to be overwritten.",
err=True,
)
click.echo(
f"You are exporting to {dest}, found {OSXPHOTOS_EXPORT_DB} files in:"
)
for other_db in other_db_files:
click.echo(f"{other_db}")
click.confirm("Do you want to continue?", abort=True)
if dry_run: if dry_run:
export_db = ExportDBInMemory(os.path.join(dest, OSXPHOTOS_EXPORT_DB)) export_db = ExportDBInMemory(export_db_path)
# echo = functools.partial(click.echo, err=True) # echo = functools.partial(click.echo, err=True)
# fileutil = FileUtilNoOp(verbose=echo) # fileutil = FileUtilNoOp(verbose=echo)
fileutil = FileUtilNoOp fileutil = FileUtilNoOp
else: else:
export_db = ExportDB(os.path.join(dest, OSXPHOTOS_EXPORT_DB)) export_db = ExportDB(export_db_path)
fileutil = FileUtil fileutil = FileUtil
photos = _query( photos = _query(
@@ -1280,13 +1467,12 @@ def export(
has_raw=has_raw, has_raw=has_raw,
place=place, place=place,
no_place=no_place, no_place=no_place,
label=label,
deleted=deleted,
deleted_only=deleted_only,
) )
results_exported = [] results_exported = []
results_new = []
results_updated = []
results_skipped = []
results_exif_updated = []
if photos: if photos:
if export_bursts: if export_bursts:
# add the burst_photos to the export set # add the burst_photos to the export set
@@ -1300,7 +1486,51 @@ def export(
photo_str = "photos" if num_photos > 1 else "photo" photo_str = "photos" if num_photos > 1 else "photo"
click.echo(f"Exporting {num_photos} {photo_str} to {dest}...") click.echo(f"Exporting {num_photos} {photo_str} to {dest}...")
start_time = time.perf_counter() start_time = time.perf_counter()
if not verbose_: # though the command line option is current_name, internally all processing
# logic uses original_name which is the boolean inverse of current_name
# because the original code used --original-name as an option
original_name = not current_name
results_new = []
results_updated = []
results_skipped = []
results_exif_updated = []
if verbose_:
for p in photos:
results = export_photo(
photo=p,
dest=dest,
verbose_=verbose_,
export_by_date=export_by_date,
sidecar=sidecar,
update=update,
export_as_hardlink=export_as_hardlink,
overwrite=overwrite,
export_edited=export_edited,
original_name=original_name,
export_live=export_live,
download_missing=download_missing,
exiftool=exiftool,
directory=directory,
filename_template=filename_template,
no_extended_attributes=no_extended_attributes,
export_raw=export_raw,
album_keyword=album_keyword,
person_keyword=person_keyword,
keyword_template=keyword_template,
description_template=description_template,
export_db=export_db,
fileutil=fileutil,
dry_run=dry_run,
edited_suffix=edited_suffix,
)
results_exported.extend(results.exported)
results_new.extend(results.new)
results_updated.extend(results.updated)
results_skipped.extend(results.skipped)
results_exif_updated.extend(results.exif_updated)
else:
# show progress bar # show progress bar
with click.progressbar(photos) as bar: with click.progressbar(photos) as bar:
for p in bar: for p in bar:
@@ -1325,6 +1555,7 @@ def export(
album_keyword=album_keyword, album_keyword=album_keyword,
person_keyword=person_keyword, person_keyword=person_keyword,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
export_db=export_db, export_db=export_db,
fileutil=fileutil, fileutil=fileutil,
dry_run=dry_run, dry_run=dry_run,
@@ -1335,47 +1566,9 @@ def export(
results_updated.extend(results.updated) results_updated.extend(results.updated)
results_skipped.extend(results.skipped) results_skipped.extend(results.skipped)
results_exif_updated.extend(results.exif_updated) results_exif_updated.extend(results.exif_updated)
else:
for p in photos:
results = export_photo(
photo=p,
dest=dest,
verbose_=verbose_,
export_by_date=export_by_date,
sidecar=sidecar,
update=update,
export_as_hardlink=export_as_hardlink,
overwrite=overwrite,
export_edited=export_edited,
original_name=original_name,
export_live=export_live,
download_missing=download_missing,
exiftool=exiftool,
directory=directory,
filename_template=filename_template,
no_extended_attributes=no_extended_attributes,
export_raw=export_raw,
album_keyword=album_keyword,
person_keyword=person_keyword,
keyword_template=keyword_template,
export_db=export_db,
fileutil=fileutil,
dry_run=dry_run,
edited_suffix=edited_suffix,
)
results_exported.extend(results.exported)
results_new.extend(results.new)
results_updated.extend(results.updated)
results_skipped.extend(results.skipped)
results_exif_updated.extend(results.exif_updated)
stop_time = time.perf_counter() stop_time = time.perf_counter()
# print summary results # print summary results
if not update: if update:
photo_str = "photos" if len(results_exported) != 1 else "photo"
click.echo(f"Exported: {len(results_exported)} {photo_str}")
click.echo(f"Elapsed time: {stop_time-start_time} seconds")
else:
photo_str_new = "photos" if len(results_new) != 1 else "photo" photo_str_new = "photos" if len(results_new) != 1 else "photo"
photo_str_updated = "photos" if len(results_new) != 1 else "photo" photo_str_updated = "photos" if len(results_new) != 1 else "photo"
photo_str_skipped = "photos" if len(results_skipped) != 1 else "photo" photo_str_skipped = "photos" if len(results_skipped) != 1 else "photo"
@@ -1388,8 +1581,10 @@ def export(
+ f"skipped: {len(results_skipped)} {photo_str_skipped}, " + f"skipped: {len(results_skipped)} {photo_str_skipped}, "
+ f"updated EXIF data: {len(results_exif_updated)} {photo_str_exif_updated}" + f"updated EXIF data: {len(results_exif_updated)} {photo_str_exif_updated}"
) )
click.echo(f"Elapsed time: {stop_time-start_time} seconds") else:
photo_str = "photos" if len(results_exported) != 1 else "photo"
click.echo(f"Exported: {len(results_exported)} {photo_str}")
click.echo(f"Elapsed time: {(stop_time-start_time):.3f} seconds")
else: else:
click.echo("Did not find any photos to export") click.echo("Did not find any photos to export")
@@ -1412,8 +1607,8 @@ def help(ctx, topic, **kw):
def print_photo_info(photos, json=False): def print_photo_info(photos, json=False):
dump = []
if json: if json:
dump = []
for p in photos: for p in photos:
dump.append(p.json()) dump.append(p.json())
click.echo(f"[{', '.join(dump)}]") click.echo(f"[{', '.join(dump)}]")
@@ -1422,7 +1617,6 @@ def print_photo_info(photos, json=False):
csv_writer = csv.writer( csv_writer = csv.writer(
sys.stdout, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL sys.stdout, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
) )
dump = []
# add headers # add headers
dump.append( dump.append(
[ [
@@ -1464,6 +1658,7 @@ def print_photo_info(photos, json=False):
"has_raw", "has_raw",
"uti_raw", "uti_raw",
"path_raw", "path_raw",
"intrash",
] ]
) )
for p in photos: for p in photos:
@@ -1508,6 +1703,7 @@ def print_photo_info(photos, json=False):
p.has_raw, p.has_raw,
p.uti_raw, p.uti_raw,
p.path_raw, p.path_raw,
p.intrash,
] ]
) )
for row in dump: for row in dump:
@@ -1566,6 +1762,9 @@ def _query(
has_raw=None, has_raw=None,
place=None, place=None,
no_place=None, no_place=None,
label=None,
deleted=False,
deleted_only=False,
): ):
""" run a query against PhotosDB to extract the photos based on user supply criteria """ run a query against PhotosDB to extract the photos based on user supply criteria
used by query and export commands used by query and export commands
@@ -1573,16 +1772,37 @@ def _query(
if either is modified, need to ensure all three functions are updated """ if either is modified, need to ensure all three functions are updated """
photosdb = osxphotos.PhotosDB(dbfile=db) photosdb = osxphotos.PhotosDB(dbfile=db)
photos = photosdb.photos( if deleted or deleted_only:
keywords=keyword, photos = photosdb.photos(
persons=person, uuid=uuid,
albums=album, images=isphoto,
uuid=uuid, movies=ismovie,
images=isphoto, from_date=from_date,
movies=ismovie, to_date=to_date,
from_date=from_date, intrash=True,
to_date=to_date, )
) else:
photos = []
if not deleted_only:
photos += photosdb.photos(
uuid=uuid,
images=isphoto,
movies=ismovie,
from_date=from_date,
to_date=to_date,
)
if album:
photos = get_photos_by_attribute(photos, "albums", album, ignore_case)
if keyword:
photos = get_photos_by_attribute(photos, "keywords", keyword, ignore_case)
if person:
photos = get_photos_by_attribute(photos, "persons", person, ignore_case)
if label:
photos = get_photos_by_attribute(photos, "labels", label, ignore_case)
if folder: if folder:
# search for photos in an album in folder # search for photos in an album in folder
@@ -1758,6 +1978,34 @@ def _query(
return photos return photos
def get_photos_by_attribute(photos, attribute, values, ignore_case):
"""Search for photos based on values being in PhotoInfo.attribute
Args:
photos: a list of PhotoInfo objects
attribute: str, name of PhotoInfo attribute to search (e.g. keywords, persons, etc)
values: list of values to search in property
ignore_case: ignore case when searching
Returns:
list of PhotoInfo objects matching search criteria
"""
photos_search = []
if ignore_case:
# case-insensitive
for x in values:
x = x.lower()
photos_search.extend(
p
for p in photos
if x in [attr.lower() for attr in getattr(p, attribute)]
)
else:
for x in values:
photos_search.extend(p for p in photos if x in getattr(p, attribute))
return photos_search
def export_photo( def export_photo(
photo=None, photo=None,
dest=None, dest=None,
@@ -1779,6 +2027,7 @@ def export_photo(
album_keyword=None, album_keyword=None,
person_keyword=None, person_keyword=None,
keyword_template=None, keyword_template=None,
description_template=None,
export_db=None, export_db=None,
fileutil=FileUtil, fileutil=FileUtil,
dry_run=None, dry_run=None,
@@ -1806,6 +2055,7 @@ def export_photo(
album_keyword: boolean; if True, exports album names as keywords in metadata album_keyword: boolean; if True, exports album names as keywords in metadata
person_keyword: boolean; if True, exports person names as keywords in metadata person_keyword: boolean; if True, exports person names as keywords in metadata
keyword_template: list of strings; if provided use rendered template strings as keywords keyword_template: list of strings; if provided use rendered template strings as keywords
description_template: string; optional template string that will be rendered for use as photo description
export_db: export database instance compatible with ExportDB_ABC export_db: export database instance compatible with ExportDB_ABC
fileutil: file util class compatible with FileUtilABC fileutil: file util class compatible with FileUtilABC
dry_run: boolean; if True, doesn't actually export or update any files dry_run: boolean; if True, doesn't actually export or update any files
@@ -1880,6 +2130,7 @@ def export_photo(
use_albums_as_keywords=album_keyword, use_albums_as_keywords=album_keyword,
use_persons_as_keywords=person_keyword, use_persons_as_keywords=person_keyword,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
update=update, update=update,
export_db=export_db, export_db=export_db,
fileutil=fileutil, fileutil=fileutil,
@@ -1935,6 +2186,7 @@ def export_photo(
use_albums_as_keywords=album_keyword, use_albums_as_keywords=album_keyword,
use_persons_as_keywords=person_keyword, use_persons_as_keywords=person_keyword,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
update=update, update=update,
export_db=export_db, export_db=export_db,
fileutil=fileutil, fileutil=fileutil,
@@ -1990,10 +2242,7 @@ def get_filenames_from_template(photo, filename_template, original_name):
) )
filenames = [f"{file_}{photo_ext}" for file_ in filenames] filenames = [f"{file_}{photo_ext}" for file_ in filenames]
else: else:
if original_name: filenames = [photo.original_filename] if original_name else [photo.filename]
filenames = [photo.original_filename]
else:
filenames = [photo.filename]
return filenames return filenames
@@ -2019,13 +2268,18 @@ def get_dirnames_from_template(photo, directory, export_by_date, dest, dry_run):
dest_path = os.path.join( dest_path = os.path.join(
dest, date_created.year, date_created.mm, date_created.dd dest, date_created.year, date_created.mm, date_created.dd
) )
if not dry_run and not os.path.isdir(dest_path): if not (dry_run or os.path.isdir(dest_path)):
os.makedirs(dest_path) os.makedirs(dest_path)
dest_paths = [dest_path] dest_paths = [dest_path]
elif directory: elif directory:
# got a directory template, render it and check results are valid # got a directory template, render it and check results are valid
dirnames, unmatched = photo.render_template(directory) dirnames, unmatched = photo.render_template(directory)
if not dirnames or unmatched: if not dirnames:
raise click.BadOptionUsage(
"directory",
f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}",
)
elif unmatched:
raise click.BadOptionUsage( raise click.BadOptionUsage(
"directory", "directory",
f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}", f"Invalid template '{directory}': results={dirnames} unmatched={unmatched}",
@@ -2044,5 +2298,42 @@ def get_dirnames_from_template(photo, directory, export_by_date, dest, dry_run):
return dest_paths return dest_paths
def find_files_in_branch(pathname, filename):
""" Search a directory branch to find file(s) named filename
The branch searched includes all folders below pathname and
the parent tree of pathname but not pathname itself.
e.g. find filename in children folders and parent folders
Args:
pathname: str, full path of directory to search
filename: str, filename to search for
Returns: list of full paths to any matching files
"""
pathname = pathlib.Path(pathname).resolve()
files = []
# walk down the tree
for root, directories, filenames in os.walk(pathname):
# for directory in directories:
# print(os.path.join(root, directory))
for fname in filenames:
if fname == filename and pathlib.Path(root) != pathname:
files.append(os.path.join(root, fname))
# walk up the tree
path = pathlib.Path(pathname)
for root in path.parents:
filenames = os.listdir(root)
for fname in filenames:
filepath = os.path.join(root, fname)
if fname == filename and os.path.isfile(filepath):
files.append(os.path.join(root, fname))
return files
if __name__ == "__main__": if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter cli() # pylint: disable=no-value-for-parameter

View File

@@ -445,10 +445,7 @@ class ExportDB(ExportDB_ABC):
dt = datetime.datetime.utcnow().isoformat() dt = datetime.datetime.utcnow().isoformat()
python_path = sys.executable python_path = sys.executable
cmd = sys.argv[0] cmd = sys.argv[0]
if len(sys.argv) > 1: args = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else ""
args = " ".join(sys.argv[1:])
else:
args = ""
cwd = os.getcwd() cwd = os.getcwd()
conn = self._conn conn = self._conn
try: try:

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.29.9" __version__ = "0.30.5"

View File

@@ -62,10 +62,7 @@ class AlbumInfo:
try: try:
return self._folder_names return self._folder_names
except AttributeError: except AttributeError:
if self._db._db_version <= _PHOTOS_4_VERSION: self._folder_names = self._db._album_folder_hierarchy_list(self._uuid)
self._folder_names = self._db._album_folder_hierarchy_list(self._uuid)
else:
self._folder_names = self._db._album_folder_hierarchy_list(self._uuid)
return self._folder_names return self._folder_names
@property @property

View File

@@ -12,53 +12,59 @@ class DateTimeFormatter:
@property @property
def date(self): def date(self):
""" ISO date in form 2020-03-22 """ """ ISO date in form 2020-03-22 """
date = self.dt.date().isoformat() return self.dt.date().isoformat()
return date
@property @property
def year(self): def year(self):
""" 4 digit year """ """ 4 digit year """
year = f"{self.dt.year}" return f"{self.dt.year}"
return year
@property @property
def yy(self): def yy(self):
""" 2 digit year """ """ 2 digit year """
yy = f"{self.dt.strftime('%y')}" return f"{self.dt.strftime('%y')}"
return yy
@property @property
def mm(self): def mm(self):
""" 2 digit month """ """ 2 digit month """
mm = f"{self.dt.strftime('%m')}" return f"{self.dt.strftime('%m')}"
return mm
@property @property
def month(self): def month(self):
""" Month as locale's full name """ """ Month as locale's full name """
month = f"{self.dt.strftime('%B')}" return f"{self.dt.strftime('%B')}"
return month
@property @property
def mon(self): def mon(self):
""" Month as locale's abbreviated name """ """ Month as locale's abbreviated name """
mon = f"{self.dt.strftime('%b')}" return f"{self.dt.strftime('%b')}"
return mon
@property @property
def dd(self): def dd(self):
""" 2-digit day of the month """ """ 2-digit day of the month """
dd = f"{self.dt.strftime('%d')}" return f"{self.dt.strftime('%d')}"
return dd
@property @property
def dow(self): def dow(self):
""" Day of week as locale's name """ """ Day of week as locale's name """
dow = f"{self.dt.strftime('%A')}" return f"{self.dt.strftime('%A')}"
return dow
@property @property
def doy(self): def doy(self):
""" Julian day of year starting from 001 """ """ Julian day of year starting from 001 """
doy = f"{self.dt.strftime('%j')}" return f"{self.dt.strftime('%j')}"
return doy
@property
def hour(self):
""" 2-digit hour """
return f"{self.dt.strftime('%H')}"
@property
def min(self):
""" 2-digit minute """
return f"{self.dt.strftime('%M')}"
@property
def sec(self):
""" 2-digit second """
return f"{self.dt.strftime('%S')}"

View File

@@ -59,11 +59,7 @@ class _ExifToolProc:
) )
return return
if exiftool: self._exiftool = exiftool if exiftool else get_exiftool_path()
self._exiftool = exiftool
else:
self._exiftool = get_exiftool_path()
self._process_running = False self._process_running = False
self._start_proc() self._start_proc()
@@ -156,8 +152,7 @@ class ExifTool:
if value is None: if value is None:
value = "" value = ""
command = [] command = [f"-{tag}={value}"]
command.append(f"-{tag}={value}")
if self.overwrite: if self.overwrite:
command.append("-overwrite_original") command.append("-overwrite_original")
self.run_commands(*command) self.run_commands(*command)
@@ -193,7 +188,7 @@ class ExifTool:
no_file: (bool) do not pass the filename to exiftool (default=False) no_file: (bool) do not pass the filename to exiftool (default=False)
by default, all commands will be run against self.file by default, all commands will be run against self.file
use no_file=True to run a command without passing the filename """ use no_file=True to run a command without passing the filename """
if not hasattr(self, "_process") or not self._process: if not (hasattr(self, "_process") and self._process):
raise ValueError("exiftool process is not running") raise ValueError("exiftool process is not running")
if not commands: if not commands:
@@ -245,8 +240,7 @@ class ExifTool:
def json(self): def json(self):
""" returns JSON string containing all EXIF tags and values from exiftool """ """ returns JSON string containing all EXIF tags and values from exiftool """
json_str = self.run_commands("-json") return self.run_commands("-json")
return json_str
def _read_exif(self): def _read_exif(self):
""" read exif data from file """ """ read exif data from file """
@@ -254,5 +248,4 @@ class ExifTool:
self.data = {k: v for k, v in data.items()} self.data = {k: v for k, v in data.items()}
def __str__(self): def __str__(self):
str_ = f"file: {self.file}\nexiftool: {self._exiftoolproc._exiftool}" return f"file: {self.file}\nexiftool: {self._exiftoolproc._exiftool}"
return str_

View File

@@ -11,6 +11,7 @@ from abc import ABC, abstractmethod
class FileUtilABC(ABC): class FileUtilABC(ABC):
""" Abstract base class for FileUtil """ """ Abstract base class for FileUtil """
@classmethod @classmethod
@abstractmethod @abstractmethod
def hardlink(cls, src, dest): def hardlink(cls, src, dest):
@@ -39,6 +40,7 @@ class FileUtilABC(ABC):
class FileUtilMacOS(FileUtilABC): class FileUtilMacOS(FileUtilABC):
""" Various file utilities """ """ Various file utilities """
@classmethod @classmethod
def hardlink(cls, src, dest): def hardlink(cls, src, dest):
""" Hardlinks a file from src path to dest path """ Hardlinks a file from src path to dest path
@@ -119,9 +121,7 @@ class FileUtilMacOS(FileUtilABC):
if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG: if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG:
return False return False
if s1 == s2: return s1 == s2
return True
return False
@classmethod @classmethod
def file_sig(cls, f1): def file_sig(cls, f1):
@@ -135,14 +135,17 @@ class FileUtilMacOS(FileUtilABC):
class FileUtil(FileUtilMacOS): class FileUtil(FileUtilMacOS):
""" Various file utilities """ """ Various file utilities """
pass pass
class FileUtilNoOp(FileUtil): class FileUtilNoOp(FileUtil):
""" No-Op implementation of FileUtil for testing / dry-run mode """ No-Op implementation of FileUtil for testing / dry-run mode
all methods with exception of cmp_sig and file_cmp are no-op all methods with exception of cmp_sig and file_cmp are no-op
cmp_sig functions as FileUtil.cmp_sig does cmp_sig functions as FileUtil.cmp_sig does
file_cmp returns mock data file_cmp returns mock data
""" """
@staticmethod @staticmethod
def noop(*args): def noop(*args):
pass pass
@@ -155,7 +158,7 @@ class FileUtilNoOp(FileUtil):
cls.verbose = verbose cls.verbose = verbose
else: else:
raise ValueError(f"verbose {verbose} not callable") raise ValueError(f"verbose {verbose} not callable")
return super(FileUtilNoOp, cls).__new__(cls) return super(FileUtilNoOp, cls).__new__(cls)
@classmethod @classmethod
def hardlink(cls, src, dest): def hardlink(cls, src, dest):
@@ -164,7 +167,7 @@ class FileUtilNoOp(FileUtil):
@classmethod @classmethod
def copy(cls, src, dest, norsrc=False): def copy(cls, src, dest, norsrc=False):
cls.verbose(f"copy: {src} {dest}") cls.verbose(f"copy: {src} {dest}")
@classmethod @classmethod
def unlink(cls, dest): def unlink(cls, dest):
cls.verbose(f"unlink: {dest}") cls.verbose(f"unlink: {dest}")

View File

@@ -6,4 +6,5 @@ PhotosDB.photos() returns a list of PhotoInfo objects
from ._photoinfo_exifinfo import ExifInfo from ._photoinfo_exifinfo import ExifInfo
from ._photoinfo_export import ExportResults from ._photoinfo_export import ExportResults
from ._photoinfo_scoreinfo import ScoreInfo
from .photoinfo import PhotoInfo from .photoinfo import PhotoInfo

View File

@@ -156,6 +156,46 @@ def _export_photo_uuid_applescript(
return None return None
# _check_export_suffix is not a class method, don't import this into PhotoInfo
def _check_export_suffix(src, dest, edited):
"""Helper function for exporting photos to check file extensions of destination path.
Checks that dst file extension is appropriate for the src.
If edited=True, will use src file extension of ".jpeg" if None provided for src.
Args:
src: path to source file or None.
dest: path to destination file.
edited: set to True if exporting an edited photo.
Returns:
True if src and dest extensions are OK, else False.
Raises:
ValueError if edited is False and src is None
"""
# check extension of destination
if src is not None:
# use suffix from edited file
actual_suffix = pathlib.Path(src).suffix
elif edited:
# use .jpeg as that's probably correct
actual_suffix = ".jpeg"
else:
raise ValueError("src must not be None if edited=False")
# Photo's often converts .JPG to .jpeg or .tif to .tiff on import
dest_ext = dest.suffix.lower()
actual_ext = actual_suffix.lower()
suffixes = sorted([dest_ext, actual_ext])
return (
dest_ext == actual_ext
or suffixes == [".jpeg", ".jpg"]
or suffixes == [".tif", ".tiff"]
)
def export( def export(
self, self,
dest, dest,
@@ -175,6 +215,7 @@ def export(
use_albums_as_keywords=False, use_albums_as_keywords=False,
use_persons_as_keywords=False, use_persons_as_keywords=False,
keyword_template=None, keyword_template=None,
description_template=None,
): ):
""" export photo """ export photo
dest: must be valid destination path (or exception raised) dest: must be valid destination path (or exception raised)
@@ -182,8 +223,11 @@ def export(
**NOTE**: if provided, user must ensure file extension (suffix) is correct. **NOTE**: if provided, user must ensure file extension (suffix) is correct.
For example, if photo is .CR2 file, edited image may be .jpeg. For example, if photo is .CR2 file, edited image may be .jpeg.
If you provide an extension different than what the actual file is, If you provide an extension different than what the actual file is,
export will print a warning but will happily export the photo using the export will print a warning but will export the photo using the
incorrect file extension. e.g. to get the extension of the edited photo, incorrect file extension (unless use_photos_export is true, in which case export will
use the extension provided by Photos upon export; in this case, an incorrect extension is
silently ignored).
e.g. to get the extension of the edited photo,
reference PhotoInfo.path_edited reference PhotoInfo.path_edited
edited: (boolean, default=False); if True will export the edited version of the photo edited: (boolean, default=False); if True will export the edited version of the photo
(or raise exception if no edited version) (or raise exception if no edited version)
@@ -207,6 +251,7 @@ def export(
use_persons_as_keywords: (boolean, default = False); if True, will include person names in keywords use_persons_as_keywords: (boolean, default = False); if True, will include person names in keywords
when exporting metadata with exiftool or sidecar when exporting metadata with exiftool or sidecar
keyword_template: (list of strings); list of template strings that will be rendered as used as keywords keyword_template: (list of strings); list of template strings that will be rendered as used as keywords
description_template: string; optional template string that will be rendered for use as photo description
returns: list of photos exported returns: list of photos exported
""" """
@@ -230,6 +275,7 @@ def export(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
return results.exported return results.exported
@@ -254,19 +300,23 @@ def export2(
use_albums_as_keywords=False, use_albums_as_keywords=False,
use_persons_as_keywords=False, use_persons_as_keywords=False,
keyword_template=None, keyword_template=None,
description_template=None,
update=False, update=False,
export_db=None, export_db=None,
fileutil=FileUtil, fileutil=FileUtil,
dry_run=False, dry_run=False,
): ):
""" export photo, like export but with update and dry_run options """ export photo, like export but with update and dry_run options
dest: must be valid destination path (or exception raised) dest: must be valid destination path or exception raised
filename: (optional): name of exported picture; if not provided, will use current filename filename: (optional): name of exported picture; if not provided, will use current filename
**NOTE**: if provided, user must ensure file extension (suffix) is correct. **NOTE**: if provided, user must ensure file extension (suffix) is correct.
For example, if photo is .CR2 file, edited image may be .jpeg. For example, if photo is .CR2 file, edited image may be .jpeg.
If you provide an extension different than what the actual file is, If you provide an extension different than what the actual file is,
export will print a warning but will happily export the photo using the export will print a warning but will export the photo using the
incorrect file extension. e.g. to get the extension of the edited photo, incorrect file extension (unless use_photos_export is true, in which case export will
use the extension provided by Photos upon export; in this case, an incorrect extension is
silently ignored).
e.g. to get the extension of the edited photo,
reference PhotoInfo.path_edited reference PhotoInfo.path_edited
edited: (boolean, default=False); if True will export the edited version of the photo edited: (boolean, default=False); if True will export the edited version of the photo
(or raise exception if no edited version) (or raise exception if no edited version)
@@ -290,6 +340,7 @@ def export2(
use_persons_as_keywords: (boolean, default = False); if True, will include person names in keywords use_persons_as_keywords: (boolean, default = False); if True, will include person names in keywords
when exporting metadata with exiftool or sidecar when exporting metadata with exiftool or sidecar
keyword_template: (list of strings); list of template strings that will be rendered as used as keywords keyword_template: (list of strings); list of template strings that will be rendered as used as keywords
description_template: string; optional template string that will be rendered for use as photo description
update: (boolean, default=False); if True export will run in update mode, that is, it will update: (boolean, default=False); if True export will run in update mode, that is, it will
not export the photo if the current version already exists in the destination not export the photo if the current version already exists in the destination
export_db: (ExportDB_ABC); instance of a class that conforms to ExportDB_ABC with methods export_db: (ExportDB_ABC); instance of a class that conforms to ExportDB_ABC with methods
@@ -370,27 +421,6 @@ def export2(
fname = pathlib.Path(fname) fname = pathlib.Path(fname)
dest = dest / fname dest = dest / fname
# check extension of destination
if edited and self.path_edited is not None:
# use suffix from edited file
actual_suffix = pathlib.Path(self.path_edited).suffix
elif edited:
# use .jpeg as that's probably correct
# if edited and path_edited is None, will raise FileNotFoundError below
# unless use_photos_export is True
actual_suffix = ".jpeg"
else:
# use suffix from the non-edited file
actual_suffix = pathlib.Path(self.filename).suffix
# warn if suffixes don't match but ignore .JPG / .jpeg as
# Photo's often converts .JPG to .jpeg
suffixes = sorted([x.lower() for x in [dest.suffix, actual_suffix]])
if dest.suffix.lower() != actual_suffix.lower() and suffixes != [".jpeg", ".jpg"]:
logging.warning(
f"Invalid destination suffix: {dest.suffix}, should be {actual_suffix}"
)
# check to see if file exists and if so, add (1), (2), etc until we find one that works # check to see if file exists and if so, add (1), (2), etc until we find one that works
# Photos checks the stem and adds (1), (2), etc which avoids collision with sidecars # Photos checks the stem and adds (1), (2), etc which avoids collision with sidecars
# e.g. exporting sidecar for file1.png and file1.jpeg # e.g. exporting sidecar for file1.png and file1.jpeg
@@ -438,6 +468,13 @@ def export2(
if not os.path.isfile(src): if not os.path.isfile(src):
raise FileNotFoundError(f"{src} does not appear to exist") raise FileNotFoundError(f"{src} does not appear to exist")
if not _check_export_suffix(src, dest, edited):
logging.warning(
f"Invalid destination suffix: {dest.suffix} for {self.path}, "
+ f"edited={edited}, path_edited={self.path_edited}, "
+ f"original_filename={self.original_filename}, filename={self.filename}"
)
logging.debug( logging.debug(
f"exporting {src} to {dest}, overwrite={overwrite}, increment={increment}, dest exists: {dest.exists()}" f"exporting {src} to {dest}, overwrite={overwrite}, increment={increment}, dest exists: {dest.exists()}"
) )
@@ -638,6 +675,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
if not dry_run: if not dry_run:
try: try:
@@ -653,6 +691,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
if not dry_run: if not dry_run:
try: try:
@@ -680,6 +719,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
)[0] )[0]
if old_data != current_data: if old_data != current_data:
@@ -695,6 +735,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
export_db.set_exifdata_for_file( export_db.set_exifdata_for_file(
exported_file, exported_file,
@@ -702,6 +743,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
), ),
) )
export_db.set_stat_exif_for_file( export_db.set_stat_exif_for_file(
@@ -717,6 +759,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
export_db.set_exifdata_for_file( export_db.set_exifdata_for_file(
exported_file, exported_file,
@@ -724,6 +767,7 @@ def export2(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
), ),
) )
export_db.set_stat_exif_for_file( export_db.set_stat_exif_for_file(
@@ -757,6 +801,8 @@ def _export_photo(
action depending on update, overwrite action depending on update, overwrite
Assumes destination is the right destination (e.g. UUID matches) Assumes destination is the right destination (e.g. UUID matches)
sets UUID and JSON info foo exported file using set_uuid_for_file, set_inf_for_uuido sets UUID and JSON info foo exported file using set_uuid_for_file, set_inf_for_uuido
Args:
src: src path (string) src: src path (string)
dest: dest path (pathlib.Path) dest: dest path (pathlib.Path)
update: bool update: bool
@@ -766,7 +812,9 @@ def _export_photo(
export_as_hardlink: bool export_as_hardlink: bool
exiftool: bool exiftool: bool
fileutil: FileUtil class that conforms to fileutil.FileUtilABC fileutil: FileUtil class that conforms to fileutil.FileUtilABC
Returns: ExportResults
Returns:
ExportResults
""" """
exported_files = [] exported_files = []
@@ -919,6 +967,7 @@ def _write_exif_data(
use_albums_as_keywords=False, use_albums_as_keywords=False,
use_persons_as_keywords=False, use_persons_as_keywords=False,
keyword_template=None, keyword_template=None,
description_template=None,
): ):
""" write exif data to image file at filepath """ write exif data to image file at filepath
filepath: full path to the image file """ filepath: full path to the image file """
@@ -930,6 +979,7 @@ def _write_exif_data(
use_albums_as_keywords=use_albums_as_keywords, use_albums_as_keywords=use_albums_as_keywords,
use_persons_as_keywords=use_persons_as_keywords, use_persons_as_keywords=use_persons_as_keywords,
keyword_template=keyword_template, keyword_template=keyword_template,
description_template=description_template,
) )
)[0] )[0]
for exiftag, val in exif_info.items(): for exiftag, val in exif_info.items():
@@ -948,6 +998,7 @@ def _exiftool_json_sidecar(
use_albums_as_keywords=False, use_albums_as_keywords=False,
use_persons_as_keywords=False, use_persons_as_keywords=False,
keyword_template=None, keyword_template=None,
description_template=None,
): ):
""" return json string of EXIF details in exiftool sidecar format """ return json string of EXIF details in exiftool sidecar format
Does not include all the EXIF fields as those are likely already in the image Does not include all the EXIF fields as those are likely already in the image
@@ -973,7 +1024,13 @@ def _exiftool_json_sidecar(
exif = {} exif = {}
exif["_CreatedBy"] = "osxphotos, https://github.com/RhetTbull/osxphotos" exif["_CreatedBy"] = "osxphotos, https://github.com/RhetTbull/osxphotos"
if self.description: if description_template is not None:
description = self.render_template(
description_template, expand_inplace=True, inplace_sep=", "
)[0]
exif["EXIF:ImageDescription"] = description
exif["XMP:Description"] = description
elif self.description:
exif["EXIF:ImageDescription"] = self.description exif["EXIF:ImageDescription"] = self.description
exif["XMP:Description"] = self.description exif["XMP:Description"] = self.description
@@ -1046,7 +1103,6 @@ def _exiftool_json_sidecar(
lat_str, lon_str = dd_to_dms_str(lat, lon) lat_str, lon_str = dd_to_dms_str(lat, lon)
exif["EXIF:GPSLatitude"] = lat_str exif["EXIF:GPSLatitude"] = lat_str
exif["EXIF:GPSLongitude"] = lon_str exif["EXIF:GPSLongitude"] = lon_str
exif["Composite:GPSPosition"] = f"{lat_str}, {lon_str}"
lat_ref = "North" if lat >= 0 else "South" lat_ref = "North" if lat >= 0 else "South"
lon_ref = "East" if lon >= 0 else "West" lon_ref = "East" if lon >= 0 else "West"
exif["EXIF:GPSLatitudeRef"] = lat_ref exif["EXIF:GPSLatitudeRef"] = lat_ref
@@ -1076,16 +1132,25 @@ def _xmp_sidecar(
use_albums_as_keywords=False, use_albums_as_keywords=False,
use_persons_as_keywords=False, use_persons_as_keywords=False,
keyword_template=None, keyword_template=None,
description_template=None,
): ):
""" returns string for XMP sidecar """ returns string for XMP sidecar
use_albums_as_keywords: treat album names as keywords use_albums_as_keywords: treat album names as keywords
use_persons_as_keywords: treat person names as keywords use_persons_as_keywords: treat person names as keywords
keyword_template: (list of strings); list of template strings to render as keywords """ keyword_template: (list of strings); list of template strings to render as keywords
description_template: string; optional template string that will be rendered for use as photo description """
# TODO: add additional fields to XMP file? # TODO: add additional fields to XMP file?
xmp_template = Template(filename=os.path.join(_TEMPLATE_DIR, _XMP_TEMPLATE_NAME)) xmp_template = Template(filename=os.path.join(_TEMPLATE_DIR, _XMP_TEMPLATE_NAME))
if description_template is not None:
description = self.render_template(
description_template, expand_inplace=True, inplace_sep=", "
)[0]
else:
description = self.description if self.description is not None else ""
keyword_list = [] keyword_list = []
if self.keywords: if self.keywords:
keyword_list.extend(self.keywords) keyword_list.extend(self.keywords)
@@ -1142,7 +1207,11 @@ def _xmp_sidecar(
subject_list = list(self.keywords) + person_list subject_list = list(self.keywords) + person_list
xmp_str = xmp_template.render( xmp_str = xmp_template.render(
photo=self, keywords=keyword_list, persons=person_list, subjects=subject_list photo=self,
description=description,
keywords=keyword_list,
persons=person_list,
subjects=subject_list,
) )
# remove extra lines that mako inserts from template # remove extra lines that mako inserts from template
@@ -1153,7 +1222,7 @@ def _xmp_sidecar(
def _write_sidecar(self, filename, sidecar_str): def _write_sidecar(self, filename, sidecar_str):
""" write sidecar_str to filename """ write sidecar_str to filename
used for exporting sidecar info """ used for exporting sidecar info """
if not filename and not sidecar_str: if not (filename or sidecar_str):
raise ( raise (
ValueError( ValueError(
f"filename {filename} and sidecar_str {sidecar_str} must not be None" f"filename {filename} and sidecar_str {sidecar_str} must not be None"

View File

@@ -0,0 +1,119 @@
""" PhotoInfo methods to expose computed score info from the library """
import logging
from dataclasses import dataclass
from .._constants import _PHOTOS_4_VERSION
@dataclass(frozen=True)
class ScoreInfo:
""" Computed photo score info associated with a photo from the Photos library """
overall: float
curation: float
promotion: float
highlight_visibility: float
behavioral: float
failure: float
harmonious_color: float
immersiveness: float
interaction: float
interesting_subject: float
intrusive_object_presence: float
lively_color: float
low_light: float
noise: float
pleasant_camera_tilt: float
pleasant_composition: float
pleasant_lighting: float
pleasant_pattern: float
pleasant_perspective: float
pleasant_post_processing: float
pleasant_reflection: float
pleasant_symmetry: float
sharply_focused_subject: float
tastefully_blurred: float
well_chosen_subject: float
well_framed_subject: float
well_timed_shot: float
@property
def score(self):
""" Computed score information for a photo
Returns:
ScoreInfo instance
"""
if self._db._db_version <= _PHOTOS_4_VERSION:
logging.debug(f"score not implemented for this database version")
return None
try:
return self._scoreinfo # pylint: disable=access-member-before-definition
except AttributeError:
try:
scores = self._db._db_scoreinfo_uuid[self.uuid]
self._scoreinfo = ScoreInfo(
overall=scores["overall_aesthetic"],
curation=scores["curation"],
promotion=scores["promotion"],
highlight_visibility=scores["highlight_visibility"],
behavioral=scores["behavioral"],
failure=scores["failure"],
harmonious_color=scores["harmonious_color"],
immersiveness=scores["immersiveness"],
interaction=scores["interaction"],
interesting_subject=scores["interesting_subject"],
intrusive_object_presence=scores["intrusive_object_presence"],
lively_color=scores["lively_color"],
low_light=scores["low_light"],
noise=scores["noise"],
pleasant_camera_tilt=scores["pleasant_camera_tilt"],
pleasant_composition=scores["pleasant_composition"],
pleasant_lighting=scores["pleasant_lighting"],
pleasant_pattern=scores["pleasant_pattern"],
pleasant_perspective=scores["pleasant_perspective"],
pleasant_post_processing=scores["pleasant_post_processing"],
pleasant_reflection=scores["pleasant_reflection"],
pleasant_symmetry=scores["pleasant_symmetry"],
sharply_focused_subject=scores["sharply_focused_subject"],
tastefully_blurred=scores["tastefully_blurred"],
well_chosen_subject=scores["well_chosen_subject"],
well_framed_subject=scores["well_framed_subject"],
well_timed_shot=scores["well_timed_shot"],
)
return self._scoreinfo
except KeyError:
self._scoreinfo = ScoreInfo(
overall=0.0,
curation=0.0,
promotion=0.0,
highlight_visibility=0.0,
behavioral=0.0,
failure=0.0,
harmonious_color=0.0,
immersiveness=0.0,
interaction=0.0,
interesting_subject=0.0,
intrusive_object_presence=0.0,
lively_color=0.0,
low_light=0.0,
noise=0.0,
pleasant_camera_tilt=0.0,
pleasant_composition=0.0,
pleasant_lighting=0.0,
pleasant_pattern=0.0,
pleasant_perspective=0.0,
pleasant_post_processing=0.0,
pleasant_reflection=0.0,
pleasant_symmetry=0.0,
sharply_focused_subject=0.0,
tastefully_blurred=0.0,
well_chosen_subject=0.0,
well_framed_subject=0.0,
well_timed_shot=0.0,
)
return self._scoreinfo

View File

@@ -21,12 +21,16 @@ import yaml
from .._constants import ( from .._constants import (
_MOVIE_TYPE, _MOVIE_TYPE,
_PHOTO_TYPE, _PHOTO_TYPE,
_PHOTOS_4_ALBUM_KIND,
_PHOTOS_4_ROOT_FOLDER,
_PHOTOS_4_VERSION, _PHOTOS_4_VERSION,
_PHOTOS_5_ALBUM_KIND,
_PHOTOS_5_SHARED_ALBUM_KIND,
_PHOTOS_5_SHARED_PHOTO_PATH, _PHOTOS_5_SHARED_PHOTO_PATH,
) )
from ..albuminfo import AlbumInfo from ..albuminfo import AlbumInfo
from ..placeinfo import PlaceInfo4, PlaceInfo5
from ..phototemplate import PhotoTemplate from ..phototemplate import PhotoTemplate
from ..placeinfo import PlaceInfo4, PlaceInfo5
from ..utils import _debug, _get_resource_loc, findfiles, get_preferred_uti_extension from ..utils import _debug, _get_resource_loc, findfiles, get_preferred_uti_extension
@@ -55,6 +59,7 @@ class PhotoInfo:
_xmp_sidecar, _xmp_sidecar,
ExportResults, ExportResults,
) )
from ._photoinfo_scoreinfo import score, ScoreInfo
def __init__(self, db=None, uuid=None, info=None): def __init__(self, db=None, uuid=None, info=None):
self._uuid = uuid self._uuid = uuid
@@ -64,6 +69,7 @@ class PhotoInfo:
@property @property
def filename(self): def filename(self):
""" filename of the picture """ """ filename of the picture """
# sourcery off
if self.has_raw and self.raw_original: if self.has_raw and self.raw_original:
# return name of the RAW file # return name of the RAW file
# TODO: not yet implemented # TODO: not yet implemented
@@ -84,8 +90,7 @@ class PhotoInfo:
seconds = self._info["imageTimeZoneOffsetSeconds"] or 0 seconds = self._info["imageTimeZoneOffsetSeconds"] or 0
delta = timedelta(seconds=seconds) delta = timedelta(seconds=seconds)
tz = timezone(delta) tz = timezone(delta)
imagedate_utc = imagedate.astimezone(tz=tz) return imagedate.astimezone(tz=tz)
return imagedate_utc
@property @property
def date_modified(self): def date_modified(self):
@@ -96,8 +101,7 @@ class PhotoInfo:
seconds = self._info["imageTimeZoneOffsetSeconds"] or 0 seconds = self._info["imageTimeZoneOffsetSeconds"] or 0
delta = timedelta(seconds=seconds) delta = timedelta(seconds=seconds)
tz = timezone(delta) tz = timezone(delta)
imagedate_utc = imagedate.astimezone(tz=tz) return imagedate.astimezone(tz=tz)
return imagedate_utc
else: else:
return None return None
@@ -340,21 +344,26 @@ class PhotoInfo:
@property @property
def albums(self): def albums(self):
""" list of albums picture is contained in """ """ list of albums picture is contained in """
albums = [] try:
for album in self._info["albums"]: return self._albums
if not self._db._dbalbum_details[album]["intrash"]: except AttributeError:
albums.append(self._db._dbalbum_details[album]["title"]) album_uuids = self._get_album_uuids()
return albums self._albums = list(
{self._db._dbalbum_details[album]["title"] for album in album_uuids}
)
return self._albums
@property @property
def album_info(self): def album_info(self):
""" list of AlbumInfo objects representing albums the photos is contained in """ """ list of AlbumInfo objects representing albums the photos is contained in """
albums = [] try:
for album in self._info["albums"]: return self._album_info
if not self._db._dbalbum_details[album]["intrash"]: except AttributeError:
albums.append(AlbumInfo(db=self._db, uuid=album)) album_uuids = self._get_album_uuids()
self._album_info = [
return albums AlbumInfo(db=self._db, uuid=album) for album in album_uuids
]
return self._album_info
@property @property
def keywords(self): def keywords(self):
@@ -408,6 +417,11 @@ class PhotoInfo:
""" True if picture is hidden """ """ True if picture is hidden """
return True if self._info["hidden"] == 1 else False return True if self._info["hidden"] == 1 else False
@property
def intrash(self):
""" True if picture is in trash ('Recently Deleted' folder)"""
return self._info["intrash"]
@property @property
def location(self): def location(self):
""" returns (latitude, longitude) as float in degrees or None """ """ returns (latitude, longitude) as float in degrees or None """
@@ -484,12 +498,11 @@ class PhotoInfo:
self is not included in the returned list """ self is not included in the returned list """
if self._info["burst"]: if self._info["burst"]:
burst_uuid = self._info["burstUUID"] burst_uuid = self._info["burstUUID"]
burst_photos = [ return [
PhotoInfo(db=self._db, uuid=u, info=self._db._dbphotos[u]) PhotoInfo(db=self._db, uuid=u, info=self._db._dbphotos[u])
for u in self._db._dbphotos_burst[burst_uuid] for u in self._db._dbphotos_burst[burst_uuid]
if u != self._uuid if u != self._uuid
] ]
return burst_photos
else: else:
return [] return []
@@ -629,7 +642,49 @@ class PhotoInfo:
otherwise returns False """ otherwise returns False """
return self._info["raw_is_original"] return self._info["raw_is_original"]
def render_template(self, template_str, none_str="_", path_sep=None): @property
def height(self):
""" returns height of the current photo version in pixels """
return self._info["height"]
@property
def width(self):
""" returns width of the current photo version in pixels """
return self._info["width"]
@property
def orientation(self):
""" returns EXIF orientation of the current photo version as int """
return self._info["orientation"]
@property
def original_height(self):
""" returns height of the original photo version in pixels """
return self._info["original_height"]
@property
def original_width(self):
""" returns width of the original photo version in pixels """
return self._info["original_width"]
@property
def original_orientation(self):
""" returns EXIF orientation of the original photo version as int """
return self._info["original_orientation"]
@property
def original_filesize(self):
""" returns filesize of original photo in bytes as int """
return self._info["original_filesize"]
def render_template(
self,
template_str,
none_str="_",
path_sep=None,
expand_inplace=False,
inplace_sep=None,
):
"""Renders a template string for PhotoInfo instance using PhotoTemplate """Renders a template string for PhotoInfo instance using PhotoTemplate
Args: Args:
@@ -637,9 +692,22 @@ class PhotoInfo:
none_str: a str to use if template field renders to None, default is "_". none_str: a str to use if template field renders to None, default is "_".
path_sep: a single character str to use as path separator when joining path_sep: a single character str to use as path separator when joining
fields like folder_album; if not provided, defaults to os.path.sep fields like folder_album; if not provided, defaults to os.path.sep
expand_inplace: expand multi-valued substitutions in-place as a single string
instead of returning individual strings
inplace_sep: optional string to use as separator between multi-valued keywords
with expand_inplace; default is ','
Returns:
([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values
""" """
template = PhotoTemplate(self) template = PhotoTemplate(self)
return template.render(template_str, none_str, path_sep) return template.render(
template_str,
none_str=none_str,
path_sep=path_sep,
expand_inplace=expand_inplace,
inplace_sep=inplace_sep,
)
@property @property
def _longitude(self): def _longitude(self):
@@ -651,6 +719,37 @@ class PhotoInfo:
""" Returns latitude, in degrees """ """ Returns latitude, in degrees """
return self._info["latitude"] return self._info["latitude"]
def _get_album_uuids(self):
""" Return list of album UUIDs this photo is found in
Filters out albums in the trash and any special album types
Returns: list of album UUIDs
"""
if self._db._db_version <= _PHOTOS_4_VERSION:
version4 = True
album_kind = [_PHOTOS_4_ALBUM_KIND]
else:
version4 = False
album_kind = [_PHOTOS_5_SHARED_ALBUM_KIND, _PHOTOS_5_ALBUM_KIND]
album_list = []
for album in self._info["albums"]:
detail = self._db._dbalbum_details[album]
if (
detail["kind"] in album_kind
and not detail["intrash"]
and (
not version4
# in Photos <= 4, special albums like "printAlbum" have kind _PHOTOS_4_ALBUM_KIND
# but should not be listed here; they can be distinguished by looking
# for folderUuid of _PHOTOS_4_ROOT_FOLDER as opposed to _PHOTOS_4_TOP_LEVEL_ALBUM
or (version4 and detail["folderUuid"] != _PHOTOS_4_ROOT_FOLDER)
)
):
album_list.append(album)
return album_list
def __repr__(self): def __repr__(self):
return f"osxphotos.{self.__class__.__name__}(db={self._db}, uuid='{self._uuid}', info={self._info})" return f"osxphotos.{self.__class__.__name__}(db={self._db}, uuid='{self._uuid}', info={self._info})"
@@ -661,6 +760,8 @@ class PhotoInfo:
date_modified_iso = ( date_modified_iso = (
self.date_modified.isoformat() if self.date_modified else None self.date_modified.isoformat() if self.date_modified else None
) )
exif = str(self.exif_info) if self.exif_info else None
score = str(self.score) if self.score else None
info = { info = {
"uuid": self.uuid, "uuid": self.uuid,
@@ -701,6 +802,10 @@ class PhotoInfo:
"has_raw": self.has_raw, "has_raw": self.has_raw,
"uti_raw": self.uti_raw, "uti_raw": self.uti_raw,
"path_raw": self.path_raw, "path_raw": self.path_raw,
"place": self.place,
"exif": exif,
"score": score,
"intrash": self.intrash,
} }
return yaml.dump(info, sort_keys=False) return yaml.dump(info, sort_keys=False)
@@ -713,6 +818,7 @@ class PhotoInfo:
folders = {album.title: album.folder_names for album in self.album_info} folders = {album.title: album.folder_names for album in self.album_info}
exif = dataclasses.asdict(self.exif_info) if self.exif_info else {} exif = dataclasses.asdict(self.exif_info) if self.exif_info else {}
place = self.place.as_dict() if self.place else {} place = self.place.as_dict() if self.place else {}
score = dataclasses.asdict(self.score) if self.score else {}
pic = { pic = {
"uuid": self.uuid, "uuid": self.uuid,
@@ -758,15 +864,23 @@ class PhotoInfo:
"path_raw": self.path_raw, "path_raw": self.path_raw,
"place": place, "place": place,
"exif": exif, "exif": exif,
"score": score,
"intrash": self.intrash,
} }
return json.dumps(pic) return json.dumps(pic)
# compare two PhotoInfo objects for equality
def __eq__(self, other): def __eq__(self, other):
""" Compare two PhotoInfo objects for equality """
# Can't just compare the two __dicts__ because some methods (like albums)
# memoize their value once called in an instance variable (e.g. self._albums)
if isinstance(other, self.__class__): if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__ return (
self._db.db_path == other._db.db_path
and self.uuid == other.uuid
and self._info == other._info
)
return False return False
def __ne__(self, other): def __ne__(self, other):
""" Compare two PhotoInfo objects for inequality """
return not self.__eq__(other) return not self.__eq__(other)

View File

@@ -0,0 +1,145 @@
""" Methods for PhotosDB to add Photos 5 photo score info
ref: https://simonwillison.net/2020/May/21/dogsheep-photos/
"""
import logging
from .._constants import _PHOTOS_4_VERSION
from ..utils import _open_sql_file
"""
This module should be imported in the class defintion of PhotosDB in photosdb.py
Do not import this module directly
This module adds the following method to PhotosDB:
_process_scoreinfo: process photo score info
The following data structures are added to PhotosDB
self._db_scoreinfo_uuid
These methods only work on Photos 5 databases. Will print warning on earlier library versions.
"""
def _process_scoreinfo(self):
""" Process computed photo scores
Note: Only works on Photos version == 5.0
"""
# _db_scoreinfo_uuid is dict in form {uuid: {score values}}
self._db_scoreinfo_uuid = {}
if self._db_version <= _PHOTOS_4_VERSION:
raise NotImplementedError(
f"search info not implemented for this database version"
)
else:
_process_scoreinfo_5(self)
def _process_scoreinfo_5(photosdb):
""" Process computed photo scores for Photos 5 databases
Args:
photosdb: an OSXPhotosDB instance
"""
db = photosdb._tmp_db
(conn, cursor) = _open_sql_file(db)
result = cursor.execute(
"""
SELECT
ZGENERICASSET.ZUUID,
ZGENERICASSET.ZOVERALLAESTHETICSCORE,
ZGENERICASSET.ZCURATIONSCORE,
ZGENERICASSET.ZPROMOTIONSCORE,
ZGENERICASSET.ZHIGHLIGHTVISIBILITYSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZBEHAVIORALSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZFAILURESCORE,
ZCOMPUTEDASSETATTRIBUTES.ZHARMONIOUSCOLORSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZIMMERSIVENESSSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZINTERACTIONSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZINTERESTINGSUBJECTSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZINTRUSIVEOBJECTPRESENCESCORE,
ZCOMPUTEDASSETATTRIBUTES.ZLIVELYCOLORSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZLOWLIGHT,
ZCOMPUTEDASSETATTRIBUTES.ZNOISESCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTCAMERATILTSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTCOMPOSITIONSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTLIGHTINGSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTPATTERNSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTPERSPECTIVESCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTPOSTPROCESSINGSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTREFLECTIONSSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTSYMMETRYSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZSHARPLYFOCUSEDSUBJECTSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZTASTEFULLYBLURREDSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZWELLCHOSENSUBJECTSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZWELLFRAMEDSUBJECTSCORE,
ZCOMPUTEDASSETATTRIBUTES.ZWELLTIMEDSHOTSCORE
FROM ZGENERICASSET
JOIN ZCOMPUTEDASSETATTRIBUTES ON ZCOMPUTEDASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK
"""
)
# 0 ZGENERICASSET.ZUUID,
# 1 ZGENERICASSET.ZOVERALLAESTHETICSCORE,
# 2 ZGENERICASSET.ZCURATIONSCORE,
# 3 ZGENERICASSET.ZPROMOTIONSCORE,
# 4 ZGENERICASSET.ZHIGHLIGHTVISIBILITYSCORE,
# 5 ZCOMPUTEDASSETATTRIBUTES.ZBEHAVIORALSCORE,
# 6 ZCOMPUTEDASSETATTRIBUTES.ZFAILURESCORE,
# 7 ZCOMPUTEDASSETATTRIBUTES.ZHARMONIOUSCOLORSCORE,
# 8 ZCOMPUTEDASSETATTRIBUTES.ZIMMERSIVENESSSCORE,
# 9 ZCOMPUTEDASSETATTRIBUTES.ZINTERACTIONSCORE,
# 10 ZCOMPUTEDASSETATTRIBUTES.ZINTERESTINGSUBJECTSCORE,
# 11 ZCOMPUTEDASSETATTRIBUTES.ZINTRUSIVEOBJECTPRESENCESCORE,
# 12 ZCOMPUTEDASSETATTRIBUTES.ZLIVELYCOLORSCORE,
# 13 ZCOMPUTEDASSETATTRIBUTES.ZLOWLIGHT,
# 14 ZCOMPUTEDASSETATTRIBUTES.ZNOISESCORE,
# 15 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTCAMERATILTSCORE,
# 16 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTCOMPOSITIONSCORE,
# 17 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTLIGHTINGSCORE,
# 18 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTPATTERNSCORE,
# 19 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTPERSPECTIVESCORE,
# 20 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTPOSTPROCESSINGSCORE,
# 21 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTREFLECTIONSSCORE,
# 22 ZCOMPUTEDASSETATTRIBUTES.ZPLEASANTSYMMETRYSCORE,
# 23 ZCOMPUTEDASSETATTRIBUTES.ZSHARPLYFOCUSEDSUBJECTSCORE,
# 24 ZCOMPUTEDASSETATTRIBUTES.ZTASTEFULLYBLURREDSCORE,
# 25 ZCOMPUTEDASSETATTRIBUTES.ZWELLCHOSENSUBJECTSCORE,
# 26 ZCOMPUTEDASSETATTRIBUTES.ZWELLFRAMEDSUBJECTSCORE,
# 27 ZCOMPUTEDASSETATTRIBUTES.ZWELLTIMEDSHOTSCORE
for row in result:
uuid = row[0]
scores = {"uuid": uuid}
scores["overall_aesthetic"] = row[1]
scores["curation"] = row[2]
scores["promotion"] = row[3]
scores["highlight_visibility"] = row[4]
scores["behavioral"] = row[5]
scores["failure"] = row[6]
scores["harmonious_color"] = row[7]
scores["immersiveness"] = row[8]
scores["interaction"] = row[9]
scores["interesting_subject"] = row[10]
scores["intrusive_object_presence"] = row[11]
scores["lively_color"] = row[12]
scores["low_light"] = row[13]
scores["noise"] = row[14]
scores["pleasant_camera_tilt"] = row[15]
scores["pleasant_composition"] = row[16]
scores["pleasant_lighting"] = row[17]
scores["pleasant_pattern"] = row[18]
scores["pleasant_perspective"] = row[19]
scores["pleasant_post_processing"] = row[20]
scores["pleasant_reflection"] = row[21]
scores["pleasant_symmetry"] = row[22]
scores["sharply_focused_subject"] = row[23]
scores["tastefully_blurred"] = row[24]
scores["well_chosen_subject"] = row[25]
scores["well_framed_subject"] = row[26]
scores["well_timed_shot"] = row[27]
photosdb._db_scoreinfo_uuid[uuid] = scores

View File

@@ -102,7 +102,7 @@ def _process_searchinfo(self):
# 8: groups.lookup_identifier # 8: groups.lookup_identifier
for row in c: for row in c:
uuid = ints_to_uuid(row[1],row[2]) uuid = ints_to_uuid(row[1], row[2])
# strings have null character appended, so strip it # strings have null character appended, so strip it
record = {} record = {}
record["uuid"] = uuid record["uuid"] = uuid
@@ -123,13 +123,9 @@ def _process_searchinfo(self):
category = record["category"] category = record["category"]
try: try:
_db_searchinfo_categories[category].append( _db_searchinfo_categories[category].append(record["normalized_string"])
record["normalized_string"]
)
except KeyError: except KeyError:
_db_searchinfo_categories[category] = [ _db_searchinfo_categories[category] = [record["normalized_string"]]
record["normalized_string"]
]
if category == SEARCH_CATEGORY_LABEL: if category == SEARCH_CATEGORY_LABEL:
label = record["content_string"] label = record["content_string"]
@@ -198,6 +194,7 @@ def labels_normalized_as_dict(self):
# The following method is not imported into PhotosDB # The following method is not imported into PhotosDB
@lru_cache(maxsize=128) @lru_cache(maxsize=128)
def ints_to_uuid(uuid_0, uuid_1): def ints_to_uuid(uuid_0, uuid_1):
""" convert two signed ints into a UUID strings """ convert two signed ints into a UUID strings

View File

@@ -46,8 +46,6 @@ from ..utils import (
# TODO: Add test for imageTimeZoneOffsetSeconds = None # TODO: Add test for imageTimeZoneOffsetSeconds = None
# TODO: Fix command line so multiple --keyword, etc. are AND (instead of OR as they are in .photos())
# Or fix the help text to match behavior
# TODO: Add test for __str__ # TODO: Add test for __str__
# TODO: Add special albums and magic albums # TODO: Add special albums and magic albums
@@ -64,6 +62,7 @@ class PhotosDB:
labels_as_dict, labels_as_dict,
labels_normalized_as_dict, labels_normalized_as_dict,
) )
from ._photosdb_process_scoreinfo import _process_scoreinfo
def __init__(self, *dbfile_, dbfile=None): def __init__(self, *dbfile_, dbfile=None):
""" create a new PhotosDB object """ create a new PhotosDB object
@@ -254,7 +253,7 @@ class PhotosDB:
if _db_is_locked(self._dbfile): if _db_is_locked(self._dbfile):
self._tmp_db = self._copy_db_file(self._dbfile) self._tmp_db = self._copy_db_file(self._dbfile)
self._db_version = self._get_db_version() self._db_version = self._get_db_version(self._tmp_db)
# If Photos >= 5, actual data isn't in photos.db but in Photos.sqlite # If Photos >= 5, actual data isn't in photos.db but in Photos.sqlite
if int(self._db_version) > int(_PHOTOS_4_VERSION): if int(self._db_version) > int(_PHOTOS_4_VERSION):
@@ -294,18 +293,17 @@ class PhotosDB:
@property @property
def keywords_as_dict(self): def keywords_as_dict(self):
""" return keywords as dict of keyword, count in reverse sorted order (descending) """ """ return keywords as dict of keyword, count in reverse sorted order (descending) """
keywords = {} keywords = {
for k in self._dbkeywords_keyword.keys(): k: len(self._dbkeywords_keyword[k]) for k in self._dbkeywords_keyword.keys()
keywords[k] = len(self._dbkeywords_keyword[k]) }
keywords = dict(sorted(keywords.items(), key=lambda kv: kv[1], reverse=True)) keywords = dict(sorted(keywords.items(), key=lambda kv: kv[1], reverse=True))
return keywords return keywords
@property @property
def persons_as_dict(self): def persons_as_dict(self):
""" return persons as dict of person, count in reverse sorted order (descending) """ """ return persons as dict of person, count in reverse sorted order (descending) """
persons = {} persons = {k: len(self._dbfaces_person[k]) for k in self._dbfaces_person.keys()}
for k in self._dbfaces_person.keys():
persons[k] = len(self._dbfaces_person[k])
persons = dict(sorted(persons.items(), key=lambda kv: kv[1], reverse=True)) persons = dict(sorted(persons.items(), key=lambda kv: kv[1], reverse=True))
return persons return persons
@@ -313,18 +311,16 @@ class PhotosDB:
def albums_as_dict(self): def albums_as_dict(self):
""" return albums as dict of albums, count in reverse sorted order (descending) """ """ return albums as dict of albums, count in reverse sorted order (descending) """
albums = {} albums = {}
album_keys = [ album_keys = self._get_album_uuids(shared=False)
k for album in album_keys:
for k in self._dbalbums_album.keys() title = self._dbalbum_details[album]["title"]
if self._dbalbum_details[k]["cloudownerhashedpersonid"] is None if album in self._dbalbums_album:
and not self._dbalbum_details[k]["intrash"] try:
] albums[title] += len(self._dbalbums_album[album])
for k in album_keys: except KeyError:
title = self._dbalbum_details[k]["title"] albums[title] = len(self._dbalbums_album[album])
if title in albums:
albums[title] += len(self._dbalbums_album[k])
else: else:
albums[title] = len(self._dbalbums_album[k]) albums[title] = 0 # empty album
albums = dict(sorted(albums.items(), key=lambda kv: kv[1], reverse=True)) albums = dict(sorted(albums.items(), key=lambda kv: kv[1], reverse=True))
return albums return albums
@@ -333,25 +329,17 @@ class PhotosDB:
""" returns shared albums as dict of albums, count in reverse sorted order (descending) """ returns shared albums as dict of albums, count in reverse sorted order (descending)
valid only on Photos 5; on Photos <= 4, prints warning and returns empty dict """ valid only on Photos 5; on Photos <= 4, prints warning and returns empty dict """
# if _dbalbum_details[key]["cloudownerhashedpersonid"] is not None, then it's a shared album
if self._db_version <= _PHOTOS_4_VERSION:
logging.warning(
f"albums_shared not implemented for Photos versions < {_PHOTOS_5_VERSION}"
)
return {}
albums = {} albums = {}
album_keys = [ album_keys = self._get_album_uuids(shared=True)
k for album in album_keys:
for k in self._dbalbums_album.keys() title = self._dbalbum_details[album]["title"]
if self._dbalbum_details[k]["cloudownerhashedpersonid"] is not None if album in self._dbalbums_album:
] try:
for k in album_keys: albums[title] += len(self._dbalbums_album[album])
title = self._dbalbum_details[k]["title"] except KeyError:
if title in albums: albums[title] = len(self._dbalbums_album[album])
albums[title] += len(self._dbalbums_album[k])
else: else:
albums[title] = len(self._dbalbums_album[k]) albums[title] = 0 # empty album
albums = dict(sorted(albums.items(), key=lambda kv: kv[1], reverse=True)) albums = dict(sorted(albums.items(), key=lambda kv: kv[1], reverse=True))
return albums return albums
@@ -412,34 +400,28 @@ class PhotosDB:
@property @property
def album_info(self): def album_info(self):
""" return list of AlbumInfo objects for each album in the photos database """ """ return list of AlbumInfo objects for each album in the photos database """
try:
albums = [ return self._album_info
AlbumInfo(db=self, uuid=album) except AttributeError:
for album in self._dbalbums_album.keys() self._album_info = [
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is None AlbumInfo(db=self, uuid=album)
and not self._dbalbum_details[album]["intrash"] for album in self._get_album_uuids(shared=False)
] ]
return albums return self._album_info
@property @property
def album_info_shared(self): def album_info_shared(self):
""" return list of AlbumInfo objects for each shared album in the photos database """ return list of AlbumInfo objects for each shared album in the photos database
only valid for Photos 5; on Photos <= 4, prints warning and returns empty list """ only valid for Photos 5; on Photos <= 4, prints warning and returns empty list """
# if _dbalbum_details[key]["cloudownerhashedpersonid"] is not None, then it's a shared album # if _dbalbum_details[key]["cloudownerhashedpersonid"] is not None, then it's a shared album
try:
if self._db_version <= _PHOTOS_4_VERSION: return self._album_info_shared
logging.warning( except AttributeError:
f"albums_shared not implemented for Photos versions < {_PHOTOS_5_VERSION}" self._album_info_shared = [
) AlbumInfo(db=self, uuid=album)
return [] for album in self._get_album_uuids(shared=True)
]
albums_shared = [ return self._album_info_shared
AlbumInfo(db=self, uuid=album)
for album in self._dbalbums_album.keys()
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is not None
and not self._dbalbum_details[album]["intrash"]
]
return albums_shared
@property @property
def albums(self): def albums(self):
@@ -448,13 +430,11 @@ class PhotosDB:
# Could be more than one album with same name # Could be more than one album with same name
# Right now, they are treated as same album and photos are combined from albums with same name # Right now, they are treated as same album and photos are combined from albums with same name
albums = { try:
self._dbalbum_details[album]["title"] return self._albums
for album in self._dbalbums_album.keys() except AttributeError:
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is None self._albums = self._get_albums(shared=False)
and not self._dbalbum_details[album]["intrash"] return self._albums
}
return list(albums)
@property @property
def albums_shared(self): def albums_shared(self):
@@ -466,19 +446,11 @@ class PhotosDB:
# if _dbalbum_details[key]["cloudownerhashedpersonid"] is not None, then it's a shared album # if _dbalbum_details[key]["cloudownerhashedpersonid"] is not None, then it's a shared album
if self._db_version <= _PHOTOS_4_VERSION: try:
logging.warning( return self._albums_shared
f"album_names_shared not implemented for Photos versions < {_PHOTOS_5_VERSION}" except AttributeError:
) self._albums_shared = self._get_albums(shared=True)
return [] return self._albums_shared
albums = {
self._dbalbum_details[album]["title"]
for album in self._dbalbums_album.keys()
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is not None
and not self._dbalbum_details[album]["intrash"]
}
return list(albums)
@property @property
def db_version(self): def db_version(self):
@@ -495,6 +467,14 @@ class PhotosDB:
""" returns path to the Photos library PhotosDB was initialized with """ """ returns path to the Photos library PhotosDB was initialized with """
return self._library_path return self._library_path
def get_db_connection(self):
""" Get connection to the working copy of the Photos database
Returns:
tuple of (connection, cursor) to sqlite3 database
"""
return _open_sql_file(self._tmp_db)
def _copy_db_file(self, fname): def _copy_db_file(self, fname):
""" copies the sqlite database file to a temp file """ """ copies the sqlite database file to a temp file """
""" returns the name of the temp file """ """ returns the name of the temp file """
@@ -519,12 +499,18 @@ class PhotosDB:
return dest_path return dest_path
def _get_db_version(self): def _get_db_version(self, db_file):
""" gets the Photos DB version from LiGlobals table """ """ Gets the Photos DB version from LiGlobals table
""" returns the version as str"""
Args:
db_file: path to database file containing LiGlobals table
Returns: version as str
"""
version = None version = None
(conn, c) = _open_sql_file(self._tmp_db) (conn, c) = _open_sql_file(db_file)
# get database version # get database version
c.execute( c.execute(
@@ -624,6 +610,8 @@ class PhotosDB:
"folderUuid": album[5], "folderUuid": album[5],
"albumType": album[6], "albumType": album[6],
"albumSubclass": album[7], "albumSubclass": album[7],
# for compatability with Photos 5 where album kind is ZKIND
"kind": album[7],
} }
# get details about folders # get details about folders
@@ -727,9 +715,17 @@ class PhotosDB:
RKVersion.specialType, RKMaster.modelID, null, RKVersion.momentUuid, RKVersion.specialType, RKMaster.modelID, null, RKVersion.momentUuid,
RKVersion.rawMasterUuid, RKVersion.rawMasterUuid,
RKVersion.nonRawMasterUuid, RKVersion.nonRawMasterUuid,
RKMaster.alternateMasterUuid RKMaster.alternateMasterUuid,
FROM RKVersion, RKMaster WHERE RKVersion.isInTrash = 0 AND RKVersion.isInTrash,
RKVersion.masterUuid = RKMaster.uuid AND RKVersion.filename NOT LIKE '%.pdf' """ RKVersion.processedHeight,
RKVersion.processedWidth,
RKVersion.orientation,
RKMaster.height,
RKMaster.width,
RKMaster.orientation,
RKMaster.fileSize
FROM RKVersion, RKMaster
WHERE RKVersion.masterUuid = RKMaster.uuid"""
) )
else: else:
c.execute( c.execute(
@@ -746,9 +742,17 @@ class PhotosDB:
RKVersion.momentUuid, RKVersion.momentUuid,
RKVersion.rawMasterUuid, RKVersion.rawMasterUuid,
RKVersion.nonRawMasterUuid, RKVersion.nonRawMasterUuid,
RKMaster.alternateMasterUuid RKMaster.alternateMasterUuid,
FROM RKVersion, RKMaster WHERE RKVersion.isInTrash = 0 AND RKVersion.isInTrash,
RKVersion.masterUuid = RKMaster.uuid AND RKVersion.filename NOT LIKE '%.pdf' """ RKVersion.processedHeight,
RKVersion.processedWidth,
RKVersion.orientation,
RKMaster.height,
RKMaster.width,
RKMaster.orientation,
RKMaster.originalFileSize
FROM RKVersion, RKMaster
WHERE RKVersion.masterUuid = RKMaster.uuid"""
) )
# order of results # order of results
@@ -784,6 +788,14 @@ class PhotosDB:
# 29 RKVersion.rawMasterUuid, -- UUID of RAW master # 29 RKVersion.rawMasterUuid, -- UUID of RAW master
# 30 RKVersion.nonRawMasterUuid, -- UUID of non-RAW master # 30 RKVersion.nonRawMasterUuid, -- UUID of non-RAW master
# 31 RKMaster.alternateMasterUuid -- UUID of alternate master (will be RAW master for JPEG and JPEG master for RAW) # 31 RKMaster.alternateMasterUuid -- UUID of alternate master (will be RAW master for JPEG and JPEG master for RAW)
# 32 RKVersion.isInTrash
# 33 RKVersion.processedHeight,
# 34 RKVersion.processedWidth,
# 35 RKVersion.orientation,
# 36 RKMaster.height,
# 37 RKMaster.width,
# 38 RKMaster.orientation,
# 39 RKMaster.originalFileSize
for row in c: for row in c:
uuid = row[0] uuid = row[0]
@@ -810,7 +822,7 @@ class PhotosDB:
try: try:
self._dbphotos[uuid]["imageDate"] = datetime.fromtimestamp(row[5] + td) self._dbphotos[uuid]["imageDate"] = datetime.fromtimestamp(row[5] + td)
except ValueError: except ValueError:
self._dbphotos[uuid]["imageDate"] = datetime.date(1970, 1, 1) self._dbphotos[uuid]["imageDate"] = datetime(1970, 1, 1)
self._dbphotos[uuid]["mainRating"] = row[6] self._dbphotos[uuid]["mainRating"] = row[6]
self._dbphotos[uuid]["hasAdjustments"] = row[7] self._dbphotos[uuid]["hasAdjustments"] = row[7]
@@ -926,6 +938,18 @@ class PhotosDB:
self._dbphotos[uuid]["non_raw_master_uuid"] = row[30] self._dbphotos[uuid]["non_raw_master_uuid"] = row[30]
self._dbphotos[uuid]["alt_master_uuid"] = row[31] self._dbphotos[uuid]["alt_master_uuid"] = row[31]
# recently deleted items
self._dbphotos[uuid]["intrash"] = True if row[32] == 1 else False
# height/width/orientation
self._dbphotos[uuid]["height"] = row[33]
self._dbphotos[uuid]["width"] = row[34]
self._dbphotos[uuid]["orientation"] = row[35]
self._dbphotos[uuid]["original_height"] = row[36]
self._dbphotos[uuid]["original_width"] = row[37]
self._dbphotos[uuid]["original_orientation"] = row[38]
self._dbphotos[uuid]["original_filesize"] = row[39]
# get additional details from RKMaster, needed for RAW processing # get additional details from RKMaster, needed for RAW processing
c.execute( c.execute(
""" SELECT """ SELECT
@@ -976,8 +1000,7 @@ class PhotosDB:
RKModelResource.resourceTag, RKModelResource.UTI, RKVersion.specialType, RKModelResource.resourceTag, RKModelResource.UTI, RKVersion.specialType,
RKModelResource.attachedModelType, RKModelResource.resourceType RKModelResource.attachedModelType, RKModelResource.resourceType
FROM RKVersion FROM RKVersion
JOIN RKModelResource on RKModelResource.attachedModelId = RKVersion.modelId JOIN RKModelResource on RKModelResource.attachedModelId = RKVersion.modelId """
WHERE RKVersion.isInTrash = 0 """
) )
# Order of results: # Order of results:
@@ -1020,8 +1043,7 @@ class PhotosDB:
RKAdjustmentData.originator, RKAdjustmentData.originator,
RKAdjustmentData.format RKAdjustmentData.format
FROM RKVersion, RKAdjustmentData FROM RKVersion, RKAdjustmentData
WHERE RKVersion.adjustmentUuid = RKAdjustmentData.uuid WHERE RKVersion.adjustmentUuid = RKAdjustmentData.uuid """
AND RKVersion.isInTrash = 0 """
) )
for row in c: for row in c:
@@ -1043,8 +1065,6 @@ class PhotosDB:
INNER JOIN RKMaster on RKVersion.masterUuid = RKMaster.uuid INNER JOIN RKMaster on RKVersion.masterUuid = RKMaster.uuid
INNER JOIN RKModelResource on RKMaster.modelId = RKModelResource.attachedModelId INNER JOIN RKModelResource on RKMaster.modelId = RKModelResource.attachedModelId
WHERE RKModelResource.UTI = 'com.apple.quicktime-movie' WHERE RKModelResource.UTI = 'com.apple.quicktime-movie'
AND RKMaster.isInTrash = 0
AND RKVersion.isInTrash = 0
""" """
) )
@@ -1289,7 +1309,6 @@ class PhotosDB:
"SELECT ZPERSON.ZFULLNAME, ZGENERICASSET.ZUUID " "SELECT ZPERSON.ZFULLNAME, ZGENERICASSET.ZUUID "
"FROM ZPERSON, ZDETECTEDFACE, ZGENERICASSET " "FROM ZPERSON, ZDETECTEDFACE, ZGENERICASSET "
"WHERE ZDETECTEDFACE.ZPERSON = ZPERSON.Z_PK AND ZDETECTEDFACE.ZASSET = ZGENERICASSET.Z_PK " "WHERE ZDETECTEDFACE.ZPERSON = ZPERSON.Z_PK AND ZDETECTEDFACE.ZASSET = ZGENERICASSET.Z_PK "
"AND ZGENERICASSET.ZTRASHEDSTATE = 0"
) )
for person in c: for person in c:
if person[0] is None: if person[0] is None:
@@ -1313,7 +1332,6 @@ class PhotosDB:
"FROM ZGENERICASSET " "FROM ZGENERICASSET "
"JOIN Z_26ASSETS ON Z_26ASSETS.Z_34ASSETS = ZGENERICASSET.Z_PK " "JOIN Z_26ASSETS ON Z_26ASSETS.Z_34ASSETS = ZGENERICASSET.Z_PK "
"JOIN ZGENERICALBUM ON ZGENERICALBUM.Z_PK = Z_26ASSETS.Z_26ALBUMS " "JOIN ZGENERICALBUM ON ZGENERICALBUM.Z_PK = Z_26ASSETS.Z_26ALBUMS "
"WHERE ZGENERICASSET.ZTRASHEDSTATE = 0 "
) )
for album in c: for album in c:
# store by uuid in _dbalbums_uuid and by album in _dbalbums_album # store by uuid in _dbalbums_uuid and by album in _dbalbums_album
@@ -1415,7 +1433,6 @@ class PhotosDB:
"JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK " "JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK "
"JOIN Z_1KEYWORDS ON Z_1KEYWORDS.Z_1ASSETATTRIBUTES = ZADDITIONALASSETATTRIBUTES.Z_PK " "JOIN Z_1KEYWORDS ON Z_1KEYWORDS.Z_1ASSETATTRIBUTES = ZADDITIONALASSETATTRIBUTES.Z_PK "
"JOIN ZKEYWORD ON ZKEYWORD.Z_PK = Z_1KEYWORDS.Z_37KEYWORDS " "JOIN ZKEYWORD ON ZKEYWORD.Z_PK = Z_1KEYWORDS.Z_37KEYWORDS "
"WHERE ZGENERICASSET.ZTRASHEDSTATE = 0 "
) )
for keyword in c: for keyword in c:
if not keyword[1] in self._dbkeywords_uuid: if not keyword[1] in self._dbkeywords_uuid:
@@ -1469,10 +1486,17 @@ class PhotosDB:
ZGENERICASSET.ZCLOUDASSETGUID, ZGENERICASSET.ZCLOUDASSETGUID,
ZADDITIONALASSETATTRIBUTES.ZREVERSELOCATIONDATA, ZADDITIONALASSETATTRIBUTES.ZREVERSELOCATIONDATA,
ZGENERICASSET.ZMOMENT, ZGENERICASSET.ZMOMENT,
ZADDITIONALASSETATTRIBUTES.ZORIGINALRESOURCECHOICE ZADDITIONALASSETATTRIBUTES.ZORIGINALRESOURCECHOICE,
ZGENERICASSET.ZTRASHEDSTATE,
ZGENERICASSET.ZHEIGHT,
ZGENERICASSET.ZWIDTH,
ZGENERICASSET.ZORIENTATION,
ZADDITIONALASSETATTRIBUTES.ZORIGINALHEIGHT,
ZADDITIONALASSETATTRIBUTES.ZORIGINALWIDTH,
ZADDITIONALASSETATTRIBUTES.ZORIGINALORIENTATION,
ZADDITIONALASSETATTRIBUTES.ZORIGINALFILESIZE
FROM ZGENERICASSET FROM ZGENERICASSET
JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK
WHERE ZGENERICASSET.ZTRASHEDSTATE = 0
ORDER BY ZGENERICASSET.ZUUID """ ORDER BY ZGENERICASSET.ZUUID """
) )
# Order of results # Order of results
@@ -1505,6 +1529,14 @@ class PhotosDB:
# 25 ZADDITIONALASSETATTRIBUTES.ZREVERSELOCATIONDATA -- reverse geolocation data # 25 ZADDITIONALASSETATTRIBUTES.ZREVERSELOCATIONDATA -- reverse geolocation data
# 26 ZGENERICASSET.ZMOMENT -- FK for ZMOMENT.Z_PK # 26 ZGENERICASSET.ZMOMENT -- FK for ZMOMENT.Z_PK
# 27 ZADDITIONALASSETATTRIBUTES.ZORIGINALRESOURCECHOICE -- 1 if associated RAW image is original else 0 # 27 ZADDITIONALASSETATTRIBUTES.ZORIGINALRESOURCECHOICE -- 1 if associated RAW image is original else 0
# 28 ZGENERICASSET.ZTRASHEDSTATE -- 0 if not in trash, 1 if in trash
# 29 ZGENERICASSET.ZHEIGHT,
# 30 ZGENERICASSET.ZWIDTH,
# 31 ZGENERICASSET.ZORIENTATION,
# 32 ZADDITIONALASSETATTRIBUTES.ZORIGINALHEIGHT,
# 33 ZADDITIONALASSETATTRIBUTES.ZORIGINALWIDTH,
# 34 ZADDITIONALASSETATTRIBUTES.ZORIGINALORIENTATION,
# 35 ZADDITIONALASSETATTRIBUTES.ZORIGINALFILESIZE
for row in c: for row in c:
uuid = row[0] uuid = row[0]
@@ -1528,7 +1560,7 @@ class PhotosDB:
try: try:
info["imageDate"] = datetime.fromtimestamp(row[5] + td) info["imageDate"] = datetime.fromtimestamp(row[5] + td)
except ValueError: except ValueError:
info["imageDate"] = datetime.date(1970, 1, 1) info["imageDate"] = datetime(1970, 1, 1)
info["imageTimeZoneOffsetSeconds"] = row[6] info["imageTimeZoneOffsetSeconds"] = row[6]
info["hidden"] = row[9] info["hidden"] = row[9]
@@ -1653,6 +1685,18 @@ class PhotosDB:
info["original_resource_choice"] = row[27] info["original_resource_choice"] = row[27]
info["raw_is_original"] = True if row[27] == 1 else False info["raw_is_original"] = True if row[27] == 1 else False
# recently deleted items
info["intrash"] = True if row[28] == 1 else False
# height/width/orientation
info["height"] = row[29]
info["width"] = row[30]
info["orientation"] = row[31]
info["original_height"] = row[32]
info["original_width"] = row[33]
info["original_orientation"] = row[34]
info["original_filesize"] = row[35]
# associated RAW image info # associated RAW image info
# will be filled in later # will be filled in later
info["has_raw"] = False info["has_raw"] = False
@@ -1724,8 +1768,6 @@ class PhotosDB:
# determine if a photo is missing in Photos 5 # determine if a photo is missing in Photos 5
# Get info on remote/local availability for photos in shared albums # Get info on remote/local availability for photos in shared albums
# Shared photos have a null fingerprint (and some other photos do too)
# TODO: There may be a bug here, perhaps ZDATASTORESUBTYPE should be 1 --> it's the longest ZDATALENGTH (is this the original)
c.execute( c.execute(
""" SELECT """ SELECT
ZGENERICASSET.ZUUID, ZGENERICASSET.ZUUID,
@@ -1734,10 +1776,7 @@ class PhotosDB:
FROM ZGENERICASSET FROM ZGENERICASSET
JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK
JOIN ZINTERNALRESOURCE ON ZINTERNALRESOURCE.ZASSET = ZADDITIONALASSETATTRIBUTES.ZASSET JOIN ZINTERNALRESOURCE ON ZINTERNALRESOURCE.ZASSET = ZADDITIONALASSETATTRIBUTES.ZASSET
WHERE ZDATASTORESUBTYPE = 0 OR ZDATASTORESUBTYPE = 3 """ WHERE ZDATASTORESUBTYPE = 1 OR ZDATASTORESUBTYPE = 3 """
# WHERE ZDATASTORESUBTYPE = 1 OR ZDATASTORESUBTYPE = 3 """
# WHERE ZDATASTORESUBTYPE = 0 OR ZDATASTORESUBTYPE = 3 """
# WHERE ZINTERNALRESOURCE.ZFINGERPRINT IS NULL AND ZINTERNALRESOURCE.ZDATASTORESUBTYPE = 3 """
) )
for row in c: for row in c:
@@ -1870,6 +1909,9 @@ class PhotosDB:
# process exif info # process exif info
self._process_exifinfo() self._process_exifinfo()
# process computed scores
self._process_scoreinfo()
# done processing, dump debug data if requested # done processing, dump debug data if requested
if _debug(): if _debug():
logging.debug("Faces (_dbfaces_uuid):") logging.debug("Faces (_dbfaces_uuid):")
@@ -2090,6 +2132,65 @@ class PhotosDB:
hierarchy = _recurse_folder_hierarchy(folders) hierarchy = _recurse_folder_hierarchy(folders)
return hierarchy return hierarchy
def _get_album_uuids(self, shared=False):
""" Return list of album UUIDs found in photos database
Filters out albums in the trash and any special album types
Args:
shared: boolean; if True, returns shared albums, else normal albums
Returns: list of album UUIDs
"""
if self._db_version <= _PHOTOS_4_VERSION:
version4 = True
if shared:
logging.warning(
f"Shared albums not implemented for Photos library version {self._db_version}"
)
return [] # not implemented for _PHOTOS_4_VERSION
else:
album_kind = _PHOTOS_4_ALBUM_KIND
else:
version4 = False
album_kind = _PHOTOS_5_SHARED_ALBUM_KIND if shared else _PHOTOS_5_ALBUM_KIND
album_list = []
# look through _dbalbum_details because _dbalbums_album won't have empty albums it
for album, detail in self._dbalbum_details.items():
if (
detail["kind"] == album_kind
and not detail["intrash"]
and (
(shared and detail["cloudownerhashedpersonid"] is not None)
or (not shared and detail["cloudownerhashedpersonid"] is None)
)
and (
not version4
# in Photos 4, special albums like "printAlbum" have kind _PHOTOS_4_ALBUM_KIND
# but should not be listed here; they can be distinguished by looking
# for folderUuid of _PHOTOS_4_ROOT_FOLDER as opposed to _PHOTOS_4_TOP_LEVEL_ALBUM
or (version4 and detail["folderUuid"] != _PHOTOS_4_ROOT_FOLDER)
)
):
album_list.append(album)
return album_list
def _get_albums(self, shared=False):
""" Return list of album titles found in photos database
Albums may have duplicate titles -- these will be treated as a single album.
Filters out albums in the trash and any special album types
Args:
shared: boolean; if True, returns shared albums, else normal albums
Returns: list of album names
"""
album_uuids = self._get_album_uuids(shared=shared)
return list({self._dbalbum_details[album]["title"] for album in album_uuids})
def photos( def photos(
self, self,
keywords=None, keywords=None,
@@ -2097,9 +2198,10 @@ class PhotosDB:
persons=None, persons=None,
albums=None, albums=None,
images=True, images=True,
movies=False, movies=True,
from_date=None, from_date=None,
to_date=None, to_date=None,
intrash=False,
): ):
""" """
Return a list of PhotoInfo objects Return a list of PhotoInfo objects
@@ -2113,9 +2215,11 @@ class PhotosDB:
persons: list of persons to search for persons: list of persons to search for
albums: list of album names to search for albums: list of album names to search for
images: if True, returns image files, if False, does not return images; default is True images: if True, returns image files, if False, does not return images; default is True
movies: if True, returns movie files, if False, does not return movies; default is False movies: if True, returns movie files, if False, does not return movies; default is True
from_date: return photos with creation date >= from_date (datetime.datetime object, default None) from_date: return photos with creation date >= from_date (datetime.datetime object, default None)
to_date: return photos with creation date <= to_date (datetime.datetime object, default None) to_date: return photos with creation date <= to_date (datetime.datetime object, default None)
intrash: if True, returns only images in "Recently deleted items" folder,
if False returns only photos that aren't deleted; default is False
""" """
# implementation is a bit kludgy but it works # implementation is a bit kludgy but it works
@@ -2123,6 +2227,15 @@ class PhotosDB:
# use results to build a list of PhotoInfo objects # use results to build a list of PhotoInfo objects
photos_sets = [] # list of photo sets to perform intersection of photos_sets = [] # list of photo sets to perform intersection of
if intrash:
photos_sets.append(
{p for p in self._dbphotos if self._dbphotos[p]["intrash"]}
)
else:
photos_sets.append(
{p for p in self._dbphotos if not self._dbphotos[p]["intrash"]}
)
if not any([keywords, uuid, persons, albums, from_date, to_date]): if not any([keywords, uuid, persons, albums, from_date, to_date]):
# return all the photos, filtering for images and movies # return all the photos, filtering for images and movies
# append keys of all photos as a single set to photos_sets # append keys of all photos as a single set to photos_sets
@@ -2131,12 +2244,15 @@ class PhotosDB:
if albums: if albums:
album_set = set() album_set = set()
for album in albums: for album in albums:
# TODO: can have >1 album with same name. This globs them together. # glob together albums with same name
# Need a way to select which album?
if album in self._dbalbum_titles: if album in self._dbalbum_titles:
title_set = set() title_set = set()
for album_id in self._dbalbum_titles[album]: for album_id in self._dbalbum_titles[album]:
title_set.update(self._dbalbums_album[album_id]) try:
title_set.update(self._dbalbums_album[album_id])
except KeyError:
# an empty album will be in _dbalbum_titles but not _dbalbums_album
pass
album_set.update(title_set) album_set.update(title_set)
else: else:
logging.debug(f"Could not find album '{album}' in database") logging.debug(f"Could not find album '{album}' in database")
@@ -2169,7 +2285,7 @@ class PhotosDB:
logging.debug(f"Could not find person '{person}' in database") logging.debug(f"Could not find person '{person}' in database")
photos_sets.append(person_set) photos_sets.append(person_set)
if from_date or to_date: if from_date or to_date: # sourcery off
dsel = self._dbphotos dsel = self._dbphotos
if from_date: if from_date:
dsel = { dsel = {
@@ -2186,7 +2302,6 @@ class PhotosDB:
photoinfo = [] photoinfo = []
if photos_sets: # found some photos if photos_sets: # found some photos
# get the intersection of each argument/search criteria # get the intersection of each argument/search criteria
logging.debug(f"Got photo_sets: {photos_sets}")
for p in set.intersection(*photos_sets): for p in set.intersection(*photos_sets):
# filter for non-selected burst photos # filter for non-selected burst photos
if self._dbphotos[p]["burst"] and not self._dbphotos[p]["burst_key"]: if self._dbphotos[p]["burst"] and not self._dbphotos[p]["burst_key"]:
@@ -2215,5 +2330,7 @@ class PhotosDB:
return False return False
def __len__(self): def __len__(self):
""" returns number of photos in the database """ """ Returns number of photos in the database
Includes recently deleted photos and non-selected burst images
"""
return len(self._dbphotos) return len(self._dbphotos)

View File

@@ -1,5 +1,6 @@
""" Custom template system for osxphotos (implemented in PhotoInfo.render_template) """ """ Custom template system for osxphotos (implemented in PhotoInfo.render_template) """
# Rolled my own template system because: # Rolled my own template system because:
# 1. Needed to handle multiple values (e.g. album, keyword) # 1. Needed to handle multiple values (e.g. album, keyword)
# 2. Needed to handle default values if template not found # 2. Needed to handle default values if template not found
@@ -8,7 +9,7 @@
# 4. Couldn't figure out how to do #1 and #2 with str.format() # 4. Couldn't figure out how to do #1 and #2 with str.format()
# #
# This code isn't elegant but it seems to work well. PRs gladly accepted. # This code isn't elegant but it seems to work well. PRs gladly accepted.
import datetime
import locale import locale
import os import os
import re import re
@@ -35,6 +36,14 @@ TEMPLATE_SUBSTITUTIONS = {
"{created.dd}": "2-digit day of the month (zero padded) of file creation time", "{created.dd}": "2-digit day of the month (zero padded) of file creation time",
"{created.dow}": "Day of week in user's locale of the file creation time", "{created.dow}": "Day of week in user's locale of the file creation time",
"{created.doy}": "3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)", "{created.doy}": "3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)",
"{created.hour}": "2-digit hour of the file creation time",
"{created.min}": "2-digit minute of the file creation time",
"{created.sec}": "2-digit second of the file creation time",
"{created.strftime}": "Apply strftime template to file creation date/time. Should be used in form "
+ "{created.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. "
+ "{created.strftime,%Y-%U} would result in year-week number of year: '2020-23'. "
+ "If used with no template will return null value. "
+ "See https://strftime.org/ for help on strftime templates.",
"{modified.date}": "Photo's modification date in ISO format, e.g. '2020-03-22'", "{modified.date}": "Photo's modification date in ISO format, e.g. '2020-03-22'",
"{modified.year}": "4-digit year of file modification time", "{modified.year}": "4-digit year of file modification time",
"{modified.yy}": "2-digit year of file modification time", "{modified.yy}": "2-digit year of file modification time",
@@ -43,6 +52,31 @@ TEMPLATE_SUBSTITUTIONS = {
"{modified.mon}": "Month abbreviation in the user's locale of the file modification time", "{modified.mon}": "Month abbreviation in the user's locale of the file modification time",
"{modified.dd}": "2-digit day of the month (zero padded) of the file modification time", "{modified.dd}": "2-digit day of the month (zero padded) of the file modification time",
"{modified.doy}": "3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)", "{modified.doy}": "3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)",
"{modified.hour}": "2-digit hour of the file modification time",
"{modified.min}": "2-digit minute of the file modification time",
"{modified.sec}": "2-digit second of the file modification time",
# "{modified.strftime}": "Apply strftime template to file modification date/time. Should be used in form "
# + "{modified.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. "
# + "{modified.strftime,%Y-%U} would result in year-week number of year: '2020-23'. "
# + "If used with no template will return null value. "
# + "See https://strftime.org/ for help on strftime templates.",
"{today.date}": "Current date in iso format, e.g. '2020-03-22'",
"{today.year}": "4-digit year of current date",
"{today.yy}": "2-digit year of current date",
"{today.mm}": "2-digit month of the current date (zero padded)",
"{today.month}": "Month name in user's locale of the current date",
"{today.mon}": "Month abbreviation in the user's locale of the current date",
"{today.dd}": "2-digit day of the month (zero padded) of current date",
"{today.dow}": "Day of week in user's locale of the current date",
"{today.doy}": "3-digit day of year (e.g Julian day) of current date, starting from 1 (zero padded)",
"{today.hour}": "2-digit hour of the current date",
"{today.min}": "2-digit minute of the current date",
"{today.sec}": "2-digit second of the current date",
"{today.strftime}": "Apply strftime template to current date/time. Should be used in form "
+ "{today.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. "
+ "{today.strftime,%Y-%U} would result in year-week number of year: '2020-23'. "
+ "If used with no template will return null value. "
+ "See https://strftime.org/ for help on strftime templates.",
"{place.name}": "Place name from the photo's reverse geolocation data, as displayed in Photos", "{place.name}": "Place name from the photo's reverse geolocation data, as displayed in Photos",
"{place.country_code}": "The ISO country code from the photo's reverse geolocation data", "{place.country_code}": "The ISO country code from the photo's reverse geolocation data",
"{place.name.country}": "Country name from the photo's reverse geolocation data", "{place.name.country}": "Country name from the photo's reverse geolocation data",
@@ -71,7 +105,7 @@ TEMPLATE_SUBSTITUTIONS_MULTI_VALUED = {
# Just the multi-valued substitution names without the braces # Just the multi-valued substitution names without the braces
MULTI_VALUE_SUBSTITUTIONS = [ MULTI_VALUE_SUBSTITUTIONS = [
field.replace("{", "").replace("}", "") field.replace("{", "").replace("}", "")
for field in TEMPLATE_SUBSTITUTIONS_MULTI_VALUED.keys() for field in TEMPLATE_SUBSTITUTIONS_MULTI_VALUED
] ]
@@ -86,16 +120,41 @@ class PhotoTemplate:
""" """
self.photo = photo self.photo = photo
def render(self, template, none_str="_", path_sep=None): # holds value of current date/time for {today.x} fields
""" render a filename or directory template # gets initialized in get_template_value
self.today = None
def render(
self,
template,
none_str="_",
path_sep=None,
expand_inplace=False,
inplace_sep=None,
):
""" Render a filename or directory template
Args:
template: str template template: str template
none_str: str to use default for None values, default is '_' none_str: str to use default for None values, default is '_'
path_sep: optional character to use as path separator, default is os.path.sep """ path_sep: optional character to use as path separator, default is os.path.sep
expand_inplace: expand multi-valued substitutions in-place as a single string
instead of returning individual strings
inplace_sep: optional string to use as separator between multi-valued keywords
with expand_inplace; default is ','
Returns:
([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values
"""
if path_sep is None: if path_sep is None:
path_sep = os.path.sep path_sep = os.path.sep
elif path_sep is not None and len(path_sep) != 1: elif path_sep is not None and len(path_sep) != 1:
raise ValueError(f"path_sep must be single character: {path_sep}") raise ValueError(f"path_sep must be single character: {path_sep}")
if inplace_sep is None:
inplace_sep = ","
# the rendering happens in two phases: # the rendering happens in two phases:
# phase 1: handle all the single-value template substitutions # phase 1: handle all the single-value template substitutions
# results in a single string with all the template fields replaced # results in a single string with all the template fields replaced
@@ -107,7 +166,7 @@ class PhotoTemplate:
# regex to find {template_field,optional_default} in strings # regex to find {template_field,optional_default} in strings
# for explanation of regex see https://regex101.com/r/4JJg42/1 # for explanation of regex see https://regex101.com/r/4JJg42/1
# pylint: disable=anomalous-backslash-in-string # pylint: disable=anomalous-backslash-in-string
regex = r"(?<!\{)\{([^\\,}]+)(,{0,1}(([\w\-. ]+))?)(?=\}(?!\}))\}" regex = r"(?<!\{)\{([^\\,}]+)(,{0,1}(([\w\-\%. ]+))?)(?=\}(?!\}))\}"
if type(template) is not str: if type(template) is not str:
raise TypeError(f"template must be type str, not {type(template)}") raise TypeError(f"template must be type str, not {type(template)}")
@@ -122,7 +181,7 @@ class PhotoTemplate:
groups = len(matchobj.groups()) groups = len(matchobj.groups())
if groups == 4: if groups == 4:
try: try:
val = get_func(matchobj.group(1)) val = get_func(matchobj.group(1), matchobj.group(3))
except ValueError: except ValueError:
return matchobj.group(0) return matchobj.group(0)
@@ -172,7 +231,7 @@ class PhotoTemplate:
rendered_strings = set([rendered]) rendered_strings = set([rendered])
for field in MULTI_VALUE_SUBSTITUTIONS: for field in MULTI_VALUE_SUBSTITUTIONS:
# Build a regex that matches only the field being processed # Build a regex that matches only the field being processed
re_str = r"(?<!\\)\{(" + field + r")(,(([\w\-. ]{0,})))?\}" re_str = r"(?<!\\)\{(" + field + r")(,(([\w\-\%. ]{0,})))?\}"
regex_multi = re.compile(re_str) regex_multi = re.compile(re_str)
# holds each of the new rendered_strings, set() to avoid duplicates # holds each of the new rendered_strings, set() to avoid duplicates
@@ -181,12 +240,19 @@ class PhotoTemplate:
for str_template in rendered_strings: for str_template in rendered_strings:
if regex_multi.search(str_template): if regex_multi.search(str_template):
values = self.get_template_value_multi(field, path_sep) values = self.get_template_value_multi(field, path_sep)
for val in values: if expand_inplace:
# instead of returning multiple strings, join values into a single string
val = (
inplace_sep.join(sorted(values))
if values and values[0]
else None
)
def lookup_template_value_multi(lookup_value): def lookup_template_value_multi(lookup_value, default):
""" Closure passed to make_subst_function get_func """ Closure passed to make_subst_function get_func
Capture val and field in the closure Capture val and field in the closure
Allows make_subst_function to be re-used w/o modification """ Allows make_subst_function to be re-used w/o modification
default is not used but required so signature matches get_template_value """
if lookup_value == field: if lookup_value == field:
return val return val
else: else:
@@ -196,10 +262,33 @@ class PhotoTemplate:
self, none_str, get_func=lookup_template_value_multi self, none_str, get_func=lookup_template_value_multi
) )
new_string = regex_multi.sub(subst, str_template) new_string = regex_multi.sub(subst, str_template)
new_strings.add(new_string)
# update rendered_strings for the next field to process # update rendered_strings for the next field to process
rendered_strings = new_strings rendered_strings = {new_string}
else:
# create a new template string for each value
for val in values:
def lookup_template_value_multi(lookup_value, default):
""" Closure passed to make_subst_function get_func
Capture val and field in the closure
Allows make_subst_function to be re-used w/o modification
default is not used but required so signature matches get_template_value """
if lookup_value == field:
return val
else:
raise ValueError(
f"Unexpected value: {lookup_value}"
)
subst = make_subst_function(
self, none_str, get_func=lookup_template_value_multi
)
new_string = regex_multi.sub(subst, str_template)
new_strings.add(new_string)
# update rendered_strings for the next field to process
rendered_strings = new_strings
# find any {fields} that weren't replaced # find any {fields} that weren't replaced
unmatched = [] unmatched = []
@@ -220,11 +309,12 @@ class PhotoTemplate:
return rendered_strings, unmatched return rendered_strings, unmatched
def get_template_value(self, field): def get_template_value(self, field, default):
"""lookup value for template field (single-value template substitutions) """lookup value for template field (single-value template substitutions)
Args: Args:
field: template field to find value for. field: template field to find value for.
default: the default value provided by the user
Returns: Returns:
The matching template value (which may be None). The matching template value (which may be None).
@@ -233,173 +323,278 @@ class PhotoTemplate:
ValueError if no rule exists for field. ValueError if no rule exists for field.
""" """
# initialize today with current date/time if needed
if self.today is None:
self.today = datetime.datetime.now()
# must be a valid keyword # must be a valid keyword
if field =="name": if field == "name":
return pathlib.Path(self.photo.filename).stem return pathlib.Path(self.photo.filename).stem
if field =="original_name": if field == "original_name":
return pathlib.Path(self.photo.original_filename).stem return pathlib.Path(self.photo.original_filename).stem
if field =="title": if field == "title":
return self.photo.title return self.photo.title
if field =="descr": if field == "descr":
return self.photo.description return self.photo.description
if field =="created.date": if field == "created.date":
return DateTimeFormatter(self.photo.date).date return DateTimeFormatter(self.photo.date).date
if field =="created.year": if field == "created.year":
return DateTimeFormatter(self.photo.date).year return DateTimeFormatter(self.photo.date).year
if field =="created.yy": if field == "created.yy":
return DateTimeFormatter(self.photo.date).yy return DateTimeFormatter(self.photo.date).yy
if field =="created.mm": if field == "created.mm":
return DateTimeFormatter(self.photo.date).mm return DateTimeFormatter(self.photo.date).mm
if field =="created.month": if field == "created.month":
return DateTimeFormatter(self.photo.date).month return DateTimeFormatter(self.photo.date).month
if field =="created.mon": if field == "created.mon":
return DateTimeFormatter(self.photo.date).mon return DateTimeFormatter(self.photo.date).mon
if field =="created.dd": if field == "created.dd":
return DateTimeFormatter(self.photo.date).dd return DateTimeFormatter(self.photo.date).dd
if field =="created.dow": if field == "created.dow":
return DateTimeFormatter(self.photo.date).dow return DateTimeFormatter(self.photo.date).dow
if field =="created.doy": if field == "created.doy":
return DateTimeFormatter(self.photo.date).doy return DateTimeFormatter(self.photo.date).doy
if field =="modified.date": if field == "created.hour":
return DateTimeFormatter(self.photo.date).hour
if field == "created.min":
return DateTimeFormatter(self.photo.date).min
if field == "created.sec":
return DateTimeFormatter(self.photo.date).sec
if field == "created.strftime":
if default:
try:
return self.photo.date.strftime(default)
except:
raise ValueError(f"Invalid strftime template: '{default}'")
else:
return None
if field == "modified.date":
return ( return (
DateTimeFormatter(self.photo.date_modified).date DateTimeFormatter(self.photo.date_modified).date
if self.photo.date_modified if self.photo.date_modified
else None else None
) )
if field =="modified.year": if field == "modified.year":
return ( return (
DateTimeFormatter(self.photo.date_modified).year DateTimeFormatter(self.photo.date_modified).year
if self.photo.date_modified if self.photo.date_modified
else None else None
) )
if field =="modified.yy": if field == "modified.yy":
return ( return (
DateTimeFormatter(self.photo.date_modified).yy if self.photo.date_modified else None DateTimeFormatter(self.photo.date_modified).yy
if self.photo.date_modified
else None
) )
if field =="modified.mm": if field == "modified.mm":
return ( return (
DateTimeFormatter(self.photo.date_modified).mm if self.photo.date_modified else None DateTimeFormatter(self.photo.date_modified).mm
if self.photo.date_modified
else None
) )
if field =="modified.month": if field == "modified.month":
return ( return (
DateTimeFormatter(self.photo.date_modified).month DateTimeFormatter(self.photo.date_modified).month
if self.photo.date_modified if self.photo.date_modified
else None else None
) )
if field =="modified.mon": if field == "modified.mon":
return ( return (
DateTimeFormatter(self.photo.date_modified).mon DateTimeFormatter(self.photo.date_modified).mon
if self.photo.date_modified if self.photo.date_modified
else None else None
) )
if field =="modified.dd": if field == "modified.dd":
return ( return (
DateTimeFormatter(self.photo.date_modified).dd if self.photo.date_modified else None DateTimeFormatter(self.photo.date_modified).dd
if self.photo.date_modified
else None
) )
if field =="modified.doy": if field == "modified.doy":
return ( return (
DateTimeFormatter(self.photo.date_modified).doy DateTimeFormatter(self.photo.date_modified).doy
if self.photo.date_modified if self.photo.date_modified
else None else None
) )
if field =="place.name": if field == "modified.hour":
return (
DateTimeFormatter(self.photo.date_modified).hour
if self.photo.date_modified
else None
)
if field == "modified.min":
return (
DateTimeFormatter(self.photo.date_modified).min
if self.photo.date_modified
else None
)
if field == "modified.sec":
return (
DateTimeFormatter(self.photo.date_modified).sec
if self.photo.date_modified
else None
)
# TODO: disabling modified.strftime for now because now clean way to pass
# a default value if modified time is None
# if field == "modified.strftime":
# if default and self.photo.date_modified:
# try:
# return self.photo.date_modified.strftime(default)
# except:
# raise ValueError(f"Invalid strftime template: '{default}'")
# else:
# return None
if field == "today.date":
return DateTimeFormatter(self.today).date
if field == "today.year":
return DateTimeFormatter(self.today).year
if field == "today.yy":
return DateTimeFormatter(self.today).yy
if field == "today.mm":
return DateTimeFormatter(self.today).mm
if field == "today.month":
return DateTimeFormatter(self.today).month
if field == "today.mon":
return DateTimeFormatter(self.today).mon
if field == "today.dd":
return DateTimeFormatter(self.today).dd
if field == "today.dow":
return DateTimeFormatter(self.today).dow
if field == "today.doy":
return DateTimeFormatter(self.today).doy
if field == "today.hour":
return DateTimeFormatter(self.today).hour
if field == "today.min":
return DateTimeFormatter(self.today).min
if field == "today.sec":
return DateTimeFormatter(self.today).sec
if field == "today.strftime":
if default:
try:
return self.today.strftime(default)
except:
raise ValueError(f"Invalid strftime template: '{default}'")
else:
return None
if field == "place.name":
return self.photo.place.name if self.photo.place else None return self.photo.place.name if self.photo.place else None
if field =="place.country_code": if field == "place.country_code":
return self.photo.place.country_code if self.photo.place else None return self.photo.place.country_code if self.photo.place else None
if field =="place.name.country": if field == "place.name.country":
return ( return (
self.photo.place.names.country[0] self.photo.place.names.country[0]
if self.photo.place and self.photo.place.names.country if self.photo.place and self.photo.place.names.country
else None else None
) )
if field =="place.name.state_province": if field == "place.name.state_province":
return ( return (
self.photo.place.names.state_province[0] self.photo.place.names.state_province[0]
if self.photo.place and self.photo.place.names.state_province if self.photo.place and self.photo.place.names.state_province
else None else None
) )
if field =="place.name.city": if field == "place.name.city":
return ( return (
self.photo.place.names.city[0] self.photo.place.names.city[0]
if self.photo.place and self.photo.place.names.city if self.photo.place and self.photo.place.names.city
else None else None
) )
if field =="place.name.area_of_interest": if field == "place.name.area_of_interest":
return ( return (
self.photo.place.names.area_of_interest[0] self.photo.place.names.area_of_interest[0]
if self.photo.place and self.photo.place.names.area_of_interest if self.photo.place and self.photo.place.names.area_of_interest
else None else None
) )
if field =="place.address": if field == "place.address":
return ( return (
self.photo.place.address_str self.photo.place.address_str
if self.photo.place and self.photo.place.address_str if self.photo.place and self.photo.place.address_str
else None else None
) )
if field =="place.address.street": if field == "place.address.street":
return ( return (
self.photo.place.address.street self.photo.place.address.street
if self.photo.place and self.photo.place.address.street if self.photo.place and self.photo.place.address.street
else None else None
) )
if field =="place.address.city": if field == "place.address.city":
return ( return (
self.photo.place.address.city self.photo.place.address.city
if self.photo.place and self.photo.place.address.city if self.photo.place and self.photo.place.address.city
else None else None
) )
if field =="place.address.state_province": if field == "place.address.state_province":
return ( return (
self.photo.place.address.state_province self.photo.place.address.state_province
if self.photo.place and self.photo.place.address.state_province if self.photo.place and self.photo.place.address.state_province
else None else None
) )
if field =="place.address.postal_code": if field == "place.address.postal_code":
return ( return (
self.photo.place.address.postal_code self.photo.place.address.postal_code
if self.photo.place and self.photo.place.address.postal_code if self.photo.place and self.photo.place.address.postal_code
else None else None
) )
if field =="place.address.country": if field == "place.address.country":
return ( return (
self.photo.place.address.country self.photo.place.address.country
if self.photo.place and self.photo.place.address.country if self.photo.place and self.photo.place.address.country
else None else None
) )
if field =="place.address.country_code": if field == "place.address.country_code":
return ( return (
self.photo.place.address.iso_country_code self.photo.place.address.iso_country_code
if self.photo.place and self.photo.place.address.iso_country_code if self.photo.place and self.photo.place.address.iso_country_code

View File

@@ -87,19 +87,19 @@ class PLRevGeoLocationInfo:
self.postalAddress = postalAddress self.postalAddress = postalAddress
def __eq__(self, other): def __eq__(self, other):
for field in [ return all(
"addressString", getattr(self, field) == getattr(other, field)
"countryCode", for field in [
"isHome", "addressString",
"compoundNames", "countryCode",
"compoundSecondaryNames", "isHome",
"version", "compoundNames",
"geoServiceProvider", "compoundSecondaryNames",
"postalAddress", "version",
]: "geoServiceProvider",
if getattr(self, field) != getattr(other, field): "postalAddress",
return False ]
return True )
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
@@ -151,21 +151,17 @@ class PLRevGeoMapItem:
self.finalPlaceInfos = finalPlaceInfos self.finalPlaceInfos = finalPlaceInfos
def __eq__(self, other): def __eq__(self, other):
for field in ["sortedPlaceInfos", "finalPlaceInfos"]: return all(
if getattr(self, field) != getattr(other, field): getattr(self, field) == getattr(other, field)
return False for field in ["sortedPlaceInfos", "finalPlaceInfos"]
return True )
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __str__(self): def __str__(self):
sortedPlaceInfos = [] sortedPlaceInfos = [str(place) for place in self.sortedPlaceInfos]
finalPlaceInfos = [] finalPlaceInfos = [str(place) for place in self.finalPlaceInfos]
for place in self.sortedPlaceInfos:
sortedPlaceInfos.append(str(place))
for place in self.finalPlaceInfos:
finalPlaceInfos.append(str(place))
return ( return (
f"finalPlaceInfos: {finalPlaceInfos}, sortedPlaceInfos: {sortedPlaceInfos}" f"finalPlaceInfos: {finalPlaceInfos}, sortedPlaceInfos: {sortedPlaceInfos}"
) )
@@ -192,10 +188,10 @@ class PLRevGeoMapItemAdditionalPlaceInfo:
self.dominantOrderType = dominantOrderType self.dominantOrderType = dominantOrderType
def __eq__(self, other): def __eq__(self, other):
for field in ["area", "name", "placeType", "dominantOrderType"]: return all(
if getattr(self, field) != getattr(other, field): getattr(self, field) == getattr(other, field)
return False for field in ["area", "name", "placeType", "dominantOrderType"]
return True )
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
@@ -245,19 +241,19 @@ class CNPostalAddress:
self._subLocality = _subLocality self._subLocality = _subLocality
def __eq__(self, other): def __eq__(self, other):
for field in [ return all(
"_ISOCountryCode", getattr(self, field) == getattr(other, field)
"_city", for field in [
"_country", "_ISOCountryCode",
"_postalCode", "_city",
"_state", "_country",
"_street", "_postalCode",
"_subAdministrativeArea", "_state",
"_subLocality", "_street",
]: "_subAdministrativeArea",
if getattr(self, field) != getattr(other, field): "_subLocality",
return False ]
return True )
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
@@ -490,16 +486,14 @@ class PlaceInfo4(PlaceInfo):
"names": self.names, "names": self.names,
"country_code": self.country_code, "country_code": self.country_code,
} }
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")" return "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
return strval
def as_dict(self): def as_dict(self):
info = { return {
"name": self.name, "name": self.name,
"names": self.names._asdict(), "names": self.names._asdict(),
"country_code": self.country_code, "country_code": self.country_code,
} }
return info
class PlaceInfo5(PlaceInfo): class PlaceInfo5(PlaceInfo):
@@ -509,7 +503,6 @@ class PlaceInfo5(PlaceInfo):
""" revgeoloc_bplist: a binary plist blob containing """ revgeoloc_bplist: a binary plist blob containing
a serialized PLRevGeoLocationInfo object """ a serialized PLRevGeoLocationInfo object """
self._bplist = revgeoloc_bplist self._bplist = revgeoloc_bplist
# todo: check for None?
self._plrevgeoloc = archiver.unarchive(revgeoloc_bplist) self._plrevgeoloc = archiver.unarchive(revgeoloc_bplist)
self._process_place_info() self._process_place_info()
@@ -541,17 +534,23 @@ class PlaceInfo5(PlaceInfo):
@property @property
def address(self): def address(self):
addr = self._plrevgeoloc.postalAddress addr = self._plrevgeoloc.postalAddress
address = PostalAddress( if addr is not None:
street=addr._street, postal_address = PostalAddress(
sub_locality=addr._subLocality, street=addr._street,
city=addr._city, sub_locality=addr._subLocality,
sub_administrative_area=addr._subAdministrativeArea, city=addr._city,
state_province=addr._state, sub_administrative_area=addr._subAdministrativeArea,
postal_code=addr._postalCode, state_province=addr._state,
country=addr._country, postal_code=addr._postalCode,
iso_country_code=addr._ISOCountryCode, country=addr._country,
) iso_country_code=addr._ISOCountryCode,
return address )
else:
postal_address = PostalAddress(
None, None, None, None, None, None, None, None
)
return postal_address
def _process_place_info(self): def _process_place_info(self):
""" Process sortedPlaceInfos to set self._name and self._names """ """ Process sortedPlaceInfos to set self._name and self._names """
@@ -630,16 +629,14 @@ class PlaceInfo5(PlaceInfo):
"address_str": self.address_str, "address_str": self.address_str,
"address": str(self.address), "address": str(self.address),
} }
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")" return "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
return strval
def as_dict(self): def as_dict(self):
info = { return {
"name": self.name, "name": self.name,
"names": self.names._asdict(), "names": self.names._asdict(),
"country_code": self.country_code, "country_code": self.country_code,
"ishome": self.ishome, "ishome": self.ishome,
"address_str": self.address_str, "address_str": self.address_str,
"address": self.address._asdict(), "address": self.address._asdict() if self.address is not None else None,
} }
return info

View File

@@ -71,29 +71,42 @@
% endif % endif
</%def> </%def>
<%def name="gps_info(latitude, longitude)">
% if latitude is not None and longitude is not None:
<exif:GPSLongitudeRef>${"E" if longitude >= 0 else "W"}</exif:GPSLongitudeRef>
<exif:GPSLongitude>${abs(longitude)}</exif:GPSLongitude>
<exif:GPSLatitude>${abs(latitude)}</exif:GPSLatitude>
<exif:GPSLatitudeRef>${"N" if latitude >= 0 else "S"}</exif:GPSLatitudeRef>
% endif
</%def>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.4.0"> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.4.0">
<!-- mirrors Photos 5 "Export IPTC as XMP" option --> <!-- mirrors Photos 5 "Export IPTC as XMP" option -->
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" <rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"> xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
${dc_description(photo.description)} ${dc_description(description)}
${dc_title(photo.title)} ${dc_title(photo.title)}
${dc_subject(subjects)} ${dc_subject(subjects)}
${dc_datecreated(photo.date)} ${dc_datecreated(photo.date)}
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
${iptc_personinimage(persons)} ${iptc_personinimage(persons)}
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
${dk_tagslist(keywords)} ${dk_tagslist(keywords)}
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
${adobe_createdate(photo.date)} ${adobe_createdate(photo.date)}
${adobe_modifydate(photo.date)} ${adobe_modifydate(photo.date)}
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
${gps_info(*photo.location)}
</rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta> </x:xmpmeta>

View File

@@ -149,7 +149,7 @@ def dd_to_dms_str(lat, lon):
def get_system_library_path(): def get_system_library_path():
""" return the path to the system Photos library as string """ """ return the path to the system Photos library as string """
""" only works on MacOS 10.15+ """ """ only works on MacOS 10.15 """
""" on earlier versions, returns None """ """ on earlier versions, returns None """
_, major, _ = _get_os_version() _, major, _ = _get_os_version()
if int(major) < 15: if int(major) < 15:
@@ -166,16 +166,10 @@ def get_system_library_path():
with open(plist_file, "rb") as fp: with open(plist_file, "rb") as fp:
pl = plistload(fp) pl = plistload(fp)
else: else:
logging.warning(f"could not find plist file: {str(plist_file)}") logging.debug(f"could not find plist file: {str(plist_file)}")
return None return None
photospath = pl["SystemLibraryPath"] return pl.get("SystemLibraryPath")
if photospath is not None:
return photospath
else:
logging.warning("Could not get path to Photos database")
return None
def get_last_library_path(): def get_last_library_path():
@@ -194,7 +188,7 @@ def get_last_library_path():
# get the IPXDefaultLibraryURLBookmark from com.apple.Photos.plist # get the IPXDefaultLibraryURLBookmark from com.apple.Photos.plist
# this is a serialized CFData object # this is a serialized CFData object
photosurlref = pl["IPXDefaultLibraryURLBookmark"] photosurlref = pl.get("IPXDefaultLibraryURLBookmark")
if photosurlref is not None: if photosurlref is not None:
# use CFURLCreateByResolvingBookmarkData to de-serialize bookmark data into a CFURLRef # use CFURLCreateByResolvingBookmarkData to de-serialize bookmark data into a CFURLRef
@@ -261,10 +255,9 @@ def get_preferred_uti_extension(uti):
# reference: https://developer.apple.com/documentation/coreservices/1442744-uttypecopypreferredtagwithclass?language=objc # reference: https://developer.apple.com/documentation/coreservices/1442744-uttypecopypreferredtagwithclass?language=objc
ext = CoreServices.UTTypeCopyPreferredTagWithClass( return CoreServices.UTTypeCopyPreferredTagWithClass(
uti, CoreServices.kUTTagClassFilenameExtension uti, CoreServices.kUTTagClassFilenameExtension
) )
return ext
def findfiles(pattern, path_): def findfiles(pattern, path_):

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@@ -5,6 +5,6 @@
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key> <key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
<date>2020-04-25T23:54:43Z</date> <date>2020-04-25T23:54:43Z</date>
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key> <key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
<date>2020-04-26T06:26:10Z</date> <date>2020-06-27T16:03:48Z</date>
</dict> </dict>
</plist> </plist>

View File

@@ -11,6 +11,6 @@
<key>PLLastRevGeoForcedProviderOutOfDateCheckVersionKey</key> <key>PLLastRevGeoForcedProviderOutOfDateCheckVersionKey</key>
<integer>1</integer> <integer>1</integer>
<key>PLLastRevGeoVerFileFetchDateKey</key> <key>PLLastRevGeoVerFileFetchDateKey</key>
<date>2020-04-25T23:54:29Z</date> <date>2020-06-27T16:03:43Z</date>
</dict> </dict>
</plist> </plist>

View File

@@ -3,7 +3,7 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>LastHistoryRowId</key> <key>LastHistoryRowId</key>
<integer>606</integer> <integer>651</integer>
<key>LibraryBuildTag</key> <key>LibraryBuildTag</key>
<string>D8C4AAA1-3AB6-4A65-BEBD-99CC3E5D433E</string> <string>D8C4AAA1-3AB6-4A65-BEBD-99CC3E5D433E</string>
<key>LibrarySchemaVersion</key> <key>LibrarySchemaVersion</key>

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

View File

@@ -24,7 +24,7 @@
<key>SnapshotCompletedDate</key> <key>SnapshotCompletedDate</key>
<date>2019-07-27T13:16:43Z</date> <date>2019-07-27T13:16:43Z</date>
<key>SnapshotLastValidated</key> <key>SnapshotLastValidated</key>
<date>2020-04-25T23:56:35Z</date> <date>2020-06-27T16:03:33Z</date>
<key>SnapshotTables</key> <key>SnapshotTables</key>
<dict/> <dict/>
</dict> </dict>

View File

@@ -7,7 +7,7 @@
<key>hostuuid</key> <key>hostuuid</key>
<string>9575E48B-8D5F-5654-ABAC-4431B1167324</string> <string>9575E48B-8D5F-5654-ABAC-4431B1167324</string>
<key>pid</key> <key>pid</key>
<integer>4021</integer> <integer>763</integer>
<key>processname</key> <key>processname</key>
<string>photolibraryd</string> <string>photolibraryd</string>
<key>uid</key> <key>uid</key>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@@ -10,6 +10,7 @@
<string>88A5F8B8-5B9A-43C7-BB85-3952B81580EB/L0/020</string> <string>88A5F8B8-5B9A-43C7-BB85-3952B81580EB/L0/020</string>
<string>29EF7A97-7E76-4D5F-A5E0-CC0A93E8524C/L0/020</string> <string>29EF7A97-7E76-4D5F-A5E0-CC0A93E8524C/L0/020</string>
<string>2C2AF115-BD1D-4434-A747-D1C8BD8E2045/L0/020</string> <string>2C2AF115-BD1D-4434-A747-D1C8BD8E2045/L0/020</string>
<string>CB051A4C-2CB7-4B90-B59B-08CC4D0C2823/L0/020</string>
</array> </array>
<key>Photos</key> <key>Photos</key>
<dict> <dict>

View File

@@ -3,24 +3,24 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>BackgroundHighlightCollection</key> <key>BackgroundHighlightCollection</key>
<date>2020-05-30T01:45:51Z</date> <date>2020-06-24T04:02:13Z</date>
<key>BackgroundHighlightEnrichment</key> <key>BackgroundHighlightEnrichment</key>
<date>2020-05-30T01:45:51Z</date> <date>2020-06-24T04:02:12Z</date>
<key>BackgroundJobAssetRevGeocode</key> <key>BackgroundJobAssetRevGeocode</key>
<date>2020-05-30T04:01:24Z</date> <date>2020-06-24T04:02:13Z</date>
<key>BackgroundJobSearch</key> <key>BackgroundJobSearch</key>
<date>2020-05-30T01:45:51Z</date> <date>2020-06-24T04:02:13Z</date>
<key>BackgroundPeopleSuggestion</key> <key>BackgroundPeopleSuggestion</key>
<date>2020-05-30T01:45:51Z</date> <date>2020-06-24T04:02:12Z</date>
<key>BackgroundUserBehaviorProcessor</key> <key>BackgroundUserBehaviorProcessor</key>
<date>2020-05-29T04:31:38Z</date> <date>2020-06-24T04:02:13Z</date>
<key>PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey</key> <key>PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey</key>
<date>2020-05-30T02:16:06Z</date> <date>2020-05-30T02:16:06Z</date>
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key> <key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
<date>2020-05-29T04:31:37Z</date> <date>2020-05-29T04:31:37Z</date>
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key> <key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
<date>2020-05-30T04:01:24Z</date> <date>2020-06-24T04:02:13Z</date>
<key>SiriPortraitDonation</key> <key>SiriPortraitDonation</key>
<date>2020-05-29T04:31:38Z</date> <date>2020-06-24T04:02:13Z</date>
</dict> </dict>
</plist> </plist>

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

View File

@@ -16,7 +16,7 @@ KEYWORDS = [
"United Kingdom", "United Kingdom",
] ]
PERSONS = ["Katie", "Suzy", "Maria"] PERSONS = ["Katie", "Suzy", "Maria"]
ALBUMS = ["Pumpkin Farm", "Last Import", "AlbumInFolder"] ALBUMS = ["Pumpkin Farm", "AlbumInFolder"]
KEYWORDS_DICT = { KEYWORDS_DICT = {
"Kids": 4, "Kids": 4,
"wedding": 2, "wedding": 2,
@@ -29,7 +29,7 @@ KEYWORDS_DICT = {
"United Kingdom": 1, "United Kingdom": 1,
} }
PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 1} PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 1}
ALBUM_DICT = {"Pumpkin Farm": 3, "Last Import": 1, "AlbumInFolder": 1} ALBUM_DICT = {"Pumpkin Farm": 3, "AlbumInFolder": 1}
def test_init(): def test_init():
@@ -124,7 +124,7 @@ def test_attributes():
) )
assert p.description == "Girl holding pumpkin" assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!" assert p.title == "I found one!"
assert p.albums == ["Pumpkin Farm", "AlbumInFolder"] assert sorted(p.albums) == ["AlbumInFolder", "Pumpkin Farm"]
assert p.persons == ["Katie"] assert p.persons == ["Katie"]
assert p.path.endswith( assert p.path.endswith(
"/tests/Test-10.12.6.photoslibrary/Masters/2019/08/24/20190824-030824/Pumkins2.jpg" "/tests/Test-10.12.6.photoslibrary/Masters/2019/08/24/20190824-030824/Pumkins2.jpg"

View File

@@ -229,6 +229,7 @@ def test_albums_photos():
def test_photoinfo_albums(): def test_photoinfo_albums():
""" Test PhotoInfo.albums """
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
@@ -238,7 +239,20 @@ def test_photoinfo_albums():
assert "Pumpkin Farm" in albums assert "Pumpkin Farm" in albums
def test_photoinfo_albums_2():
""" Test that PhotoInfo.albums returns only number albums expected """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["two_albums"]])
albums = photos[0].albums
assert len(albums) == 2
def test_photoinfo_album_info(): def test_photoinfo_album_info():
""" test PhotoInfo.album_info """
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
@@ -249,4 +263,4 @@ def test_photoinfo_album_info():
assert album_info[0].title in ["Pumpkin Farm", "Test Album"] assert album_info[0].title in ["Pumpkin Farm", "Test Album"]
assert album_info[1].title in ["Pumpkin Farm", "Test Album"] assert album_info[1].title in ["Pumpkin Farm", "Test Album"]
assert photos[0] in album_info[0].photos assert photos[0].uuid in [photo.uuid for photo in album_info[0].photos]

View File

@@ -244,4 +244,4 @@ def test_photoinfo_album_info():
assert album_info[0].title in ["Pumpkin Farm", "Test Album"] assert album_info[0].title in ["Pumpkin Farm", "Test Album"]
assert album_info[1].title in ["Pumpkin Farm", "Test Album"] assert album_info[1].title in ["Pumpkin Farm", "Test Album"]
assert photos[0] in album_info[0].photos assert photos[0].uuid in [photo.uuid for photo in album_info[0].photos]

View File

@@ -106,6 +106,7 @@ def test_init4():
except: except:
pass pass
def test_init5(mocker): def test_init5(mocker):
# test failed get_last_library_path # test failed get_last_library_path
import osxphotos import osxphotos
@@ -116,7 +117,6 @@ def test_init5(mocker):
# get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb
# because of the layout of photosdb/ need to patch it this way...don't really understand why, but it works # because of the layout of photosdb/ need to patch it this way...don't really understand why, but it works
mocker.patch("osxphotos.photosdb.photosdb.get_last_library_path", new=bad_library) mocker.patch("osxphotos.photosdb.photosdb.get_last_library_path", new=bad_library)
with pytest.raises(Exception): with pytest.raises(Exception):
assert osxphotos.PhotosDB() assert osxphotos.PhotosDB()
@@ -207,7 +207,7 @@ def test_attributes():
) )
assert p.description == "Girl holding pumpkin" assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!" assert p.title == "I found one!"
assert p.albums == ["Pumpkin Farm", "Test Album", "Multi Keyword"] assert sorted(p.albums) == ["Multi Keyword", "Pumpkin Farm", "Test Album"]
assert p.persons == ["Katie"] assert p.persons == ["Katie"]
assert p.path.endswith( assert p.path.endswith(
"tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg" "tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"

View File

@@ -215,7 +215,7 @@ def test_attributes():
) )
assert p.description == "Girl holding pumpkin" assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!" assert p.title == "I found one!"
assert p.albums == ["Pumpkin Farm", "Test Album"] assert sorted(p.albums) == ["Pumpkin Farm", "Test Album"]
assert p.persons == ["Katie"] assert p.persons == ["Katie"]
assert p.path.endswith( assert p.path.endswith(
"tests/Test-10.15.4.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg" "tests/Test-10.15.4.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"

View File

@@ -7,6 +7,10 @@ PHOTOS_DB = "tests/Test-10.15.5.photoslibrary/database/photos.db"
PHOTOS_DB_PATH = "/Test-10.15.5.photoslibrary/database/photos.db" PHOTOS_DB_PATH = "/Test-10.15.5.photoslibrary/database/photos.db"
PHOTOS_LIBRARY_PATH = "/Test-10.15.5.photoslibrary" PHOTOS_LIBRARY_PATH = "/Test-10.15.5.photoslibrary"
PHOTOS_DB_LEN = 14
PHOTOS_NOT_IN_TRASH_LEN = 13
PHOTOS_IN_TRASH_LEN = 1
KEYWORDS = [ KEYWORDS = [
"Kids", "Kids",
"wedding", "wedding",
@@ -22,10 +26,12 @@ KEYWORDS = [
PERSONS = ["Katie", "Suzy", "Maria", _UNKNOWN_PERSON] PERSONS = ["Katie", "Suzy", "Maria", _UNKNOWN_PERSON]
ALBUMS = [ ALBUMS = [
"Pumpkin Farm", "Pumpkin Farm",
"Test Album", "Test Album", # there are 2 albums named "Test Album" for testing duplicate album names
"AlbumInFolder", "AlbumInFolder",
"Raw" "Raw",
] # Note: there are 2 albums named "Test Album" for testing duplicate album names "I have a deleted twin", # there's an empty album with same name that has been deleted
"EmptyAlbum",
]
KEYWORDS_DICT = { KEYWORDS_DICT = {
"Kids": 4, "Kids": 4,
"wedding": 2, "wedding": 2,
@@ -43,6 +49,8 @@ ALBUM_DICT = {
"Test Album": 2, "Test Album": 2,
"AlbumInFolder": 2, "AlbumInFolder": 2,
"Raw": 4, "Raw": 4,
"I have a deleted twin": 1,
"EmptyAlbum": 0,
} # Note: there are 2 albums named "Test Album" for testing duplicate album names } # Note: there are 2 albums named "Test Album" for testing duplicate album names
UUID_DICT = { UUID_DICT = {
@@ -58,8 +66,19 @@ UUID_DICT = {
"external_edit": "DC99FBDD-7A52-4100-A5BB-344131646C30", "external_edit": "DC99FBDD-7A52-4100-A5BB-344131646C30",
"no_external_edit": "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51", "no_external_edit": "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51",
"export": "D79B8D77-BFFC-460B-9312-034F2877D35B", # "Pumkins2.jpg" "export": "D79B8D77-BFFC-460B-9312-034F2877D35B", # "Pumkins2.jpg"
"export_tif": "8846E3E6-8AC8-4857-8448-E3D025784410",
"in_album": "D79B8D77-BFFC-460B-9312-034F2877D35B", # "Pumkins2.jpg"
"date_invalid": "8846E3E6-8AC8-4857-8448-E3D025784410",
"intrash": "71E3E212-00EB-430D-8A63-5E294B268554",
"not_intrash": "DC99FBDD-7A52-4100-A5BB-344131646C30",
} }
UUID_PUMPKIN_FARM = [
"F12384F6-CD17-4151-ACBA-AE0E3688539E",
"D79B8D77-BFFC-460B-9312-034F2877D35B",
"1EB2B765-0765-43BA-A90C-0D0580E6172C",
]
def test_init1(): def test_init1():
# test named argument # test named argument
@@ -109,14 +128,14 @@ def test_init4():
def test_init5(mocker): def test_init5(mocker):
# test failed get_last_library_path # test failed get_last_library_path
import osxphotos import osxphotos
def bad_library(): def bad_library():
return None return None
# get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb # get_last_library actually in utils but need to patch it in photosdb because it's imported into photosdb
# because of the layout of photosdb/ need to patch it this way...don't really understand why, but it works # because of the layout of photosdb/ need to patch it this way...don't really understand why, but it works
mocker.patch("osxphotos.photosdb.photosdb.get_last_library_path", new=bad_library) mocker.patch("osxphotos.photosdb.photosdb.get_last_library_path", new=bad_library)
with pytest.raises(Exception): with pytest.raises(Exception):
assert osxphotos.PhotosDB() assert osxphotos.PhotosDB()
@@ -126,7 +145,7 @@ def test_db_len():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
# assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS
assert len(photosdb) == 12 assert len(photosdb) == PHOTOS_DB_LEN
def test_db_version(): def test_db_version():
@@ -214,7 +233,7 @@ def test_attributes():
) )
assert p.description == "Girl holding pumpkin" assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!" assert p.title == "I found one!"
assert p.albums == ["Pumpkin Farm", "Test Album"] assert sorted(p.albums) == ["Pumpkin Farm", "Test Album"]
assert p.persons == ["Katie"] assert p.persons == ["Katie"]
assert p.path.endswith( assert p.path.endswith(
"tests/Test-10.15.5.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg" "tests/Test-10.15.5.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
@@ -222,6 +241,46 @@ def test_attributes():
assert p.ismissing == False assert p.ismissing == False
def test_attributes_2():
""" Test attributes including height, width, etc """
import datetime
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]])
assert len(photos) == 1
p = photos[0]
assert p.keywords == ["wedding"]
assert p.original_filename == "wedding.jpg"
assert p.filename == "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51.jpeg"
assert p.date == datetime.datetime(
2019,
4,
15,
14,
40,
24,
86000,
datetime.timezone(datetime.timedelta(seconds=-14400)),
)
assert p.description == "Bride Wedding day"
assert p.title is None
assert sorted(p.albums) == ["AlbumInFolder", "I have a deleted twin"]
assert p.persons == ["Maria"]
assert p.path.endswith(
"tests/Test-10.15.5.photoslibrary/originals/E/E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51.jpeg"
)
assert not p.ismissing
assert p.hasadjustments
assert p.height == 1325
assert p.width == 1526
assert p.original_height == 1367
assert p.original_width == 2048
assert p.orientation == 1
assert p.original_orientation == 1
assert p.original_filesize == 460483
def test_missing(): def test_missing():
import osxphotos import osxphotos
@@ -229,7 +288,7 @@ def test_missing():
photos = photosdb.photos(uuid=[UUID_DICT["missing"]]) photos = photosdb.photos(uuid=[UUID_DICT["missing"]])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
assert p.path == None assert p.path is None
assert p.ismissing == True assert p.ismissing == True
@@ -378,7 +437,63 @@ def test_count():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos() photos = photosdb.photos()
assert len(photos) == 12 assert len(photos) == PHOTOS_NOT_IN_TRASH_LEN
def test_photos_intrash_1():
""" test PhotosDB.photos(intrash=True) """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(intrash=True)
assert len(photos) == PHOTOS_IN_TRASH_LEN
def test_photos_intrash_2():
""" test PhotosDB.photos(intrash=True) """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(intrash=True)
for p in photos:
assert p.intrash
def test_photos_intrash_2():
""" test PhotosDB.photos(intrash=False) """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(intrash=False)
for p in photos:
assert not p.intrash
def test_photoinfo_intrash_1():
""" Test PhotoInfo.intrash """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
p = photosdb.photos(uuid=[UUID_DICT["intrash"]], intrash=True)[0]
assert p.intrash
def test_photoinfo_intrash_2():
""" Test PhotoInfo.intrash and intrash=default"""
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
p = photosdb.photos(uuid=[UUID_DICT["intrash"]])
assert not p
def test_photoinfo_not_intrash():
""" Test PhotoInfo.intrash """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
p = photosdb.photos(uuid=[UUID_DICT["not_intrash"]])[0]
assert not p.intrash
def test_keyword_2(): def test_keyword_2():
@@ -402,6 +517,16 @@ def test_keyword_not_in_album():
assert photos3[0].uuid == "A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C" assert photos3[0].uuid == "A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C"
def test_album_folder_name():
"""Test query with album name same as a folder name """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(albums=["Pumpkin Farm"])
assert sorted(p.uuid for p in photos) == sorted(UUID_PUMPKIN_FARM)
def test_get_db_path(): def test_get_db_path():
import osxphotos import osxphotos
@@ -418,6 +543,26 @@ def test_get_library_path():
assert lib_path.endswith(PHOTOS_LIBRARY_PATH) assert lib_path.endswith(PHOTOS_LIBRARY_PATH)
def test_get_db_connection():
""" Test PhotosDB.get_db_connection """
import osxphotos
import sqlite3
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
conn, cursor = photosdb.get_db_connection()
assert isinstance(conn, sqlite3.Connection)
assert isinstance(cursor, sqlite3.Cursor)
results = conn.execute(
"SELECT ZUUID FROM ZGENERICASSET WHERE ZFAVORITE = 1;"
).fetchall()
assert len(results) == 1
assert results[0][0] == "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51" # uuid
conn.close()
def test_export_1(): def test_export_1():
# test basic export # test basic export
# get an unedited image and export it using default filename # get an unedited image and export it using default filename
@@ -730,12 +875,55 @@ def test_export_13():
assert e.type == type(FileNotFoundError()) assert e.type == type(FileNotFoundError())
def test_eq(): def test_export_14(caplog):
# test export with user provided filename with different (but valid) extension than source
import os
import os.path
import tempfile
import time
import osxphotos import osxphotos
tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
dest = tempdir.name
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos1 = photosdb.photos(uuid=[UUID_DICT["export"]]) photos = photosdb.photos(uuid=[UUID_DICT["export_tif"]])
photos2 = photosdb.photos(uuid=[UUID_DICT["export"]])
timestamp = time.time()
filename = f"osxphotos-export-2-test-{timestamp}.tif"
expected_dest = os.path.join(dest, filename)
got_dest = photos[0].export(dest, filename)[0]
assert got_dest == expected_dest
assert os.path.isfile(got_dest)
assert "Invalid destination suffix" not in caplog.text
def test_eq():
""" Test equality of two PhotoInfo objects """
import osxphotos
photosdb1 = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photosdb2 = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos1 = photosdb1.photos(uuid=[UUID_DICT["export"]])
photos2 = photosdb2.photos(uuid=[UUID_DICT["export"]])
assert photos1[0] == photos2[0]
def test_eq_2():
""" Test equality of two PhotoInfo objects when one has memoized property """
import osxphotos
photosdb1 = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photosdb2 = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos1 = photosdb1.photos(uuid=[UUID_DICT["in_album"]])
photos2 = photosdb2.photos(uuid=[UUID_DICT["in_album"]])
# memoize a value
albums = photos1[0].albums
assert albums
assert photos1[0] == photos2[0] assert photos1[0] == photos2[0]
@@ -781,12 +969,39 @@ def test_from_to_date():
photosdb = osxphotos.PhotosDB(PHOTOS_DB) photosdb = osxphotos.PhotosDB(PHOTOS_DB)
photos = photosdb.photos(from_date=dt.datetime(2018, 10, 28)) photos = photosdb.photos(from_date=dt.datetime(2018, 10, 28))
assert len(photos) ==6 assert len(photos) == 6
photos = photosdb.photos(to_date=dt.datetime(2018, 10, 28)) photos = photosdb.photos(to_date=dt.datetime(2018, 10, 28))
assert len(photos) == 6 assert len(photos) == 7
photos = photosdb.photos( photos = photosdb.photos(
from_date=dt.datetime(2018, 9, 28), to_date=dt.datetime(2018, 9, 29) from_date=dt.datetime(2018, 9, 28), to_date=dt.datetime(2018, 9, 29)
) )
assert len(photos) == 4 assert len(photos) == 4
def test_date_invalid():
""" Test date is invalid """
from datetime import datetime, timedelta, timezone
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["date_invalid"]])
assert len(photos) == 1
p = photos[0]
delta = timedelta(seconds=p.tzoffset)
tz = timezone(delta)
assert p.date == datetime(1970, 1, 1).astimezone(tz=tz)
def test_date_modified_invalid():
""" Test date modified is invalid """
from datetime import datetime, timedelta, timezone
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["date_invalid"]])
assert len(photos) == 1
p = photos[0]
assert p.date_modified is None

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,16 @@
""" test datetime_formatter.DateTimeFormatter """ """ test datetime_formatter.DateTimeFormatter """
import pytest import pytest
def test_datetime_formatter():
def test_datetime_formatter_1():
"""Test DateTimeFormatter """
import datetime import datetime
import locale import locale
from osxphotos.datetime_formatter import DateTimeFormatter from osxphotos.datetime_formatter import DateTimeFormatter
locale.setlocale(locale.LC_ALL, "en_US") locale.setlocale(locale.LC_ALL, "en_US")
dt = datetime.datetime(2020,5,23) dt = datetime.datetime(2020, 5, 23, 12, 42, 33)
dtf = DateTimeFormatter(dt) dtf = DateTimeFormatter(dt)
assert dtf.date == "2020-05-23" assert dtf.date == "2020-05-23"
@@ -19,3 +21,54 @@ def test_datetime_formatter():
assert dtf.mm == "05" assert dtf.mm == "05"
assert dtf.dd == "23" assert dtf.dd == "23"
assert dtf.doy == "144" assert dtf.doy == "144"
assert dtf.hour == "12"
assert dtf.min == "42"
assert dtf.sec == "33"
def test_datetime_formatter_2():
"""Test DateTimeFormatter with hour > 12 """
import datetime
import locale
from osxphotos.datetime_formatter import DateTimeFormatter
locale.setlocale(locale.LC_ALL, "en_US")
dt = datetime.datetime(2020, 5, 23, 14, 42, 33)
dtf = DateTimeFormatter(dt)
assert dtf.date == "2020-05-23"
assert dtf.year == "2020"
assert dtf.yy == "20"
assert dtf.month == "May"
assert dtf.mon == "May"
assert dtf.mm == "05"
assert dtf.dd == "23"
assert dtf.doy == "144"
assert dtf.hour == "14"
assert dtf.min == "42"
assert dtf.sec == "33"
def test_datetime_formatter_3():
"""Test DateTimeFormatter zero-padding """
import datetime
import locale
from osxphotos.datetime_formatter import DateTimeFormatter
locale.setlocale(locale.LC_ALL, "en_US")
dt = datetime.datetime(2020, 5, 2, 9, 3, 6)
dtf = DateTimeFormatter(dt)
assert dtf.date == "2020-05-02"
assert dtf.year == "2020"
assert dtf.yy == "20"
assert dtf.month == "May"
assert dtf.mon == "May"
assert dtf.mm == "05"
assert dtf.dd == "02"
assert dtf.doy == "123"
assert dtf.hour == "09"
assert dtf.min == "03"
assert dtf.sec == "06"

View File

@@ -455,7 +455,6 @@ def test_exiftool_json_sidecar():
"XMP:Subject": ["London 2018", "St. James\'s Park", "England", "United Kingdom", "UK", "London"], "XMP:Subject": ["London 2018", "St. James\'s Park", "England", "United Kingdom", "UK", "London"],
"EXIF:GPSLatitude": "51 deg 30\' 12.86\\" N", "EXIF:GPSLatitude": "51 deg 30\' 12.86\\" N",
"EXIF:GPSLongitude": "0 deg 7\' 54.50\\" W", "EXIF:GPSLongitude": "0 deg 7\' 54.50\\" W",
"Composite:GPSPosition": "51 deg 30\' 12.86\\" N, 0 deg 7\' 54.50\\" W",
"EXIF:GPSLatitudeRef": "North", "EXIF:GPSLongitudeRef": "West", "EXIF:GPSLatitudeRef": "North", "EXIF:GPSLongitudeRef": "West",
"EXIF:DateTimeOriginal": "2018:10:13 09:18:12", "EXIF:DateTimeOriginal": "2018:10:13 09:18:12",
"EXIF:OffsetTimeOriginal": "-04:00", "EXIF:OffsetTimeOriginal": "-04:00",
@@ -586,7 +585,7 @@ def test_xmp_sidecar():
</dc:subject> </dc:subject>
<photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated> <photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
<Iptc4xmpExt:PersonInImage> <Iptc4xmpExt:PersonInImage>
<rdf:Bag> <rdf:Bag>
@@ -595,7 +594,7 @@ def test_xmp_sidecar():
</rdf:Bag> </rdf:Bag>
</Iptc4xmpExt:PersonInImage> </Iptc4xmpExt:PersonInImage>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList> <digiKam:TagsList>
<rdf:Seq> <rdf:Seq>
@@ -603,10 +602,13 @@ def test_xmp_sidecar():
</rdf:Seq> </rdf:Seq>
</digiKam:TagsList> </digiKam:TagsList>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate> <xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate>
<xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate> <xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
</rdf:Description> </rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta>""" </x:xmpmeta>"""
@@ -647,7 +649,7 @@ def test_xmp_sidecar_use_persons_keyword():
</dc:subject> </dc:subject>
<photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated> <photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
<Iptc4xmpExt:PersonInImage> <Iptc4xmpExt:PersonInImage>
<rdf:Bag> <rdf:Bag>
@@ -656,7 +658,7 @@ def test_xmp_sidecar_use_persons_keyword():
</rdf:Bag> </rdf:Bag>
</Iptc4xmpExt:PersonInImage> </Iptc4xmpExt:PersonInImage>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList> <digiKam:TagsList>
<rdf:Seq> <rdf:Seq>
@@ -666,11 +668,14 @@ def test_xmp_sidecar_use_persons_keyword():
</rdf:Seq> </rdf:Seq>
</digiKam:TagsList> </digiKam:TagsList>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate> <xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate>
<xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate> <xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
</rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta>""" </x:xmpmeta>"""
@@ -710,7 +715,7 @@ def test_xmp_sidecar_use_albums_keyword():
</dc:subject> </dc:subject>
<photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated> <photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
<Iptc4xmpExt:PersonInImage> <Iptc4xmpExt:PersonInImage>
<rdf:Bag> <rdf:Bag>
@@ -719,7 +724,7 @@ def test_xmp_sidecar_use_albums_keyword():
</rdf:Bag> </rdf:Bag>
</Iptc4xmpExt:PersonInImage> </Iptc4xmpExt:PersonInImage>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList> <digiKam:TagsList>
<rdf:Seq> <rdf:Seq>
@@ -729,11 +734,14 @@ def test_xmp_sidecar_use_albums_keyword():
</rdf:Seq> </rdf:Seq>
</digiKam:TagsList> </digiKam:TagsList>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate> <xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate>
<xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate> <xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
</rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta>""" </x:xmpmeta>"""
@@ -746,3 +754,75 @@ def test_xmp_sidecar_use_albums_keyword():
sorted(xmp_expected_lines), sorted(xmp_got_lines) sorted(xmp_expected_lines), sorted(xmp_got_lines)
): ):
assert line_expected == line_got assert line_expected == line_got
def test_xmp_sidecar_gps():
""" Test export XMP sidecar with GPS info """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["location"]])
xmp_expected = """<!-- Created with osxphotos https://github.com/RhetTbull/osxphotos -->
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.4.0">
<!-- mirrors Photos 5 "Export IPTC as XMP" option -->
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
<dc:description></dc:description>
<dc:title>St. James's Park</dc:title>
<!-- keywords and persons listed in <dc:subject> as Photos does -->
<dc:subject>
<rdf:Seq>
<rdf:li>UK</rdf:li>
<rdf:li>England</rdf:li>
<rdf:li>London</rdf:li>
<rdf:li>United Kingdom</rdf:li>
<rdf:li>London 2018</rdf:li>
<rdf:li>St. James's Park</rdf:li>
</rdf:Seq>
</dc:subject>
<photoshop:DateCreated>2018-10-13T09:18:12.501000-04:00</photoshop:DateCreated>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList>
<rdf:Seq>
<rdf:li>UK</rdf:li>
<rdf:li>England</rdf:li>
<rdf:li>London</rdf:li>
<rdf:li>United Kingdom</rdf:li>
<rdf:li>London 2018</rdf:li>
<rdf:li>St. James's Park</rdf:li>
</rdf:Seq>
</digiKam:TagsList>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-10-13T09:18:12</xmp:CreateDate>
<xmp:ModifyDate>2018-10-13T09:18:12</xmp:ModifyDate>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
<exif:GPSLongitudeRef>W</exif:GPSLongitudeRef>
<exif:GPSLongitude>0.1318055</exif:GPSLongitude>
<exif:GPSLatitude>51.50357167</exif:GPSLatitude>
<exif:GPSLatitudeRef>N</exif:GPSLatitudeRef>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>"""
xmp_expected_lines = [line.strip() for line in xmp_expected.split("\n")]
xmp_got = photos[0]._xmp_sidecar()
xmp_got_lines = [line.strip() for line in xmp_got.split("\n")]
for line_expected, line_got in zip(
sorted(xmp_expected_lines), sorted(xmp_got_lines)
):
assert line_expected == line_got

View File

@@ -178,7 +178,7 @@ def test_xmp_sidecar_keyword_template():
</dc:subject> </dc:subject>
<photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated> <photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
<Iptc4xmpExt:PersonInImage> <Iptc4xmpExt:PersonInImage>
<rdf:Bag> <rdf:Bag>
@@ -187,7 +187,7 @@ def test_xmp_sidecar_keyword_template():
</rdf:Bag> </rdf:Bag>
</Iptc4xmpExt:PersonInImage> </Iptc4xmpExt:PersonInImage>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList> <digiKam:TagsList>
<rdf:Seq> <rdf:Seq>
@@ -198,11 +198,14 @@ def test_xmp_sidecar_keyword_template():
</rdf:Seq> </rdf:Seq>
</digiKam:TagsList> </digiKam:TagsList>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate> <xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate>
<xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate> <xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
</rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta>""" </x:xmpmeta>"""

View File

@@ -380,7 +380,6 @@ def test_exiftool_json_sidecar():
"XMP:Subject": ["London 2018", "St. James\'s Park", "England", "United Kingdom", "UK", "London"], "XMP:Subject": ["London 2018", "St. James\'s Park", "England", "United Kingdom", "UK", "London"],
"EXIF:GPSLatitude": "51 deg 30\' 12.86\\" N", "EXIF:GPSLatitude": "51 deg 30\' 12.86\\" N",
"EXIF:GPSLongitude": "0 deg 7\' 54.50\\" W", "EXIF:GPSLongitude": "0 deg 7\' 54.50\\" W",
"Composite:GPSPosition": "51 deg 30\' 12.86\\" N, 0 deg 7\' 54.50\\" W",
"EXIF:GPSLatitudeRef": "North", "EXIF:GPSLongitudeRef": "West", "EXIF:GPSLatitudeRef": "North", "EXIF:GPSLongitudeRef": "West",
"EXIF:DateTimeOriginal": "2018:10:13 09:18:12", "EXIF:DateTimeOriginal": "2018:10:13 09:18:12",
"EXIF:OffsetTimeOriginal": "-04:00", "EXIF:OffsetTimeOriginal": "-04:00",
@@ -431,7 +430,7 @@ def test_xmp_sidecar():
</dc:subject> </dc:subject>
<photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated> <photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
<Iptc4xmpExt:PersonInImage> <Iptc4xmpExt:PersonInImage>
<rdf:Bag> <rdf:Bag>
@@ -440,7 +439,7 @@ def test_xmp_sidecar():
</rdf:Bag> </rdf:Bag>
</Iptc4xmpExt:PersonInImage> </Iptc4xmpExt:PersonInImage>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList> <digiKam:TagsList>
<rdf:Seq> <rdf:Seq>
@@ -448,11 +447,14 @@ def test_xmp_sidecar():
</rdf:Seq> </rdf:Seq>
</digiKam:TagsList> </digiKam:TagsList>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate> <xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate>
<xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate> <xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
</rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta>""" </x:xmpmeta>"""
@@ -490,7 +492,7 @@ def test_xmp_sidecar_keyword_template():
</dc:subject> </dc:subject>
<photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated> <photoshop:DateCreated>2018-09-28T15:35:49.063000-04:00</photoshop:DateCreated>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'> xmlns:Iptc4xmpExt='http://iptc.org/std/Iptc4xmpExt/2008-02-29/'>
<Iptc4xmpExt:PersonInImage> <Iptc4xmpExt:PersonInImage>
<rdf:Bag> <rdf:Bag>
@@ -499,7 +501,7 @@ def test_xmp_sidecar_keyword_template():
</rdf:Bag> </rdf:Bag>
</Iptc4xmpExt:PersonInImage> </Iptc4xmpExt:PersonInImage>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:digiKam='http://www.digikam.org/ns/1.0/'> xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList> <digiKam:TagsList>
<rdf:Seq> <rdf:Seq>
@@ -510,11 +512,14 @@ def test_xmp_sidecar_keyword_template():
</rdf:Seq> </rdf:Seq>
</digiKam:TagsList> </digiKam:TagsList>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about='' <rdf:Description rdf:about=""
xmlns:xmp='http://ns.adobe.com/xap/1.0/'> xmlns:xmp='http://ns.adobe.com/xap/1.0/'>
<xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate> <xmp:CreateDate>2018-09-28T15:35:49</xmp:CreateDate>
<xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate> <xmp:ModifyDate>2018-09-28T15:35:49</xmp:ModifyDate>
</rdf:Description> </rdf:Description>
<rdf:Description rdf:about=""
xmlns:exif='http://ns.adobe.com/exif/1.0/'>
</rdf:Description>
</rdf:RDF> </rdf:RDF>
</x:xmpmeta>""" </x:xmpmeta>"""

View File

@@ -41,8 +41,16 @@ ALBUM_DICT = {
UUID_DICT = { UUID_DICT = {
"favorite": "6bxcNnzRQKGnK4uPrCJ9UQ", "favorite": "6bxcNnzRQKGnK4uPrCJ9UQ",
"not_favorite": "8SOE9s0XQVGsuq4ONohTng", "not_favorite": "8SOE9s0XQVGsuq4ONohTng",
"date_invalid": "YZFCPY24TUySvpu7owiqxA",
"intrash": "3tljdX43R8+k6peNHVrJNQ",
"not_intrash": "6bxcNnzRQKGnK4uPrCJ9UQ",
"has_adjustments": "6bxcNnzRQKGnK4uPrCJ9UQ",
} }
PHOTOS_DB_LEN = 8
PHOTOS_NOT_IN_TRASH_LEN = 7
PHOTOS_IN_TRASH_LEN = 1
def test_init(): def test_init():
import osxphotos import osxphotos
@@ -58,12 +66,13 @@ def test_db_version():
assert photosdb.db_version in osxphotos._constants._TESTED_DB_VERSIONS assert photosdb.db_version in osxphotos._constants._TESTED_DB_VERSIONS
assert photosdb.db_version == "4025" assert photosdb.db_version == "4025"
def test_db_len(): def test_db_len():
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
# assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS # assert photosdb.db_version in osxphotos._TESTED_DB_VERSIONS
assert len(photosdb) == 7 assert len(photosdb) == PHOTOS_DB_LEN
def test_os_version(): def test_os_version():
@@ -153,6 +162,44 @@ def test_attributes():
assert p.ismissing == False assert p.ismissing == False
def test_attributes_2():
""" Test attributes including height, width, etc """
import datetime
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]])
assert len(photos) == 1
p = photos[0]
assert p.keywords == ["wedding"]
assert p.original_filename == "wedding.jpg"
assert p.filename == "wedding.jpg"
assert p.date == datetime.datetime(
2019,
4,
15,
14,
40,
24,
86000,
datetime.timezone(datetime.timedelta(seconds=-14400)),
)
assert p.description == "Bride Wedding day"
assert p.title is None
assert sorted(p.albums) == []
assert p.persons == ["Maria"]
assert p.path.endswith("Masters/2019/07/27/20190727-131650/wedding.jpg")
assert not p.ismissing
assert p.hasadjustments
assert p.height == 1325
assert p.width == 1526
assert p.original_height == 1367
assert p.original_width == 2048
assert p.orientation == 1
assert p.original_orientation == 1
assert p.original_filesize == 460483
def test_missing(): def test_missing():
import osxphotos import osxphotos
@@ -160,8 +207,8 @@ def test_missing():
photos = photosdb.photos(uuid=["od0fmC7NQx+ayVr+%i06XA"]) photos = photosdb.photos(uuid=["od0fmC7NQx+ayVr+%i06XA"])
assert len(photos) == 1 assert len(photos) == 1
p = photos[0] p = photos[0]
assert p.path == None assert p.path is None
assert p.ismissing == True assert p.ismissing
def test_favorite(): def test_favorite():
@@ -307,7 +354,63 @@ def test_count():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos() photos = photosdb.photos()
assert len(photos) == 7 assert len(photos) == PHOTOS_NOT_IN_TRASH_LEN
def test_photos_intrash_1():
""" test PhotosDB.photos(intrash=True) """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(intrash=True)
assert len(photos) == PHOTOS_IN_TRASH_LEN
def test_photos_intrash_2():
""" test PhotosDB.photos(intrash=True) """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(intrash=True)
for p in photos:
assert p.intrash
def test_photos_intrash_2():
""" test PhotosDB.photos(intrash=False) """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(intrash=False)
for p in photos:
assert not p.intrash
def test_photoinfo_intrash_1():
""" Test PhotoInfo.intrash """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
p = photosdb.photos(uuid=[UUID_DICT["intrash"]], intrash=True)[0]
assert p.intrash
def test_photoinfo_intrash_2():
""" Test PhotoInfo.intrash and intrash=default"""
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
p = photosdb.photos(uuid=[UUID_DICT["intrash"]])
assert not p
def test_photoinfo_not_intrash():
""" Test PhotoInfo.intrash """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
p = photosdb.photos(uuid=[UUID_DICT["not_intrash"]])[0]
assert not p.intrash
def test_keyword_2(): def test_keyword_2():
@@ -407,3 +510,30 @@ def test_multi_person():
photos = photosdb.photos(persons=["Katie", "Suzy"]) photos = photosdb.photos(persons=["Katie", "Suzy"])
assert len(photos) == 3 assert len(photos) == 3
def test_date_invalid():
""" Test date is invalid """
from datetime import datetime, timedelta, timezone
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["date_invalid"]])
assert len(photos) == 1
p = photos[0]
delta = timedelta(seconds=p.tzoffset)
tz = timezone(delta)
assert p.date == datetime(1970, 1, 1).astimezone(tz=tz)
def test_date_modified_invalid():
""" Test date modified is invalid """
from datetime import datetime, timedelta, timezone
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["date_invalid"]])
assert len(photos) == 1
p = photos[0]
assert p.date_modified is None

View File

@@ -13,6 +13,9 @@ ALBUM_DICT = {}
UUID_DICT = {"movie": "CfnR005YQ1uvNdq8UcnFtw", "image": "XuKdBnARTB+fPyyY+uh4fQ"} UUID_DICT = {"movie": "CfnR005YQ1uvNdq8UcnFtw", "image": "XuKdBnARTB+fPyyY+uh4fQ"}
PHOTOS_LEN = 6
MOVIES_LEN = 1
def test_init(): def test_init():
import osxphotos import osxphotos
@@ -97,8 +100,8 @@ def test_count_photos():
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos() photos = photosdb.photos(movies=False)
assert len(photos) == 6 assert len(photos) == PHOTOS_LEN
def test_count_movies(): def test_count_movies():
@@ -106,7 +109,7 @@ def test_count_movies():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(movies=True, images=False) photos = photosdb.photos(movies=True, images=False)
assert len(photos) == 1 assert len(photos) == MOVIES_LEN
def test_count_movies_2(): def test_count_movies_2():
@@ -114,7 +117,7 @@ def test_count_movies_2():
# if don't ask for movies=True, won't get any # if don't ask for movies=True, won't get any
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["movie"]]) photos = photosdb.photos(uuid=[UUID_DICT["movie"]], movies=False)
assert len(photos) == 0 assert len(photos) == 0
@@ -123,7 +126,7 @@ def test_count_all():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(images=True, movies=True) photos = photosdb.photos(images=True, movies=True)
assert len(photos) == 7 assert len(photos) == PHOTOS_LEN + MOVIES_LEN
def test_uti_movie(): def test_uti_movie():

View File

@@ -16,6 +16,9 @@ UUID_DICT = {
"image": "FF158787-3EA0-4B06-8D93-4E7E362495DE", "image": "FF158787-3EA0-4B06-8D93-4E7E362495DE",
} }
PHOTOS_LEN = 6
MOVIES_LEN = 1
def test_init(): def test_init():
import osxphotos import osxphotos
@@ -102,8 +105,8 @@ def test_count_photos():
import osxphotos import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos() photos = photosdb.photos(movies=False)
assert len(photos) == 6 assert len(photos) == PHOTOS_LEN
def test_count_movies(): def test_count_movies():
@@ -111,7 +114,7 @@ def test_count_movies():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(movies=True, images=False) photos = photosdb.photos(movies=True, images=False)
assert len(photos) == 1 assert len(photos) == MOVIES_LEN
def test_count_movies_2(): def test_count_movies_2():
@@ -119,7 +122,7 @@ def test_count_movies_2():
# if don't ask for movies=True, won't get any # if don't ask for movies=True, won't get any
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=[UUID_DICT["movie"]]) photos = photosdb.photos(uuid=[UUID_DICT["movie"]], movies=False)
assert len(photos) == 0 assert len(photos) == 0
@@ -128,7 +131,7 @@ def test_count_all():
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB) photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(images=True, movies=True) photos = photosdb.photos(images=True, movies=True)
assert len(photos) == 7 assert len(photos) == PHOTOS_LEN + MOVIES_LEN
def test_uti_movie(): def test_uti_movie():

97
tests/test_score_info.py Normal file
View File

@@ -0,0 +1,97 @@
""" Test ScoreInfo """
from math import isclose
import pytest
from osxphotos.photoinfo import ScoreInfo
PHOTOS_DB_5 = "tests/Test-10.15.5.photoslibrary"
PHOTOS_DB_4 = "tests/Test-10.14.6.photoslibrary"
SCORE_DICT = {
"4D521201-92AC-43E5-8F7C-59BC41C37A96": ScoreInfo(
overall=0.470703125,
curation=0.5,
promotion=0.0,
highlight_visibility=0.03816793893129771,
behavioral=0.0,
failure=-0.0006928443908691406,
harmonious_color=0.017852783203125,
immersiveness=0.003086090087890625,
interaction=0.019999999552965164,
interesting_subject=-0.0885009765625,
intrusive_object_presence=-0.037872314453125,
lively_color=0.10540771484375,
low_light=0.00824737548828125,
noise=-0.015655517578125,
pleasant_camera_tilt=-0.006256103515625,
pleasant_composition=0.028564453125,
pleasant_lighting=-0.00439453125,
pleasant_pattern=0.09088134765625,
pleasant_perspective=0.11859130859375,
pleasant_post_processing=0.00698089599609375,
pleasant_reflection=-0.01523590087890625,
pleasant_symmetry=0.01242828369140625,
sharply_focused_subject=0.08538818359375,
tastefully_blurred=0.022125244140625,
well_chosen_subject=0.05596923828125,
well_framed_subject=0.5986328125,
well_timed_shot=0.0134124755859375,
),
"6191423D-8DB8-4D4C-92BE-9BBBA308AAC4": ScoreInfo(
overall=0.853515625,
curation=0.75,
promotion=0.0,
highlight_visibility=0.05725190839694656,
behavioral=0.0,
failure=-0.0004916191101074219,
harmonious_color=0.382080078125,
immersiveness=0.0133209228515625,
interaction=0.03999999910593033,
interesting_subject=0.1632080078125,
intrusive_object_presence=-0.00966644287109375,
lively_color=0.44091796875,
low_light=0.01322174072265625,
noise=-0.0026721954345703125,
pleasant_camera_tilt=0.028045654296875,
pleasant_composition=0.33642578125,
pleasant_lighting=0.46142578125,
pleasant_pattern=0.1944580078125,
pleasant_perspective=0.494384765625,
pleasant_post_processing=0.4970703125,
pleasant_reflection=0.00910186767578125,
pleasant_symmetry=0.00930023193359375,
sharply_focused_subject=0.52490234375,
tastefully_blurred=0.63916015625,
well_chosen_subject=0.64208984375,
well_framed_subject=0.485595703125,
well_timed_shot=0.01531219482421875,
),
}
@pytest.fixture
def photosdb():
import osxphotos
return osxphotos.PhotosDB(dbfile=PHOTOS_DB_5)
def test_score_info_v5(photosdb):
""" test score """
# use math.isclose to compare floats
# on MacOS x64 these can probably compared for equality but would possibly
# fail if osxphotos ever ported to other platforms
for uuid in SCORE_DICT:
photo = photosdb.photos(uuid=[uuid], movies=True)[0]
for attr in photo.score.__dict__:
assert isclose(getattr(photo.score, attr), getattr(SCORE_DICT[uuid], attr))
def test_score_info_v4():
""" test version 4, score should be None """
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_4)
for photo in photosdb.photos():
assert photo.score is None

Some files were not shown because too many files have changed in this diff Show More