From 24feb8d2c8c6d3d619612ed63f6ddca50ebc346c Mon Sep 17 00:00:00 2001 From: Salvoxia Date: Thu, 11 Apr 2024 22:26:23 +0200 Subject: [PATCH] Added support for accepting negative album_levels, creating album names from the deepest folders in the tree instead of the highest --- immich_auto_album.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/immich_auto_album.py b/immich_auto_album.py index fd206f9..d6474b6 100644 --- a/immich_auto_album.py +++ b/immich_auto_album.py @@ -41,7 +41,7 @@ logging.debug("album_levels = %d", album_levels) logging.debug("album_level_separator = %s", album_level_separator) # Verify album levels -if album_levels < 1: +if album_levels == 0: parser.print_help() exit(1) @@ -105,12 +105,21 @@ for asset in assets: # A single chunk means it's just the image file in no sub folder, ignore if len(path_chunks) == 1: continue + + # remove last item from path chunks, which is the file name + del path_chunks[-1] album_name_chunks = () - # either use as many path chunks as we have (excluding the asset name itself), + # either use as many path chunks as we have, # or the specified album levels - album_name_chunk_size = min(len(path_chunks)-1, album_levels) + album_name_chunk_size = min(len(path_chunks), album_levels) + if album_levels < 0: + album_name_chunk_size = min(len(path_chunks), abs(album_levels))*-1 + # Copy album name chunks from the path to use as album name album_name_chunks = path_chunks[:album_name_chunk_size] + if album_name_chunk_size < 0: + album_name_chunks = path_chunks[album_name_chunk_size:] + album_name = album_level_separator.join(album_name_chunks) # Check that the extracted album name is not actually a file name in root_path album_to_assets[album_name].append(asset['id'])