From c0a76d27340db968f3c14636048c0ed0924004ba Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:06:06 +0200 Subject: [PATCH 1/4] Feature Album order option --- immich_auto_album.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/immich_auto_album.py b/immich_auto_album.py index ef924c6..1497422 100644 --- a/immich_auto_album.py +++ b/immich_auto_album.py @@ -51,6 +51,7 @@ parser.add_argument("-d", "--delete-confirm", action="store_true", help="Confirm parser.add_argument("-x", "--share-with", action="append", help="A user name (or email address of an existing user) to share newly created albums with. Sharing only happens if the album was actually created, not if new assets were added to an existing album. If the the share role should be specified by user, the format = must be used, where must be one of 'viewer' or 'editor'. May be specified multiple times to share albums with more than one user.") parser.add_argument("-o", "--share-role", default="viewer", choices=['viewer', 'editor'], help="The default share role for users newly created albums are shared with. Only effective if --share-with is specified at least once and the share role is not specified within --share-with.") parser.add_argument("-S", "--sync-mode", default=0, type=int, choices=[0, 1, 2], help="Synchronization mode to use. Synchronization mode helps synchronizing changes in external libraries structures to Immich after albums have already been created. Possible Modes: 0 = do nothing; 1 = Delete any empty albums; 2 = Trigger offline asset removal (REQUIRES API KEY OF AN ADMIN USER!)") +parser.add_argument("-O", "--album-order", default=False, type=str, choices=[False, 'asc', 'desc'], help="Set album sorting to newest or oldes file first, immich defaults to newest file first") args = vars(parser.parse_args()) # set up logger to log in logfmt format @@ -68,6 +69,7 @@ album_levels = args["album_levels"] # Album Levels Range handling album_levels_range_arr = () album_level_separator = args["album_separator"] +album_order = args["album_order"] insecure = args["insecure"] ignore_albums = args["ignore"] mode = args["mode"] @@ -91,6 +93,7 @@ logging.debug("unattended = %s", unattended) logging.debug("album_levels = %s", album_levels) #logging.debug("album_levels_range = %s", album_levels_range) logging.debug("album_level_separator = %s", album_level_separator) +logging.debug("album_order = %s", album_order) logging.debug("insecure = %s", insecure) logging.debug("ignore = %s", ignore_albums) logging.debug("mode = %s", mode) @@ -191,6 +194,7 @@ def parseSeparatedStrings(items: list[str]) -> dict: return d def create_album_name(path_chunks: list[str], album_separator: str) -> str: + """ Create album names from provided path_chunks string array. @@ -353,7 +357,7 @@ def deleteAlbum(album: dict): return True -def createAlbum(albumName: str) -> str: +def createAlbum(albumName: str, albumOrder: str) -> str: """ Creates an album with the provided name and returns the ID of the created album @@ -362,6 +366,8 @@ def createAlbum(albumName: str) -> str: ---------- albumName : str Name of the album to create + albumOrder : str + False or order [asc|desc] Returns --------- @@ -380,7 +386,16 @@ def createAlbum(albumName: str) -> str: } r = requests.post(root_url+apiEndpoint, json=data, **requests_kwargs) assert r.status_code in [200, 201] - return r.json()['id'] + + albumId = r.json()['id'] + + if albumOrder: + data = { + 'order': 'asc', + } + r = requests.patch(root_url+apiEndpoint+f'/{albumId}', json=data, **requests_kwargs) + assert r.status_code in [200, 201] + return albumId def addAssetsToAlbum(albumId: str, assets: list[str]): @@ -640,7 +655,7 @@ created_albums = dict() for album in album_to_assets: if album in album_to_id: continue - album_id = createAlbum(album) + album_id = createAlbum(album, album_order) album_to_id[album] = album_id created_albums[album] = album_id logging.info('Album %s added!', album) From d81b1b0675ef44e688e6da23e693be4ee0da9468 Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:07:59 +0200 Subject: [PATCH 2/4] cleanup --- immich_auto_album.py | 1 - 1 file changed, 1 deletion(-) diff --git a/immich_auto_album.py b/immich_auto_album.py index 1497422..88b491e 100644 --- a/immich_auto_album.py +++ b/immich_auto_album.py @@ -194,7 +194,6 @@ def parseSeparatedStrings(items: list[str]) -> dict: return d def create_album_name(path_chunks: list[str], album_separator: str) -> str: - """ Create album names from provided path_chunks string array. From 5730236383759bca4c85b0065ad821726b6d8c8d Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:10:04 +0200 Subject: [PATCH 3/4] fix typo --- immich_auto_album.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/immich_auto_album.py b/immich_auto_album.py index 88b491e..a8ec3ef 100644 --- a/immich_auto_album.py +++ b/immich_auto_album.py @@ -51,7 +51,7 @@ parser.add_argument("-d", "--delete-confirm", action="store_true", help="Confirm parser.add_argument("-x", "--share-with", action="append", help="A user name (or email address of an existing user) to share newly created albums with. Sharing only happens if the album was actually created, not if new assets were added to an existing album. If the the share role should be specified by user, the format = must be used, where must be one of 'viewer' or 'editor'. May be specified multiple times to share albums with more than one user.") parser.add_argument("-o", "--share-role", default="viewer", choices=['viewer', 'editor'], help="The default share role for users newly created albums are shared with. Only effective if --share-with is specified at least once and the share role is not specified within --share-with.") parser.add_argument("-S", "--sync-mode", default=0, type=int, choices=[0, 1, 2], help="Synchronization mode to use. Synchronization mode helps synchronizing changes in external libraries structures to Immich after albums have already been created. Possible Modes: 0 = do nothing; 1 = Delete any empty albums; 2 = Trigger offline asset removal (REQUIRES API KEY OF AN ADMIN USER!)") -parser.add_argument("-O", "--album-order", default=False, type=str, choices=[False, 'asc', 'desc'], help="Set album sorting to newest or oldes file first, immich defaults to newest file first") +parser.add_argument("-O", "--album-order", default=False, type=str, choices=[False, 'asc', 'desc'], help="Set album sorting to newest or oldest file first, immich defaults to newest file first") args = vars(parser.parse_args()) # set up logger to log in logfmt format From ad785ab10565af904f6fc25506f267da0ea3c2bd Mon Sep 17 00:00:00 2001 From: Christian Ferbar <5595808+ferbar@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:20:04 +0200 Subject: [PATCH 4/4] fix order --- immich_auto_album.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/immich_auto_album.py b/immich_auto_album.py index a8ec3ef..a2b2839 100644 --- a/immich_auto_album.py +++ b/immich_auto_album.py @@ -390,7 +390,7 @@ def createAlbum(albumName: str, albumOrder: str) -> str: if albumOrder: data = { - 'order': 'asc', + 'order': albumOrder } r = requests.patch(root_url+apiEndpoint+f'/{albumId}', json=data, **requests_kwargs) assert r.status_code in [200, 201]