Skip to content

Commit

Permalink
Added support for accepting negative album_levels, creating album nam…
Browse files Browse the repository at this point in the history
…es from the deepest folders in the tree instead of the highest
  • Loading branch information
Salvoxia committed Apr 11, 2024
1 parent 835f347 commit 24feb8d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions immich_auto_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
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)

Expand Down Expand Up @@ -105,12 +105,21 @@ def divide_chunks(l, n):
# 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'])
Expand Down

0 comments on commit 24feb8d

Please sign in to comment.