stash
stash copied to clipboard
[Feature] Rename files to match titles or some pattern
I'd love it if we were able to collectively rename all our files from within Stash to the respective Scene/Image/Gallery/etc title or to some pattern.
By pattern, what I mean is you could set the new filename to [{studio}] {cast:,} - {title} ({date})
. {cast:,}
is a rough example of how it could handle anything with multiple performers. You'd have cast
to obviously denote the cast, but then the ,
would denote a delimiter when there was more than one.
The date
field should also have options so you could set your format with the default being ISO8601, so if you were a silly American, you could use {date:MM/DD/YYYY}
for example.
Example:
Title: Too Hot
Date: 2013-11-20
Studio: Twistys
Performers: [Malena Morgan]
Pattern: [{studio}] {cast:,} - {title} ({date})
Output: [Twistys] Malena Morgan - Too Hot (2013-11-20)
Now obviously this can be done from outside of Stash but it's best done from within so all the database entries can be updated to match.
This is an excellent idea.
I would find it useful if it could also implement regex to match parts of the original filename and add them to the output of the revised filename.
Here's a working example of this in action in Go: https://play.golang.org/p/rdMM8vHKWou
The template string here is:
[{{.Studio}}] {{.FormatCast}} - {{.Title}} ({{.Date.Format "2006-01-02"}}).{{.Ext}}
Update: I think I prefer this better: https://play.golang.org/p/T1sO5Q8Zi-c
Pattern becomes:
[{{studio}}] {{cast "," "&"}} - {{title}} ({{date}}).{{ext}}
The code is a bit more complicated but it's much easier for users to understand.
Investigating for possible bounty.
Single brace notation seems like the way to go for me, to be consistent with the scene filename parser.
To reduce complexity and scope for the initial version, I think we should support in-place renaming only - not moving files between directories.
This functionality should be embedded in a new page, accessed from the Tools
settings menu.
The new page would provide a query filter to filter scenes, and a text field for the pattern. Patterns should be able to be saved - this can be added to the config file. The user can type in a pattern, with a dropdown list of fields that can be added (similar to the scene filename parser), or select from a saved pattern.
The page should show the existing filenames and a preview of the new filenames.
The page should provide checkboxes to allow renaming of specific files. A first-row checkbox will allow selecting all scenes on the page. There should also be a button to apply renaming to all files matching the query filter.
We may need to consider performing the renaming operation in a task, rather than an immediate method.
Suggest the following new graphql interfaces:
type RenameScenePreview {
scene: Scene!
newFilename: String!
}
input PreviewRenameScenesInput {
pattern: String!
scene_filter: SceneFilterType
filter: FindFilterType
}
query previewRenameScenes(input: PreviewRenameScenesInput!): [RenameScenePreview !]
input RenameScenesInput {
pattern: String!
scene_ids: [ID!]
scene_filter: SceneFilterType
filter: FindFilterType
}
"""Returns job ID"""
mutation renameScenes(input: RenameScenesInput!): String!
That all seems great to me, however I'm not sure about the following:
Single brace notation seems like the way to go for me, to be consistent with the scene filename parser.
The code I wrote works for double braces as that's what the text/template
module expects. To get single braces to work, you'd need to either find a completely different solution, or add in additional braces.
@WithoutPants Any further interest in this feature?
@WithoutPants Any further interest in this feature?
There is, but not sure when I'll get to it.
Most rename functionality mentioned in the issue is covered by renamer and renamerOnUpdate plugins from here https://github.com/stashapp/CommunityScripts/tree/main/plugins
Isn't this exactly what the renamerOnUpdate plugin does? And they've recently added a button so that you can run it on all your scenes with the provided template.
Most rename functionality mentioned in the issue is covered by renamer and renamerOnUpdate plugins from here https://github.com/stashapp/CommunityScripts/tree/main/plugins
The renamer script was deprecated recently.
Closing this as https://github.com/stashapp/CommunityScripts/tree/main/plugins/renamerOnUpdate ( mentioned above ) seems to cover everything mentioned.