diff --git a/API_README.md b/API_README.md index 3264a690..f04c10b4 100644 --- a/API_README.md +++ b/API_README.md @@ -2005,7 +2005,7 @@ cog.out(get_template_field_table()) |{lf}|A line feed: '\n', alias for {newline}| |{cr}|A carriage return: '\r'| |{crlf}|a carriage return + line feed: '\r\n'| -|{osxphotos_version}|The osxphotos version, e.g. '0.50.13'| +|{osxphotos_version}|The osxphotos version, e.g. '0.51.0'| |{osxphotos_cmd_line}|The full command line used to run osxphotos| |{album}|Album(s) photo is contained in| |{folder_album}|Folder path + album photo is contained in. e.g. 'Folder/Subfolder/Album' or just 'Album' if no enclosing folder| diff --git a/README.md b/README.md index 82622f67..2ee29236 100644 --- a/README.md +++ b/README.md @@ -1953,7 +1953,7 @@ Substitution Description {lf} A line feed: '\n', alias for {newline} {cr} A carriage return: '\r' {crlf} a carriage return + line feed: '\r\n' -{osxphotos_version} The osxphotos version, e.g. '0.50.13' +{osxphotos_version} The osxphotos version, e.g. '0.51.0' {osxphotos_cmd_line} The full command line used to run osxphotos The following substitutions may result in multiple values. Thus if specified @@ -2430,7 +2430,7 @@ The following template field substitutions are availabe for use the templating s |{lf}|A line feed: '\n', alias for {newline}| |{cr}|A carriage return: '\r'| |{crlf}|a carriage return + line feed: '\r\n'| -|{osxphotos_version}|The osxphotos version, e.g. '0.50.13'| +|{osxphotos_version}|The osxphotos version, e.g. '0.51.0'| |{osxphotos_cmd_line}|The full command line used to run osxphotos| |{album}|Album(s) photo is contained in| |{folder_album}|Folder path + album photo is contained in. e.g. 'Folder/Subfolder/Album' or just 'Album' if no enclosing folder| diff --git a/docs/.buildinfo b/docs/.buildinfo index b6490645..0f97a0d1 100644 --- a/docs/.buildinfo +++ b/docs/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: fb04ea7e5d453b9c94599f1736a60474 +config: ec5046c1e0bd94597cfc68b7f262f83c tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/_modules/index.html b/docs/_modules/index.html index 4c1c8291..3cbec3c7 100644 --- a/docs/_modules/index.html +++ b/docs/_modules/index.html @@ -5,7 +5,7 @@ - Overview: module code - osxphotos 0.50.13 documentation + Overview: module code - osxphotos 0.51.0 documentation @@ -123,7 +123,7 @@
-
osxphotos 0.50.13 documentation
+
osxphotos 0.51.0 documentation
@@ -146,7 +146,7 @@
@@ -146,7 +146,7 @@
@@ -146,7 +146,7 @@ +def folder_by_path(folders: List[str], verbose: Optional[callable] = None) -> Folder: + """Get (and create if necessary) a Photos Folder by path (passed as list of folder names)""" + library = PhotosLibrary() + verbose = verbose or noop + top_folder_name = folders.pop(0) + top_folder = library.folder(top_folder_name, top_level=True) + if not top_folder: + verbose(f"Creating folder '{top_folder_name}'") + top_folder = library.create_folder(top_folder_name) + current_folder = top_folder + for folder_name in folders: + folder = current_folder.folder(folder_name) + if not folder: + verbose(f"Creating folder '{folder_name}'") + folder = current_folder.create_folder(folder_name) + current_folder = folder + return current_folder + + +def album_by_path( + folders_album: List[str], verbose: Optional[callable] = None +) -> Album: + """Get (and create if necessary) a Photos Album by path (pass as list of folders, album name)""" + library = PhotosLibrary() + verbose = verbose or noop + if len(folders_album) > 1: + # have folders + album_name = folders_album.pop() + folder = folder_by_path(folders_album, verbose) + album = folder.album(album_name) + if not album: + verbose(f"Creating album '{album_name}'") + album = folder.create_album(album_name) + else: + # only have album name + album_name = folders_album[0] + album = library.album(album_name, top_level=True) + if not album: + verbose(f"Creating album '{album_name}'") + album = library.create_album(album_name) + + return album + +
[docs]class PhotosAlbumPhotoScript: """Add photoscript.Photo objects to album""" - def __init__(self, name: str, verbose: Optional[callable] = None): - self.name = name + def __init__( + self, name: str, verbose: Optional[callable] = None, split_folder: Optional[str] = None + ): + """Return a PhotosAlbumPhotoScript object, creating the album if necessary + + Args: + name: Name of album + verbose: optional callable to print verbose output + split_folder: if set, split album name on value of split_folder to create folders if necessary, + e.g. if name = 'folder1/folder2/album' and split_folder='/', + then folders 'folder1' and 'folder2' will be created and album 'album' will be created in 'folder2'; + if not set, album 'folder1/folder2/album' will be created + """ self.verbose = verbose or noop self.library = PhotosLibrary() - album = self.library.album(name) - if album is None: - self.verbose(f"Creating Photos album '{self.name}'") - album = self.library.create_album(name) - self.album = album + folders_album = name.split(split_folder) if split_folder else [name] + self.album = album_by_path(folders_album, verbose=verbose) + self.name = name def add(self, photo: Photo): self.album.add([photo]) diff --git a/docs/_modules/osxphotos/phototemplate.html b/docs/_modules/osxphotos/phototemplate.html index 2be904cd..054259cd 100644 --- a/docs/_modules/osxphotos/phototemplate.html +++ b/docs/_modules/osxphotos/phototemplate.html @@ -5,7 +5,7 @@ - osxphotos.phototemplate - osxphotos 0.50.3 documentation + osxphotos.phototemplate - osxphotos 0.51.0 documentation @@ -123,7 +123,7 @@
@@ -146,7 +146,7 @@
@@ -147,7 +147,7 @@
@@ -145,7 +145,7 @@
@@ -147,7 +147,7 @@
@@ -147,7 +147,7 @@
@@ -147,7 +147,7 @@
@@ -145,7 +145,7 @@
@@ -147,7 +147,7 @@
@@ -144,7 +144,7 @@
@@ -147,7 +147,7 @@
@@ -147,7 +147,7 @@