Image sets: a counter in the name ends the set; copy markers, resolutions, _00 go
Test and deploy / test (push) Successful in 50s
Test and deploy / edge (push) Successful in 1m59s
Test and deploy / deploy (push) Successful in 2m59s

Each image was a release of its own in: "Set 008  10of63  new0464.jpg",
"202/430  princess-079-058.jpg", "( 098 /500)  002 148.jpg" (the counter
is part of the name: the set is the text before it),
"sexypattycake_0903040445[1].jpg" (a copy's marker), "092_081_2000x1500.jpg"
(a resolution) and "KP0027_197_00.jpg" (a constant suffix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-12 04:45:37 +02:00
1 parent e72a9b1ef5
commit 108d798d97
3 files changed
+35 -4

No files matched your search

+19 -2
View File
@@ -417,7 +417,15 @@ static DOCUMENT: LazyLock<Regex> = LazyLock::new(|| re(r"(?i)\.(pdf|epub|mobi|az
/// imageSet (lib/release/identity.ts): the name up to the number that counts the images, digits kept.
pub fn image_set(stem: &str) -> String {
// .replace(/(\d+)\s*of\s*\d+/gi, '$1')
let mut s = OF_TOTAL.replace_all(stem.as_bytes(), &b"$1"[..]).into_owned();
// Suffixes that number no image: a copy's ("…[1]"), a resolution ("…_2000x1500"), a constant one ("…_00").
let mut s = stem.as_bytes().to_vec();
for re in [&*COPY_MARK, &*RESOLUTION, &*ZERO_SUFFIX] {
s = re.replace(&s, &b""[..]).into_owned();
}
// A counter in the name counts the images: the set is the text before it ("Set 008 10of63 new0464").
if let Some(m) = NAME_COUNTER.find(&s) {
return String::from_utf8_lossy(&s[..m.start()]).into_owned();
}
// A camera's timestamp ("kurozo-2006-7-26-15-21"): the date and the time after it number no set.
let s_ts = TIMESTAMP.replace(&s, &b""[..]).into_owned();
s = s_ts;
@@ -461,7 +469,10 @@ fn trim_zeros(d: &[u8]) -> &[u8] {
}
static TIMESTAMP: LazyLock<Regex> = LazyLock::new(|| re(r"[-_. ]?(?:19|20)[0-9]{2}[-._ ](?:0?[1-9]|1[0-2])[-._ ][0-9]{1,2}(?:[-._ ][0-9]{1,2})*$"));
static OF_TOTAL: LazyLock<Regex> = LazyLock::new(|| re(r"(?i)([0-9]+)SP*ofSP*[0-9]+"));
static COPY_MARK: LazyLock<Regex> = LazyLock::new(|| re(r"SP*[\[(][0-9]+[\])]$"));
static RESOLUTION: LazyLock<Regex> = LazyLock::new(|| re(r"(?i)[_-][0-9]{3,4}x[0-9]{3,4}$"));
static ZERO_SUFFIX: LazyLock<Regex> = LazyLock::new(|| re(r"[_-]0+$"));
static NAME_COUNTER: LazyLock<Regex> = LazyLock::new(|| re(r"(?i)([0-9]+)SP*ofSP*[0-9]+|[\[(]?SP*[0-9]+SP*/SP*[0-9]+SP*[\])]?"));
fn image_prefix(stem: &str) -> String {
let b = stem.as_bytes();
@@ -1187,6 +1198,12 @@ mod image_set_tests {
("108 - Schoolwall kate108lg029_28", "108 - Schoolwall kate108lg"),
("kurozo-2006-7-26-15-21", ""),
("bwp2_037_5", "bwp2_"),
("Set 008 10of63 new0464", "Set 008 "),
("202/430 princess-079-058", ""),
("( 098 /500) 002 148", ""),
("New Folder (17) sexypattycake_0903040445[1]", "New Folder ("),
("092_081_2000x1500", "092_"),
("KP0027_197_00", "KP"),
("JimAndJoey Kindly Husband-to-Be", ""),
] {
assert_eq!(image_set(stem), want, "{stem}");