2026-08-29 02:06:14 +00:00
|
|
|
mod files;
|
2026-08-29 03:44:38 +00:00
|
|
|
mod history;
|
2026-08-29 03:01:19 +00:00
|
|
|
mod metadata;
|
|
|
|
|
mod settings;
|
2026-08-29 02:06:14 +00:00
|
|
|
|
2026-08-29 01:43:12 +00:00
|
|
|
use renamr_core::format::ExpressionFormat;
|
2026-08-29 04:04:16 +00:00
|
|
|
use renamr_core::matching::{self, EpisodeGuess, MovieGuess};
|
2026-08-29 02:42:31 +00:00
|
|
|
use renamr_core::rename::{self, RenamePlanItem, RenameResult};
|
2026-08-29 01:43:12 +00:00
|
|
|
use renamr_core::string_bindings;
|
|
|
|
|
use std::collections::HashMap;
|
2026-08-29 03:44:38 +00:00
|
|
|
use tauri::AppHandle;
|
2026-08-29 01:43:12 +00:00
|
|
|
|
|
|
|
|
/// Renders a naming-scheme expression against a set of binding values.
|
|
|
|
|
/// This is the Tauri-facing entry point into the core format engine, used by the
|
|
|
|
|
/// rename-preview panel in the UI so users see live results as they edit a pattern.
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn render_expression(expression: String, bindings: HashMap<String, String>) -> Result<String, String> {
|
|
|
|
|
let compiled = ExpressionFormat::compile(&expression).map_err(|e| e.to_string())?;
|
|
|
|
|
compiled
|
|
|
|
|
.format(&string_bindings(bindings))
|
|
|
|
|
.map_err(|e| e.to_string())
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 02:42:31 +00:00
|
|
|
/// Guesses a season/episode number pair (and series name) from a filename using local
|
|
|
|
|
/// regex patterns only - no network calls, no metadata lookup. Returns `None` when the
|
|
|
|
|
/// filename doesn't carry a recognizable season/episode marker (movies, already-clean
|
|
|
|
|
/// names, etc).
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn guess_episode(filename: String) -> Option<EpisodeGuess> {
|
|
|
|
|
matching::guess_episode(&filename)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 04:04:16 +00:00
|
|
|
/// Guesses a movie title (and release year, if present) from a filename using local
|
|
|
|
|
/// regex/heuristic patterns only - no network calls. Callers should try
|
|
|
|
|
/// `guess_episode` first and only fall back to this when it returns `None`; see
|
|
|
|
|
/// `matching::guess_movie` for why.
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
fn guess_movie(filename: String) -> Option<MovieGuess> {
|
|
|
|
|
matching::guess_movie(&filename)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 03:44:38 +00:00
|
|
|
/// Executes a batch of planned on-disk renames (optionally moving files into
|
|
|
|
|
/// subfolders - see `renamr_core::rename`; conflicting targets are always skipped,
|
|
|
|
|
/// never overwritten). The UI is expected to have already shown the user the full
|
|
|
|
|
/// old-path/new-path plan and gotten explicit confirmation before calling this.
|
2026-08-29 02:42:31 +00:00
|
|
|
/// Runs off the main thread since real filesystem I/O shouldn't block the UI.
|
2026-08-29 03:44:38 +00:00
|
|
|
///
|
|
|
|
|
/// Every successfully-renamed item is recorded to the rename history log afterward
|
|
|
|
|
/// (see `history::record_batch`) so it can be undone later from the History panel.
|
2026-08-29 02:42:31 +00:00
|
|
|
#[tauri::command]
|
2026-08-29 03:44:38 +00:00
|
|
|
async fn execute_rename(app: AppHandle, items: Vec<RenamePlanItem>) -> Vec<RenameResult> {
|
|
|
|
|
let results = tauri::async_runtime::spawn_blocking(move || rename::execute_renames(&items))
|
2026-08-29 02:42:31 +00:00
|
|
|
.await
|
2026-08-29 03:44:38 +00:00
|
|
|
.unwrap_or_default();
|
|
|
|
|
history::record_batch(&app, &results);
|
|
|
|
|
results
|
2026-08-29 02:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-29 01:43:12 +00:00
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
|
|
|
pub fn run() {
|
|
|
|
|
tauri::Builder::default()
|
2026-08-29 02:06:14 +00:00
|
|
|
.plugin(tauri_plugin_dialog::init())
|
|
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
render_expression,
|
2026-08-29 02:42:31 +00:00
|
|
|
guess_episode,
|
2026-08-29 04:04:16 +00:00
|
|
|
guess_movie,
|
2026-08-29 02:42:31 +00:00
|
|
|
execute_rename,
|
2026-08-29 03:01:19 +00:00
|
|
|
metadata::fetch_metadata,
|
2026-08-29 04:04:16 +00:00
|
|
|
metadata::fetch_movie_metadata,
|
2026-08-29 03:01:19 +00:00
|
|
|
settings::get_tmdb_token,
|
|
|
|
|
settings::save_tmdb_token,
|
2026-08-29 03:44:38 +00:00
|
|
|
history::list_rename_history,
|
|
|
|
|
history::undo_rename_batch,
|
2026-08-29 02:06:14 +00:00
|
|
|
files::pick_files,
|
|
|
|
|
files::pick_folder,
|
|
|
|
|
files::expand_dropped_paths,
|
|
|
|
|
])
|
2026-08-29 01:43:12 +00:00
|
|
|
.run(tauri::generate_context!())
|
|
|
|
|
.expect("error while running Renamr");
|
|
|
|
|
}
|