Skip to content

Commit

Permalink
Merge pull request #98 from Toastie/main
Browse files Browse the repository at this point in the history
Prevent automatic removal of unknown shared users
  • Loading branch information
Salvoxia authored Jan 6, 2025
2 parents 32838d8 + 2c2ef20 commit eefcae8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ This script is mostly based on the following original script: [REDVM/immich_auto
Pass this argument to enable comment and like functionality in all albums this script adds assets to. Cannot be used together with --comments-and-likes-disabled (default: False)
--comments-and-likes-disabled
Pass this argument to disable comment and like functionality in all albums this script adds assets to. Cannot be used together with --comments-and-likes-enabled (default: False)
--update-album-props-mode
Change how album properties are updated whenever new assets are added to an album. Album properties can either come from script arguments or the `.albumprops` file. Possible values:
0 = Do not change album properties.
1 = Only override album properties but do not change the share status.
2 = Override album properties and share status, this will remove all users from the album which are not in the SHARE_WITH list.
```
__Plain example without optional arguments:__
Expand Down Expand Up @@ -174,6 +179,7 @@ The environment variables are analoguous to the script's command line arguments.
| READ_ALBUM_PROPERTIES | no | Set to `True` to enable discovery of `.albumprops` files in root paths, allowing to set different album properties for differnt albums. (default: `False`)<br>Refer to [Setting Album-Fine Properties](#setting-album-fine-properties). |
| API_TIMEOUT | no | Timeout when requesting Immich API in seconds (default: `20`) |
| COMMENTS_AND_LIKES | no | Set to `1` to explicitly enable Comments & Likes functionality for all albums this script adds assets to, set to `0` to disable. If not set, this setting is left alone by the script. |
| UPDATE_ALBUM_PROPS_MODE | no | Change how album properties are updated whenever new assets are added to an album. Album properties can either come from script arguments or the `.albumprops` file. Possible values: <br>`0` = Do not change album properties.<br> `1` = Only override album properties but do not change the share status.<br> `2` = Override album properties and share status, this will remove all users from the album which are not in the SHARE_WITH list. |
#### Run the container with Docker
Expand Down Expand Up @@ -446,6 +452,7 @@ To share new albums with users `User A` and a user with mail address `userB@mydo
python3 ./immich_auto_album.py --share-with "User A=editor" --share-with "[email protected]" /path/to/external/lib https://immich.mydomain.com/api thisIs
```
Per default these share settings are applied once when the album is created and remain unchanged if an asset is added to an album later. If you want to override the share state whenever an asset is added to an album you can set `--update-album-props-mode` to `2`. Note that this will completely override all shared users, any changes made within Immich will be lost.
### Album Sharing Examples (Docker)
Two environment variables control this feature:
Expand All @@ -467,6 +474,8 @@ To share new albums with users `User A` and a user with mail address `userB@mydo
docker run -e SHARE_WITH="User A=editor:[email protected]" -e UNATTENDED="1" -e API_URL="https://immich.mydomain.com/api/" -e API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -e ROOT_PATH="/external_libs/photos" salvoxia/immich-folder-album-creator:latest /script/immich_auto_album.sh
```
Per default these share settings are applied once when the album is created and remain unchanged if an asset is added to an album later. If you want to override the share state whenever an asset is added to an album you can set `UPDATE_ALBUM_PROPS_MODE` to `2`. Note that this will completely override all shared users, any changes made within Immich will be lost.
## Cleaning Up Albums
Expand Down
4 changes: 4 additions & 0 deletions docker/immich_auto_album.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,9 @@ elif [ "$COMMENTS_AND_LIKES" == "0" ]; then
args="--comments-and-likes-disabled $args"
fi

if [ ! -z "$UPDATE_ALBUM_PROPS_MODE" ]; then
args="--update-album-props-mode $UPDATE_ALBUM_PROPS_MODE $args"
fi

BASEDIR=$(dirname "$0")
echo $args | xargs python3 -u $BASEDIR/immich_auto_album.py
27 changes: 19 additions & 8 deletions immich_auto_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,11 @@ def find_user_by_name_or_email(name_or_email: str, user_list: list[dict]) -> dic
help="Pass this argument to enable comment and like functionality in all albums this script adds assets to. Cannot be used together with --comments-and-likes-disabled")
parser.add_argument("--comments-and-likes-disabled", action="store_true",
help="Pass this argument to disable comment and like functionality in all albums this script adds assets to. Cannot be used together with --comments-and-likes-enabled")
parser.add_argument("--update-album-props-mode", type=int, choices=[0, 1, 2], default=0,
help="""Change how album properties are updated whenever new assets are added to an album. Album properties can either come from script arguments or the .albumprops file. Possible values:
0 = Do not change album properties.
1 = Only override album properties but do not change the share status.
2 = Override album properties and share status, this will remove all users from the album which are not in the SHARE_WITH list.""")


args = vars(parser.parse_args())
Expand Down Expand Up @@ -1735,6 +1740,7 @@ def find_user_by_name_or_email(name_or_email: str, user_list: list[dict]) -> dic
if comments_and_likes_disabled and comments_and_likes_enabled:
logging.fatal("Arguments --comments-and-likes-enabled and --comments-and-likes-disabled cannot be used together! Choose one!")
sys.exit(1)
update_album_props_mode = args["update_album_props_mode"]

# Override unattended if we're running in destructive mode
if mode != SCRIPT_MODE_CREATE:
Expand Down Expand Up @@ -1770,6 +1776,7 @@ def find_user_by_name_or_email(name_or_email: str, user_list: list[dict]) -> dic
logging.debug("api_timeout = %s", api_timeout)
logging.debug("comments_and_likes_enabled = %s", comments_and_likes_enabled)
logging.debug("comments_and_likes_disabled = %s", comments_and_likes_disabled)
logging.debug("update_album_props_mode = %d", update_album_props_mode)

# Verify album levels
if is_integer(album_levels) and album_levels == 0:
Expand Down Expand Up @@ -1938,14 +1945,18 @@ def find_user_by_name_or_email(name_or_email: str, user_list: list[dict]) -> dic
asset_uuids_added += assets_added
logging.info("%d new assets added to %s", len(assets_added), album.get_final_name())

# Set album properties
try:
update_album_properties(album)
except HTTPError as e:
logging.error('Error updating properties for album %s: %s', album.get_final_name(), e)

# Handle album sharing
update_album_shared_state(album, True)
# Update album properties depending on mode or if newly created
if update_album_props_mode > 0 or (album in created_albums):
# Update album properties
try:
update_album_properties(album)
except HTTPError as e:
logging.error('Error updating properties for album %s: %s', album.get_final_name(), e)

# Update album sharing if needed or newly created
if update_album_props_mode == 2 or (album in created_albums):
# Handle album sharing
update_album_shared_state(album, True)

logging.info("%d albums created", len(created_albums))

Expand Down

0 comments on commit eefcae8

Please sign in to comment.