Skip to content

Commit

Permalink
Merge pull request #37 from ferbar/dev
Browse files Browse the repository at this point in the history
Feature: add order asc option
  • Loading branch information
Salvoxia authored Aug 21, 2024
2 parents 861dddf + ad785ab commit 44b5ff1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions immich_auto_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def is_integer(str):
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 <userName>=<shareRole> must be used, where <shareRole> 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 oldest file first, immich defaults to newest file first")

args = vars(parser.parse_args())
# set up logger to log in logfmt format
Expand All @@ -68,6 +69,7 @@ def is_integer(str):
# 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"]
Expand All @@ -91,6 +93,7 @@ def is_integer(str):
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)
Expand Down Expand Up @@ -353,7 +356,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
Expand All @@ -362,6 +365,8 @@ def createAlbum(albumName: str) -> str:
----------
albumName : str
Name of the album to create
albumOrder : str
False or order [asc|desc]
Returns
---------
Expand All @@ -380,7 +385,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': albumOrder
}
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]):
Expand Down Expand Up @@ -640,7 +654,7 @@ def triggerOfflineAssetRemoval(libraryId: str):
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)
Expand Down

0 comments on commit 44b5ff1

Please sign in to comment.