Bug search info macos13 816 (#831)
* Fixed SearchInfo for macOS 13, #816 * Additional fixes for SearchInfo, #816
This commit is contained in:
parent
de14583215
commit
c2c2da6c95
@ -236,21 +236,29 @@ class SearchCategory:
|
||||
PHOTO_TYPE_FAVORITES,
|
||||
]
|
||||
PHOTO_NAME = 2056
|
||||
CAMERA = None # Photos 8+ only
|
||||
DETECTED_TEXT = None # Photos 8+ only
|
||||
|
||||
|
||||
class SearchCategory_Photos8(SearchCategory):
|
||||
"""Search categories for Photos 8"""
|
||||
|
||||
# NOTE: This list is incomplete;
|
||||
# until I get a test library that's been processed by photoanalysisd on Ventura,
|
||||
# I can't verify all these are correct
|
||||
# Many of the category values changed in Ventura / Photos 8
|
||||
# and some new categories were added
|
||||
LABEL = 1500
|
||||
MONTH = 1100
|
||||
YEAR = 1101
|
||||
HOLIDAY = 1103
|
||||
SEASON = 1104
|
||||
ACTIVITY = 1600
|
||||
KEYWORDS = 1200
|
||||
TITLE = 1201
|
||||
DESCRIPTION = 1202
|
||||
DETECTED_TEXT = 1203 # new in Photos 8
|
||||
PERSON = 1300
|
||||
ACTIVITY = 1600
|
||||
PHOTO_TYPE_FAVORITES = 2000
|
||||
PHOTO_NAME = 2100
|
||||
CAMERA = 2300 # new in Photos 8
|
||||
|
||||
|
||||
def search_category_factory(version: int) -> SearchCategory:
|
||||
|
||||
@ -132,6 +132,21 @@ class SearchInfo:
|
||||
types += self._get_text_for_category(category)
|
||||
return types
|
||||
|
||||
@property
|
||||
def detected_text(self):
|
||||
"""Returns text detected in the photo (macOS 13+ / Photos 8+ only)"""
|
||||
if self._photo._db._photos_ver < 8:
|
||||
return []
|
||||
return self._get_text_for_category(self._categories.DETECTED_TEXT)
|
||||
|
||||
@property
|
||||
def camera(self):
|
||||
"""returns camera name (macOS 13+ / Photos 8+ only)"""
|
||||
if self._photo._db._photos_ver < 8:
|
||||
return ""
|
||||
camera = self._get_text_for_category(self._categories.CAMERA)
|
||||
return camera[0] if camera else ""
|
||||
|
||||
@property
|
||||
def all(self):
|
||||
"""return all search info properties in a single list"""
|
||||
@ -147,6 +162,7 @@ class SearchInfo:
|
||||
+ self.venues
|
||||
+ self.venue_types
|
||||
+ self.media_types
|
||||
+ self.detected_text
|
||||
)
|
||||
if self.city:
|
||||
all += [self.city]
|
||||
@ -162,6 +178,8 @@ class SearchInfo:
|
||||
all += [self.year]
|
||||
if self.season:
|
||||
all += [self.season]
|
||||
if self.camera:
|
||||
all += [self.camera]
|
||||
|
||||
return all
|
||||
|
||||
@ -186,6 +204,8 @@ class SearchInfo:
|
||||
"venues": self.venues,
|
||||
"venue_types": self.venue_types,
|
||||
"media_types": self.media_types,
|
||||
"detected_text": self.detected_text,
|
||||
"camera": self.camera,
|
||||
}
|
||||
|
||||
def _get_text_for_category(self, category):
|
||||
|
||||
@ -30,6 +30,8 @@ A couple of tests require interaction with Photos and configuring a specific tes
|
||||
## Test Photo Libraries
|
||||
**Important**: The test code uses several test photo libraries created on various version of MacOS. If you need to inspect one of these or modify one for a test, make a copy of the library (for example, copy it to your ~/Pictures folder) then open the copy in Photos. Once done, copy the revised library back to the tests/ folder. If you do not do this, the Photos background process photoanalysisd will forever try to process the library resulting in updates to the database which will cause git to see changes to the file you didn't intend. I'm not aware of any way to disassociate photoanalysisd from the library once you've opened it in Photos.
|
||||
|
||||
Some of the "search_info" tests require data from my personal library on Catalina 10.15.7. The data is generated by running `tests/generate_search_info_test_data.py`
|
||||
|
||||
## Attribution ##
|
||||
These tests utilize a test Photos library. The test library is populated with photos from [flickr](https://www.flickr.com) and from my own photo library. All images used are licensed under Creative Commons 2.0 Attribution [license](https://creativecommons.org/licenses/by/2.0/).
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -198,6 +198,42 @@ UUID_MOMENT = {
|
||||
|
||||
UUID_LABELS = {"6191423D-8DB8-4D4C-92BE-9BBBA308AAC4": ["Plant", "Flower Arrangement"]}
|
||||
|
||||
UUID_CAMERA = {
|
||||
"4D521201-92AC-43E5-8F7C-59BC41C37A96": "Canon PowerShot G10",
|
||||
"A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C": "",
|
||||
}
|
||||
|
||||
|
||||
UUID_DETECTED_TEXT = {
|
||||
"4D521201-92AC-43E5-8F7C-59BC41C37A96": ["mint", "mojito", "sprouts"],
|
||||
"A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C": [],
|
||||
}
|
||||
|
||||
UUID_SEARCH_INFO = {
|
||||
"3DD2C897-F19E-4CA6-8C22-B027D5A71907": {
|
||||
"labels": ["Art", "Clothing", "Plant", "Statue"],
|
||||
"place_names": ["River Torrens/Karrawirra Parri"],
|
||||
"streets": ["River Torrens Linear Park Trl"],
|
||||
"neighborhoods": ["Central Ward"],
|
||||
"city": "",
|
||||
"locality_names": ["Adelaide", "South Australia"],
|
||||
"state": "Adelaide",
|
||||
"state_abbreviation": "SA",
|
||||
"country": "Australia",
|
||||
"bodies_of_water": [],
|
||||
"month": "June",
|
||||
"year": "2017",
|
||||
"holidays": [],
|
||||
"activities": [],
|
||||
"season": "Summer",
|
||||
"venues": [],
|
||||
"venue_types": [],
|
||||
"media_types": [],
|
||||
"detected_text": [],
|
||||
"camera": "Apple iPhone 6s",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def photosdb():
|
||||
@ -1173,3 +1209,27 @@ def test_labels(photosdb):
|
||||
photo = photosdb.get_photo(uuid=uuid)
|
||||
for label in labels:
|
||||
assert label in photo.labels
|
||||
|
||||
|
||||
def test_search_info_camera(photosdb):
|
||||
"""Test SearchInfo camera (new to Photos 8)"""
|
||||
for uuid, camera in UUID_CAMERA.items():
|
||||
photo = photosdb.get_photo(uuid=uuid)
|
||||
assert photo.search_info.camera == camera
|
||||
|
||||
|
||||
def test_search_info_detected_text(photosdb):
|
||||
"""Test SearchInfo detected text (new to Photos 8)"""
|
||||
for uuid, detected_text in UUID_DETECTED_TEXT.items():
|
||||
photo = photosdb.get_photo(uuid=uuid)
|
||||
assert (
|
||||
sorted([x.lower() for x in photo.search_info.detected_text])
|
||||
== detected_text
|
||||
)
|
||||
|
||||
|
||||
def test_search_info_dict(photosdb):
|
||||
"""Test SearchInfo changes for Photos 8"""
|
||||
for uuid, search_info in UUID_SEARCH_INFO.items():
|
||||
photo = photosdb.get_photo(uuid=uuid)
|
||||
assert photo.search_info.asdict() == search_info
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user