Added PhotosDB() behavior to open last library if no args passed but also added cautionary note to README
This commit is contained in:
@@ -268,6 +268,7 @@ if __name__ == "__main__":
|
||||
#### Read a Photos library database
|
||||
|
||||
```python
|
||||
osxphotos.PhotosDB() # not recommended, see Note below
|
||||
osxphotos.PhotosDB(path)
|
||||
osxphotos.PhotosDB(dbfile=path)
|
||||
```
|
||||
@@ -278,6 +279,8 @@ Pass the path to a Photos library or to a specific database file (e.g. "/Users/s
|
||||
|
||||
If an invalid path is passed, PhotosDB will raise `ValueError` exception.
|
||||
|
||||
**Note**: If neither path or dbfile is passed, PhotosDB will use get_last_library_path to open the last opened Photos library. This usually works but is not 100% reliable. It can also lead to loading a different library than expected if the user has held down *option* key when opening Photos to switch libraries. It is therefore recommended you explicitely pass the path to `PhotosDB()`.
|
||||
|
||||
Open the default (last opened) Photos library. (E.g. this is the library that would open if the user opened Photos.app)
|
||||
|
||||
```python
|
||||
|
||||
@@ -165,11 +165,10 @@ class PhotosDB:
|
||||
dbfile_,
|
||||
)
|
||||
elif dbfile is None:
|
||||
raise TypeError(
|
||||
f"photos database path must be specified as argument or named parameter dbfile",
|
||||
dbfile_,
|
||||
dbfile,
|
||||
)
|
||||
dbfile = get_last_library_path()
|
||||
if dbfile is None:
|
||||
# get_last_library_path must have failed to find library
|
||||
raise FileNotFoundError("Could not get path to photo library database")
|
||||
|
||||
if os.path.isdir(dbfile):
|
||||
# passed a directory, assume it's a photoslibrary
|
||||
|
||||
Reference in New Issue
Block a user