Stacks: Configure regex option for StripSequence #1510

Open
opened 2026-02-20 00:14:00 -05:00 by deekerman · 1 comment
Owner

Originally created by @koutloup on GitHub (Jul 30, 2022).

I edited my photos with various tools over the years, many of them resulting in different suffixes on export. That means i have files like:

IMG_1234
IMG_1234-1
IMG_1234-2

or

IMG_1234
IMG_1234.1
IMG_1234.2

or

IMG_1234
IMG_1234_1
IMG_1234_2

or

IMG_1234.original
IMG_1234.export

or

IMG_1234
IMG_1234.copy
IMG_1234.copy 2

that i would like to have stacked, but don't get stacked.

The current implementation only strips:

  • numeric extensions like .00000, .00001, .4542353245,.... (at least 5 digits).
  • Copies created by Chrome & Windows, example: IMG_1234 (2)
  • Copies created by OS X, example: IMG_1234 copy 2.

The problem here is that there are many different ways to name your edited/exported files and trying to strip all possible sequences would result in unwanted stacks for many users.

One solution without changing the current stacking behavior, could be an config option to provide a regex for what gets stripped from the filename.

Current implementation looks like:

func StripSequence(name string) string {
	// Strip numeric extensions like .00000, .00001, .4542353245,.... (at least 5 digits).
	if dot := strings.LastIndex(name, "."); dot != -1 && len(name[dot+1:]) >= 5 {
		if i, err := strconv.Atoi(name[dot+1:]); err == nil && i >= 0 {
			name = name[:dot]
		}
	}

	// Other common sequential naming schemes.
	if end := strings.Index(name, "("); end != -1 {
		// Copies created by Chrome & Windows, example: IMG_1234 (2).
		name = name[:end]
	} else if end := strings.Index(name, " copy"); end != -1 {
		// Copies created by OS X, example: IMG_1234 copy 2.
		name = name[:end]
	}

	name = strings.TrimSpace(name)

	return name
}

Changing it to

func StripSequence(name string, exp *regexp.Regexp) string {
	idx := exp.FindStringIndex(name)
	if idx == nil {
		return name
	}
	return name[0:idx[0]]
}

and providing \.\d{5,}$| copy \d$| \(\d*\)$ as exp would result it the same behavior.

Summary

I would like to add/implement a PHOTOPRISM_STRIPSEQUENCE_REGEX config option that defaults to the current StripSequence implementation and use it in the StripSequence function, so users can provide there own regular expression and get images stacked that wouldn't get stacked with the current implementation.

somehow related to: #2241 #1122

Originally created by @koutloup on GitHub (Jul 30, 2022). I edited my photos with various tools over the years, many of them resulting in different suffixes on export. That means i have files like: IMG_1234 IMG_1234-1 IMG_1234-2 or IMG_1234 IMG_1234.1 IMG_1234.2 or IMG_1234 IMG_1234_1 IMG_1234_2 or IMG_1234.original IMG_1234.export or IMG_1234 IMG_1234.copy IMG_1234.copy 2 that i would like to have stacked, but don't get stacked. The current implementation only strips: - numeric extensions like .00000, .00001, .4542353245,.... (at least 5 digits). - Copies created by Chrome & Windows, example: IMG_1234 (2) - Copies created by OS X, example: IMG_1234 copy 2. The problem here is that there are many different ways to name your edited/exported files and trying to strip all possible sequences would result in unwanted stacks for many users. One solution without changing the current stacking behavior, could be an config option to provide a regex for what gets stripped from the filename. Current implementation looks like: ``` func StripSequence(name string) string { // Strip numeric extensions like .00000, .00001, .4542353245,.... (at least 5 digits). if dot := strings.LastIndex(name, "."); dot != -1 && len(name[dot+1:]) >= 5 { if i, err := strconv.Atoi(name[dot+1:]); err == nil && i >= 0 { name = name[:dot] } } // Other common sequential naming schemes. if end := strings.Index(name, "("); end != -1 { // Copies created by Chrome & Windows, example: IMG_1234 (2). name = name[:end] } else if end := strings.Index(name, " copy"); end != -1 { // Copies created by OS X, example: IMG_1234 copy 2. name = name[:end] } name = strings.TrimSpace(name) return name } ``` Changing it to ``` func StripSequence(name string, exp *regexp.Regexp) string { idx := exp.FindStringIndex(name) if idx == nil { return name } return name[0:idx[0]] } ``` and providing `\.\d{5,}$| copy \d$| \(\d*\)$` as exp would result it the same behavior. Summary I would like to add/implement a PHOTOPRISM_STRIPSEQUENCE_REGEX config option that defaults to the current StripSequence implementation and use it in the StripSequence function, so users can provide there own regular expression and get images stacked that wouldn't get stacked with the current implementation. somehow related to: #2241 #1122
Author
Owner

@TenviLi commented on GitHub (Aug 7, 2022):

Wow, i also need this feature! 😆

For example, i have a directory structure like this:

  • filename_p1
  • filename_p2
  • filename_p3

Photoprism recently don't provide a feature like 'custom glob or regex patterns for StripSequence', so i cannot modify the behaviour of 'stacks automaticly recognition'.

If this feature supported, I don't need to rename the existing image files in batches by myself. It can save a lot of mechanical and repetitive work.

Just add a pattern configiration: **/*/*_p[0-9]*

(PS: I think the design of the album management tool should avoid changing the original directory structure as much as possible.)

Summary

I would like to add/implement a panel for 'custom glob or regex patterns for StripSequence' in settings UI.

Guys, what do you think?

@TenviLi commented on GitHub (Aug 7, 2022): Wow, i also need this feature! 😆 For example, i have a directory structure like this: - filename_p1 - filename_p2 - filename_p3 Photoprism recently don't provide a feature like '**custom glob or regex patterns for StripSequence**', so i cannot modify the behaviour of 'stacks automaticly recognition'. If this feature supported, I don't need to rename the existing image files in batches by myself. It can save a lot of mechanical and repetitive work. Just add a pattern configiration: `**/*/*_p[0-9]*` (PS: I think the design of the album management tool should **avoid** changing the original directory structure as much as possible.) #### Summary I would like to add/implement a panel for '**custom glob or regex **patterns** for StripSequence**' in settings UI. Guys, what do you think?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/photoprism#1510
No description provided.