Image sets: a suffix that ends the number before is a repeat too
Test and deploy / test (push) Successful in 48s
Test and deploy / edge (push) Successful in 1m53s
Test and deploy / deploy (push) Successful in 1m24s

"051 - White leather kate054001_1_1.jpg": the index is inside 054001
(set 054, image 001) and _1_1 repeats it, but only a suffix equal to the
whole number before counted as a repeat, so the set kept 054001 and every
image was a release (Duke's threads: 2,791 releases of 3,251 files). A
suffix that the number before ends with is a repeat as well. Both
implementations; tests; fixtures identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-12 02:45:29 +02:00
1 parent 392ff09910
commit f094fb4593
3 files changed
+7 -2

No files matched your search

+3 -1
View File
@@ -430,7 +430,8 @@ pub fn image_set(stem: &str) -> String {
let Some(last) = before.iter().rposition(u8::is_ascii_digit) else { break };
let start = before[..=last].iter().rposition(|c| !c.is_ascii_digit()).map_or(0, |i| i + 1);
let previous = &before[start..=last];
let same = trim_zeros(n) == trim_zeros(previous);
// A repeat: the same number, or the end of the one before (054001 ends in 1).
let same = trim_zeros(n) == trim_zeros(previous) || previous.ends_with(n);
let year = n.len() == 4 && (n.starts_with(b"19") || n.starts_with(b"20"));
if same || year || n.len() >= 4 {
let cut = before.len();
@@ -1173,6 +1174,7 @@ mod image_set_tests {
("keira_s04_l keira_s04_0040_l", "keira_s04_l keira_s04_"),
("IMG_2676", "IMG_"),
("2877-041", "2877-"),
("051 - White leather kate054001_1_1", "051 - White leather kate"),
("JimAndJoey Kindly Husband-to-Be", ""),
] {
assert_eq!(image_set(stem), want, "{stem}");
+3 -1
View File
@@ -156,7 +156,9 @@ export function imageSet(stem: string): string {
const previous = /(\d+)\D*$/.exec(before)
if (!previous) break
const n = m[1]
if (Number(n) === Number(previous[1]) || /^(?:19|20)\d\d$/.test(n) || n.length >= 4) s = before
// A repeat: the same number, or the end of the one before ("kate054001_1_1": 054001 ends in 1).
const repeat = Number(n) === Number(previous[1]) || previous[1].endsWith(n)
if (repeat || /^(?:19|20)\d\d$/.test(n) || n.length >= 4) s = before
else break
}
return /\d/.test(s) ? s.replace(/\d+\D*$/, '') : ''
+1
View File
@@ -234,6 +234,7 @@ test.group('release / par2 names', () => {
['keira_s04_l keira_s04_0040_l', 'keira_s04_l keira_s04_'],
['IMG_2676', 'IMG_'],
['2877-041', '2877-'],
['051 - White leather kate054001_1_1', '051 - White leather kate'],
['JimAndJoey Kindly Husband-to-Be', ''],
]) assert.equal(imageSet(stem), set, stem)
})