Supports duplicate album names (treated as single album)

This commit is contained in:
Rhet Turnbull
2019-12-07 12:51:39 -08:00
parent ff4066c49c
commit 2a0f27ca57
37 changed files with 38 additions and 27 deletions

View File

@@ -172,7 +172,7 @@ Returns a list of the keywords found in the Photos library
albums = photosdb.albums()
```
Returns a list of the albums found in the Photos library
Returns a list of the albums found in the Photos library. **Note**: It is possible to have more than one album with the same name in Photos. Albums with duplicate names are treated as a single album and the photos in each are combined. For example, if you have two albums named "Wedding" and each has 2 photos, osxphotos will treat this as a single album named "Wedding" with 4 photos in it.
#### ```persons```
```python
@@ -204,7 +204,7 @@ Returns a dictionary of persons (faces) found in the Photos library where key is
albums_dict = photosdb.albums_as_dict()
```
Returns a dictionary of albums found in the Photos library where key is the album name and value is the count of how many photos are in the album. Resulting dictionary is in reverse sorted order (e.g. album with the most photos is listed first)
Returns a dictionary of albums found in the Photos library where key is the album name and value is the count of how many photos are in the album. Resulting dictionary is in reverse sorted order (e.g. album with the most photos is listed first). **Note**: It is possible to have more than one album with the same name in Photos. Albums with duplicate names are treated as a single album and the photos in each are combined. For example, if you have two albums named "Wedding" and each has 2 photos, osxphotos will treat this as a single album named "Wedding" with 4 photos in it.
#### ```get_photos_library_path```
```python

View File

@@ -234,7 +234,10 @@ class PhotosDB:
albums = {}
for k in self._dbalbums_album.keys():
title = self._dbalbum_details[k]["title"]
albums[title] = len(self._dbalbums_album[k])
if title in albums:
albums[title] += len(self._dbalbums_album[k])
else:
albums[title] = len(self._dbalbums_album[k])
albums = dict(sorted(albums.items(), key=lambda kv: kv[1], reverse=True))
return albums
@@ -250,12 +253,12 @@ class PhotosDB:
def albums(self):
""" return list of albums found in photos database """
albums = []
# 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
albums = set()
for album in self._dbalbums_album.keys():
albums.append(self._dbalbum_details[album]["title"])
return albums
# albums = self._dbalbums_album.keys()
# return list(albums)
albums.add(self._dbalbum_details[album]["title"])
return list(albums)
def _setup_applescript(self):
""" setup various applescripts used internally (e.g. to close Photos) """
@@ -1108,11 +1111,12 @@ class PhotosDB:
album_titles[title] = [album_id]
for album in albums:
# TODO: can have >1 album with same name. This globs them together.
# Need a way to select with album
# TODO: document this in docs and add test
# Need a way to select with album?
if album in album_titles:
album_set = set()
for album_id in album_titles[album]:
photos_sets.append(set(self._dbalbums_album[album_id]))
album_set.update(self._dbalbums_album[album_id])
photos_sets.append(album_set)
else:
logging.debug(f"Could not find album '{album}' in database")
@@ -1140,12 +1144,15 @@ class PhotosDB:
photoinfo = []
if photos_sets: # found some photos
# get the intersection of each argument/search criteria
logging.debug(f"Got here: {photos_sets}")
for p in set.intersection(*photos_sets):
info = PhotoInfo(db=self, uuid=p, info=self._dbphotos[p])
photoinfo.append(info)
logging.debug(f"photoinfo: {pformat(photoinfo)}")
return photoinfo
def __repr__(self):
# TODO: update to use __class__ and __name__
return f"osxphotos.PhotosDB(dbfile='{self.get_db_path()}')"
@@ -1367,6 +1374,7 @@ class PhotoInfo:
return self.__info["latitude"]
def __repr__(self):
# TODO: update to use __class__ and __name__
return f"osxphotos.PhotoInfo(db={self.__db}, uuid='{self.__uuid}', info={self.__info})"
def __str__(self):

