Skip to content

Commit d225b47

Browse files
authored
Merge pull request #121 from DSchmidtDev/fix/enhance_regex_post_processing
Fix: enhance regex album name post processing
2 parents 3f40834 + d2c4b39 commit d225b47

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.idea
2+
.vscode/*

docker/immich_auto_album.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fi
4646

4747
## parse ABLUM_NAME_POST_REGEX<n>
4848
# Split on newline only
49-
IFS=$(echo -en "\n\b")´
49+
IFS=$(echo -en "\n\b")
5050
album_name_post_regex_list=""
5151
# Support up to 10 regex patterns
5252
regex_max=10
@@ -58,7 +58,7 @@ do
5858
pattern=$(echo "^ALBUM_NAME_POST_REGEX${regex_no}+=.+")
5959
TEST=$(echo "${entry}" | grep -E "$pattern")
6060
if [ ! -z "${TEST}" ]; then
61-
value=$(echo ${entry} | cut -d'=' -f2)
61+
value="${entry#*=}" # select everything after the first `=`
6262
album_name_post_regex_list="$album_name_post_regex_list --album-name-post-regex $value"
6363
fi
6464
done

immich_auto_album.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
import os
1010
import datetime
1111
from collections import defaultdict, OrderedDict
12-
import re
1312
import random
1413
from urllib.error import HTTPError
14+
15+
import regex
1516
import yaml
1617

1718
import urllib3
@@ -460,7 +461,7 @@ def is_integer(string_to_test: str) -> bool:
460461
('\\]', ']'),
461462
))
462463

463-
escaped_glob_replacement = re.compile('(%s)' % '|'.join(escaped_glob_tokens_to_re).replace('\\', '\\\\\\'))
464+
escaped_glob_replacement = regex.compile('(%s)' % '|'.join(escaped_glob_tokens_to_re).replace('\\', '\\\\\\'))
464465

465466
def glob_to_re(pattern: str) -> str:
466467
"""
@@ -475,7 +476,7 @@ def glob_to_re(pattern: str) -> str:
475476
---------
476477
A regular expression matching the same strings as the provided GLOB pattern
477478
"""
478-
return escaped_glob_replacement.sub(lambda match: escaped_glob_tokens_to_re[match.group(0)], re.escape(pattern))
479+
return escaped_glob_replacement.sub(lambda match: escaped_glob_tokens_to_re[match.group(0)], regex.escape(pattern))
479480

480481
def read_file(file_path: str) -> str:
481482
"""
@@ -662,7 +663,7 @@ def create_album_name(asset_path_chunks: list[str], album_separator: str, album_
662663
for pattern, *repl in album_name_postprocess_regex:
663664
# If no replacement string provided, default to empty string
664665
replace = repl[0] if repl else ''
665-
album_name = re.sub(pattern, replace, album_name)
666+
album_name = regex.sub(pattern, replace, album_name)
666667
logging.debug("Album Post Regex s/%s/%s/g --> %s", pattern, replace, album_name)
667668

668669
return album_name.strip()
@@ -874,15 +875,15 @@ def is_path_ignored(path_to_check: str) -> bool:
874875
if len(path_filter_regex) > 0:
875876
any_match = False
876877
for path_filter_regex_entry in path_filter_regex:
877-
if re.fullmatch(path_filter_regex_entry, path_to_check.replace(asset_root_path, '')):
878+
if regex.fullmatch(path_filter_regex_entry, path_to_check.replace(asset_root_path, '')):
878879
any_match = True
879880
if not any_match:
880881
logging.debug("Ignoring path %s due to path_filter setting!", path_to_check)
881882
is_path_ignored_result = True
882883
# If the asset "survived" the path filter, check if it is in the ignore_albums argument
883884
if not is_path_ignored_result and len(ignore_albums_regex) > 0:
884885
for ignore_albums_regex_entry in ignore_albums_regex:
885-
if re.fullmatch(ignore_albums_regex_entry, path_to_check.replace(asset_root_path, '')):
886+
if regex.fullmatch(ignore_albums_regex_entry, path_to_check.replace(asset_root_path, '')):
886887
is_path_ignored_result = True
887888
logging.debug("Ignoring path %s due to ignore_albums setting!", path_to_check)
888889
break

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
requests
22
urllib3
3-
pyyaml
3+
pyyaml
4+
regex==2024.11.6

0 commit comments

Comments
 (0)