diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 0a9a4b73..3936fd64 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.26.0" +__version__ = "0.26.1" diff --git a/osxphotos/photosdb.py b/osxphotos/photosdb.py index c85e6213..52dbe0e7 100644 --- a/osxphotos/photosdb.py +++ b/osxphotos/photosdb.py @@ -2089,37 +2089,45 @@ class PhotosDB: photos_sets.append(set(self._dbphotos.keys())) else: if albums: + album_set = set() for album in albums: # TODO: can have >1 album with same name. This globs them together. # Need a way to select which album? if album in self._dbalbum_titles: - album_set = set() + title_set = set() for album_id in self._dbalbum_titles[album]: - album_set.update(self._dbalbums_album[album_id]) - photos_sets.append(album_set) + title_set.update(self._dbalbums_album[album_id]) + album_set.update(title_set) else: logging.debug(f"Could not find album '{album}' in database") + photos_sets.append(album_set) if uuid: + uuid_set = set() for u in uuid: if u in self._dbphotos: - photos_sets.append(set([u])) + uuid_set.update([u]) else: logging.debug(f"Could not find uuid '{u}' in database") + photos_sets.append(uuid_set) if keywords: + keyword_set = set() for keyword in keywords: if keyword in self._dbkeywords_keyword: - photos_sets.append(set(self._dbkeywords_keyword[keyword])) + keyword_set.update(self._dbkeywords_keyword[keyword]) else: logging.debug(f"Could not find keyword '{keyword}' in database") + photos_sets.append(keyword_set) if persons: + person_set = set() for person in persons: if person in self._dbfaces_person: - photos_sets.append(set(self._dbfaces_person[person])) + person_set.update(self._dbfaces_person[person]) else: logging.debug(f"Could not find person '{person}' in database") + photos_sets.append(person_set) if from_date or to_date: dsel = self._dbphotos diff --git a/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-shm b/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-shm index 8b1ed46e..51c67402 100644 Binary files a/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-shm and b/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-shm differ diff --git a/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-wal b/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-wal index 2eaad379..5e08134c 100644 Binary files a/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-wal and b/tests/Test-10.15.1.photoslibrary/database/Photos.sqlite-wal differ diff --git a/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite b/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite index 0a324bbd..4a4b4425 100644 Binary files a/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite and b/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite differ diff --git a/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite-shm b/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite-shm index 87b9adac..718b04ce 100644 Binary files a/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite-shm and b/tests/Test-10.15.1.photoslibrary/database/search/psi.sqlite-shm differ diff --git a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm index 8e4a547e..860b8e5c 100644 Binary files a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm and b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-shm differ diff --git a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal index f992c55c..986d65c3 100644 Binary files a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal and b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/CLSBusinessCategoryCache.POI.sqlite-wal differ diff --git a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist index 63520e73..f05a42ae 100644 --- a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist +++ b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotoAnalysisServicePreferences.plist @@ -3,23 +3,23 @@ BackgroundHighlightCollection - 2020-04-10T17:04:49Z + 2020-04-11T01:34:25Z BackgroundHighlightEnrichment - 2020-04-10T17:04:49Z + 2020-04-11T01:34:24Z BackgroundJobAssetRevGeocode - 2020-04-10T19:39:34Z + 2020-04-11T01:34:26Z BackgroundJobSearch - 2020-04-10T17:04:49Z + 2020-04-11T01:34:26Z BackgroundPeopleSuggestion - 2020-04-10T17:04:49Z + 2020-04-11T01:34:23Z BackgroundUserBehaviorProcessor 2020-04-10T06:04:05Z PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey - 2020-04-10T19:39:35Z + 2020-04-11T01:34:33Z PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate 2020-04-10T06:04:04Z PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate - 2020-04-10T18:04:20Z + 2020-04-11T01:34:26Z SiriPortraitDonation 2020-04-10T06:04:05Z diff --git a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb index 652f0197..e2e06c43 100644 Binary files a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb and b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/PhotosGraph/photosgraph.kgdb differ diff --git a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist index 0a3e3d51..d60746e7 100644 Binary files a/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist and b/tests/Test-10.15.1.photoslibrary/private/com.apple.photoanalysisd/caches/graph/changetoken.plist differ diff --git a/tests/Test-10.15.1.photoslibrary/resources/journals/Album-change.plj b/tests/Test-10.15.1.photoslibrary/resources/journals/Album-change.plj new file mode 100644 index 00000000..bd2f8379 Binary files /dev/null and b/tests/Test-10.15.1.photoslibrary/resources/journals/Album-change.plj differ diff --git a/tests/Test-10.15.1.photoslibrary/resources/journals/Folder-change.plj b/tests/Test-10.15.1.photoslibrary/resources/journals/Folder-change.plj new file mode 100644 index 00000000..cd761840 Binary files /dev/null and b/tests/Test-10.15.1.photoslibrary/resources/journals/Folder-change.plj differ diff --git a/tests/Test-10.15.1.photoslibrary/resources/journals/HistoryToken.plist b/tests/Test-10.15.1.photoslibrary/resources/journals/HistoryToken.plist index 56ba10d9..9f534fcd 100644 Binary files a/tests/Test-10.15.1.photoslibrary/resources/journals/HistoryToken.plist and b/tests/Test-10.15.1.photoslibrary/resources/journals/HistoryToken.plist differ diff --git a/tests/test_catalina_10_15_1.py b/tests/test_catalina_10_15_1.py index 86bdacdb..9c764186 100644 --- a/tests/test_catalina_10_15_1.py +++ b/tests/test_catalina_10_15_1.py @@ -24,6 +24,7 @@ PERSONS = ["Katie", "Suzy", "Maria", _UNKNOWN_PERSON] ALBUMS = [ "Pumpkin Farm", "Test Album", + "Multi Keyword", ] # Note: there are 2 albums named "Test Album" for testing duplicate album names KEYWORDS_DICT = { "Kids": 4, @@ -40,6 +41,7 @@ PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 1, _UNKNOWN_PERSON: 1} ALBUM_DICT = { "Pumpkin Farm": 3, "Test Album": 2, + "Multi Keyword": 2, } # Note: there are 2 albums named "Test Album" for testing duplicate album names UUID_DICT = { @@ -55,6 +57,8 @@ UUID_DICT = { "external_edit": "DC99FBDD-7A52-4100-A5BB-344131646C30", "no_external_edit": "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51", "export": "D79B8D77-BFFC-460B-9312-034F2877D35B", # "Pumkins2.jpg" + "multi_query_1": "D79B8D77-BFFC-460B-9312-034F2877D35B", + "multi_query_2": "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51", } @@ -202,7 +206,7 @@ def test_attributes(): ) assert p.description == "Girl holding pumpkin" assert p.title == "I found one!" - assert p.albums == ["Pumpkin Farm", "Test Album"] + assert p.albums == ["Pumpkin Farm", "Test Album", "Multi Keyword"] assert p.persons == ["Katie"] assert p.path.endswith( "tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg" @@ -778,3 +782,50 @@ def test_from_to_date(): from_date=dt.datetime(2018, 9, 28), to_date=dt.datetime(2018, 9, 29) ) assert len(photos) == 4 + + +def test_multi_uuid(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(uuid=[UUID_DICT["favorite"], UUID_DICT["not_favorite"]]) + + assert len(photos) == 2 + + +def test_multi_keyword(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(keywords=["Kids", "wedding"]) + + assert len(photos) == 6 + + +def test_multi_album(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(albums=["Pumpkin Farm", "Test Album"]) + + assert len(photos) == 3 + + +def test_multi_person(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(persons=["Katie", "Suzy"]) + + assert len(photos) == 3 + + +def test_compound_query(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(persons=["Katie", "Maria"], albums=["Multi Keyword"]) + + assert len(photos) == 2 + assert UUID_DICT["multi_query_1"] in [p.uuid for p in photos] + assert UUID_DICT["multi_query_2"] in [p.uuid for p in photos] diff --git a/tests/test_cli.py b/tests/test_cli.py index e877e6a0..5d023dc8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -29,7 +29,7 @@ CLI_OUTPUT_NO_SUBCOMMAND = [ " query Query the Photos database using 1 or more search options; if", ] -CLI_OUTPUT_QUERY_UUID = '[{"uuid": "D79B8D77-BFFC-460B-9312-034F2877D35B", "filename": "D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg", "original_filename": "Pumkins2.jpg", "date": "2018-09-28T16:07:07-04:00", "description": "Girl holding pumpkin", "title": "I found one!", "keywords": ["Kids"], "albums": ["Pumpkin Farm", "Test Album"], "persons": ["Katie"], "path": "/tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg", "ismissing": false, "hasadjustments": false, "external_edit": false, "favorite": false, "hidden": false, "latitude": null, "longitude": null, "path_edited": null, "shared": false, "isphoto": true, "ismovie": false, "uti": "public.jpeg", "burst": false, "live_photo": false, "path_live_photo": null, "iscloudasset": false, "incloud": null}]' +CLI_OUTPUT_QUERY_UUID = '[{"uuid": "D79B8D77-BFFC-460B-9312-034F2877D35B", "filename": "D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg", "original_filename": "Pumkins2.jpg", "date": "2018-09-28T16:07:07-04:00", "description": "Girl holding pumpkin", "title": "I found one!", "keywords": ["Kids"], "albums": ["Pumpkin Farm", "Test Album", "Multi Keyword"], "persons": ["Katie"], "path": "/tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg", "ismissing": false, "hasadjustments": false, "external_edit": false, "favorite": false, "hidden": false, "latitude": null, "longitude": null, "path_edited": null, "shared": false, "isphoto": true, "ismovie": false, "uti": "public.jpeg", "burst": false, "live_photo": false, "path_live_photo": null, "iscloudasset": false, "incloud": null}]' CLI_EXPORT_FILENAMES = [ "Pumkins1.jpg", @@ -52,7 +52,7 @@ CLI_EXPORTED_DIRECTORY_TEMPLATE_FILENAMES1 = [ ] CLI_EXPORTED_DIRECTORY_TEMPLATE_FILENAMES_ALBUM1 = [ - "_/wedding.jpg", + "Multi Keyword/wedding.jpg", "_/Tulips.jpg", "_/St James Park.jpg", "Pumpkin Farm/Pumpkins3.jpg", @@ -62,7 +62,7 @@ CLI_EXPORTED_DIRECTORY_TEMPLATE_FILENAMES_ALBUM1 = [ ] CLI_EXPORTED_DIRECTORY_TEMPLATE_FILENAMES_ALBUM2 = [ - "NOALBUM/wedding.jpg", + "Multi Keyword/wedding.jpg", "NOALBUM/Tulips.jpg", "NOALBUM/St James Park.jpg", "Pumpkin Farm/Pumpkins3.jpg", diff --git a/tests/test_mojave_10_14_6.py b/tests/test_mojave_10_14_6.py index 77edda43..dae9588c 100644 --- a/tests/test_mojave_10_14_6.py +++ b/tests/test_mojave_10_14_6.py @@ -33,7 +33,10 @@ KEYWORDS_DICT = { PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 1} ALBUM_DICT = {"Pumpkin Farm": 3, "Test Album": 1, "Test Album (1)": 1} -UUID_DICT = {"favorite": "6bxcNnzRQKGnK4uPrCJ9UQ"} +UUID_DICT = { + "favorite": "6bxcNnzRQKGnK4uPrCJ9UQ", + "not_favorite": "8SOE9s0XQVGsuq4ONohTng", +} def test_init(): @@ -354,3 +357,39 @@ def test_photosinfo_repr(): assert {k: str(v).encode("utf-8") for k, v in photo.__dict__.items()} == { k: str(v).encode("utf-8") for k, v in photo2.__dict__.items() } + + +def test_multi_uuid(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(uuid=[UUID_DICT["favorite"], UUID_DICT["not_favorite"]]) + + assert len(photos) == 2 + + +def test_multi_keyword(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(keywords=["Kids", "wedding"]) + + assert len(photos) == 6 + + +def test_multi_album(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(albums=["Pumpkin Farm", "Test Album"]) + + assert len(photos) == 3 + + +def test_multi_person(): + import osxphotos + + photosdb = osxphotos.PhotosDB(PHOTOS_DB) + photos = photosdb.photos(persons=["Katie", "Suzy"]) + + assert len(photos) == 3 diff --git a/tests/test_template.py b/tests/test_template.py index cd71182a..73ee6093 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -185,7 +185,11 @@ def test_subst_multi_2_1_1(): photo = photosdb.photos(uuid=[UUID_DICT["2_1_1"]])[0] template = "{created.year}/{album}/{keyword}/{person}" - expected = ["2018/Pumpkin Farm/Kids/Katie", "2018/Test Album/Kids/Katie"] + expected = [ + "2018/Pumpkin Farm/Kids/Katie", + "2018/Test Album/Kids/Katie", + "2018/Multi Keyword/Kids/Katie", + ] rendered, _ = render_filepath_template(template, photo) assert sorted(rendered) == sorted(expected)