View File

@@ -38,7 +38,7 @@ with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
setup(
name="osxphotos",
version="0.14.10",
version="0.14.11",
description="Manipulate (read-only) Apple's Photos app library on Mac OS X",
long_description=long_description,
long_description_content_type="text/markdown",

View File

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

View File

@@ -4,8 +4,6 @@
<dict>
<key>BlacklistedMeaningsByMeaning</key>
<dict/>
<key>MePersonUUID</key>
<string>39488755-78C0-40B2-B378-EDA280E1823C</string>
<key>SceneWhitelist</key>
<array>
<string>Graduation</string>

View File

@@ -4,6 +4,10 @@
<dict>
<key>CollapsedSidebarSectionIdentifiers</key>
<array/>
<key>ExpandedSidebarItemIdentifiers</key>
<array>
<string>92D68107-B6C7-453B-96D2-97B0F26D5B8B/L0/020</string>
</array>
<key>Photos</key>
<dict>
<key>CollapsedSidebarSectionIdentifiers</key>

View File

@@ -3,24 +3,24 @@
<plist version="1.0">
<dict>
<key>BackgroundHighlightCollection</key>
<date>2019-12-01T15:27:50Z</date>
<date>0000-12-30T00:00:00Z</date>
<key>BackgroundHighlightEnrichment</key>
<date>2019-12-01T15:27:50Z</date>
<date>0000-12-30T00:00:00Z</date>
<key>BackgroundJobAssetRevGeocode</key>
<date>2019-12-01T15:27:51Z</date>
<date>0000-12-30T00:00:00Z</date>
<key>BackgroundJobSearch</key>
<date>2019-12-01T15:27:51Z</date>
<date>0000-12-30T00:00:00Z</date>
<key>BackgroundPeopleSuggestion</key>
<date>2019-12-01T15:27:50Z</date>
<date>0000-12-30T00:00:00Z</date>
<key>BackgroundUserBehaviorProcessor</key>
<date>2019-12-01T15:27:51Z</date>
<date>0000-12-30T00:00:00Z</date>
<key>PhotoAnalysisGraphLastBackgroundGraphConsistencyUpdateJobDateKey</key>
<date>2019-11-13T03:46:28Z</date>
<date>2019-12-07T19:48:13Z</date>
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
<date>2019-11-13T03:46:27Z</date>
<date>2019-12-07T19:48:13Z</date>
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
<date>2019-12-01T15:27:51Z</date>
<key>SiriPortraitDonation</key>
<date>2019-12-01T15:27:51Z</date>
<date>0000-12-30T00:00:00Z</date>
</dict>
</plist>

View File

@@ -16,7 +16,7 @@ KEYWORDS = [
]
# Photos 5 includes blank person for detected face
PERSONS = ["Katie", "Suzy", "Maria", ""]
ALBUMS = ["Pumpkin Farm"]
ALBUMS = ["Pumpkin Farm", "Test Album"] # Note: there are 2 albums named "Test Album" for testing duplicate album names
KEYWORDS_DICT = {
"Kids": 4,
"wedding": 2,
@@ -29,7 +29,8 @@ KEYWORDS_DICT = {
"United Kingdom": 1,
}
PERSONS_DICT = {"Katie": 3, "Suzy": 2, "Maria": 1, "": 1}
ALBUM_DICT = {"Pumpkin Farm": 3}
ALBUM_DICT = {"Pumpkin Farm": 3, "Test Album": 2} # Note: there are 2 albums named "Test Album" for testing duplicate album names
def test_init():
@@ -124,7 +125,7 @@ def test_attributes():
)
assert p.description() == "Girl holding pumpkin"
assert p.name() == "I found one!"
assert p.albums() == ["Pumpkin Farm"]
assert p.albums() == ["Pumpkin Farm", "Test Album"]
assert p.persons() == ["Katie"]
assert p.path().endswith(
"tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"