Files
aurora-curator/src-tauri/src/lib.rs
T

97 lines
4.1 KiB
Rust
Raw Normal View History

mod files;
2026-08-29 03:44:38 +00:00
mod history;
mod metadata;
mod settings;
use renamr_core::format::ExpressionFormat;
use renamr_core::matching::{self, EpisodeGuess, MovieGuess, ReleaseInfo};
use renamr_core::rename::{self, RenameAction, RenamePlanItem, RenameResult};
use renamr_core::string_bindings;
use std::collections::HashMap;
2026-08-29 03:44:38 +00:00
use tauri::AppHandle;
/// 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())
}
/// 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)
}
/// 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)
}
/// Guesses release-tag metadata (resolution, source, video/audio codec, release
/// group) from a filename's own text using local regex patterns only - no network
/// calls, no real media probing (Renamr never ships an ffprobe/MediaInfo dependency,
/// so filename tags are the only source for these fields). Independent of
/// `guess_episode`/`guess_movie`: called alongside whichever of those two applies,
/// since a release name carries (or doesn't carry) these tags regardless of whether
/// it's an episode or a movie.
#[tauri::command]
fn guess_release_info(filename: String) -> Option<ReleaseInfo> {
matching::guess_release_info(&filename)
}
/// Executes a batch of planned on-disk rename/copy/symlink operations (optionally
/// moving/copying files into subfolders - see `renamr_core::rename`; conflicting
/// targets are always skipped, never overwritten). `action` picks which of the three
/// happens - the UI is expected to have already shown the user the full old-path/
/// new-path plan, the chosen action, and gotten explicit confirmation before calling
/// this. 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-produced item is recorded to the rename history log afterward
/// (see `history::record_batch`), tagged with `action`, so it can be undone later from
/// the History panel - a Move undo moves the file back, a Copy/Symlink undo just
/// removes what was created.
#[tauri::command]
async fn execute_rename(app: AppHandle, items: Vec<RenamePlanItem>, action: RenameAction) -> Vec<RenameResult> {
let results = tauri::async_runtime::spawn_blocking(move || rename::execute_renames(&items, action))
.await
2026-08-29 03:44:38 +00:00
.unwrap_or_default();
history::record_batch(&app, &results, action);
2026-08-29 03:44:38 +00:00
results
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.invoke_handler(tauri::generate_handler![
render_expression,
guess_episode,
guess_movie,
guess_release_info,
execute_rename,
metadata::fetch_metadata,
metadata::fetch_movie_metadata,
settings::get_tmdb_token,
settings::save_tmdb_token,
2026-08-29 03:44:38 +00:00
history::list_rename_history,
history::undo_rename_batch,
files::pick_files,
files::pick_folder,
files::expand_dropped_paths,
])
.run(tauri::generate_context!())
.expect("error while running Renamr");
}