Make the naming scheme fully user-editable, with the user's preferred format as default

- ExpressionFormat::compile_scriptlet now falls back to treating a {token} as a
  literal multi-word binding key when it's neither a valid Rhai identifier nor
  valid Rhai script, but still looks like a plain human-typed field name (only
  letters/digits/underscores/spaces). This is what lets `{show name}` work
  without anyone needing to know Rhai, while real Rhai script (even containing
  spaces) still takes priority and genuine syntax errors still surface.
- New default naming scheme app-wide: `{show name} - {season number}x
  {episode number} - {episode name}` (previously the terser {n} - {s00e00} -
  {t} form). Match/Fetch Data auto-upgrade targets updated to match, and
  sample items carry both the short FileBot-style keys and the new
  human-readable ones side by side.
- Naming scheme editor UI rewritten: explains the field is fully editable,
  lists available fields grouped by when they become available (always /
  after Match / after Fetch Data), and clarifies Rhai script is also
  supported for anyone who wants it.
- 3 new unit tests for the plain-field-name fallback (multi-word lookup
  works, real Rhai still takes priority, genuine syntax errors still error).
This commit is contained in:
Renamr Scaffold
2026-08-29 03:15:21 +00:00
parent d1fc4039a7
commit f89589bc88
7 changed files with 240 additions and 22 deletions
+30
View File
@@ -13,6 +13,15 @@ plan before anything touches disk — there is no undo yet). Full media-metadata
bindings and the fuzzy similarity/matching engine are not yet ported. See "Porting
roadmap" below.
The naming scheme is fully user-editable from the app (the "Naming Scheme" button next
to the New Names list) — the default is `{show name} - {season number}x{episode
number} - {episode name}`, but it's just a starting point, not a fixed template.
Plain, human-readable, multi-word field names like `{show name}` work directly (no
Rhai knowledge needed), FileBot's own short field names (`{n}`, `{s00e00}`, `{t}`)
still work side by side with them, and real Rhai script is available for anyone who
wants it (e.g. `{show name.to_upper()}`). See "Naming scheme syntax" below for how
that's implemented.
## Why a rewrite, and why this stack
The original is a ~20k+ line Java/Swing app built with Ant. The goals were: faster
@@ -47,6 +56,27 @@ identical. More complex chained-method expressions will need small syntax tweaks
common string/array methods FileBot's expression helpers wrapped, so most patterns
translate directly.
### Naming scheme syntax
Every `{ }` token in an expression is resolved in this order
(`crates/renamr-core/src/format/expression.rs::compile_scriptlet`):
1. **A single bare identifier** (`{n}`, `{season}`) is a direct binding lookup — the
fast path, and how FileBot's own short field names keep working unmodified.
2. Otherwise it's **compiled as Rhai script** (`{n.to_upper()}`, `{n + " " + t}`) —
real code, with every current binding available as a script variable.
3. If it's *neither* a valid identifier *nor* valid Rhai, but it still only contains
letters, digits, underscores and spaces (e.g. `{show name}`, `{episode number}`),
it falls back to a **literal multi-word binding key** instead of raising a syntax
error — this is what lets a human-typed field name with spaces work as a plain
lookup without anyone needing to know Rhai. Anything that isn't a plausible field
name (stray punctuation, unmatched brackets, etc.) still surfaces as a real syntax
error at that point, exactly as before.
An undefined binding contributes an empty string rather than failing outright (so
`{n}{missing}` still renders); the overall expression only errors if the *total*
rendered output would be empty.
## Project layout
```