Jarian Cottingham 6dd4e83ddf feat: Add Rust implementation for performance-critical components
- Implement core Rust backend with FFmpeg integration
- Add TheTVDB API client with token caching
- Implement directory scanner with progress callbacks
- Create file manager with rename and move operations
- Add audit logging functionality
- Implement file mapping for TV episode renaming
- Build Node.js native addon via NAPI
- Include comprehensive unit and integration tests
- Update gitignore to exclude build artifacts and temp files

Resolves #TBD
2026-02-28 09:52:08 -06:00

111 lines
3.5 KiB
Rust

//! Example: File Tagging and Organization
//!
//! This example demonstrates how to tag files and move them to
//! organized folders (extras, commentary, etc.).
use movie_mapper::service::{AuditLogger, TagManager};
use std::env;
use std::path::Path;
#[tokio::main]
async fn main() {
// Get directory from command line
let directory = env::args().nth(1).expect("Please provide a directory path");
let directory = Path::new(&directory);
println!("Managing tags in directory: {:?}", directory);
// Create services
let mut tag_manager = TagManager::new();
let logger = AuditLogger::new(directory.to_str().unwrap());
// Simulate tagging some files
let sample_files = vec![
("video1.mp4", vec!["extra", "behind-the-scenes"]),
("video2.mkv", vec!["commentary"]),
("video3.mp4", vec!["extra"]),
("video4.mkv", vec![]),
];
println!("\nTagging files...");
for (filename, tags) in &sample_files {
let file_path = directory.join(filename);
// Simulate file exists (in real usage, file would actually exist)
// For this example, we'll just track the tags
for tag in tags {
tag_manager.add_tag(&file_path, tag).unwrap();
println!(" Tagged '{}' with '{}'", filename, tag);
}
}
// Show all tagged files
println!("\nFiles with 'extra' tag:");
let extra_files = tag_manager.get_tagged_files("extra");
for file_path in &extra_files {
println!(" - {:?}", file_path);
}
// Create target folders
let extras_folder = directory.join("extras");
let commentary_folder = directory.join("commentary");
println!("\nCreating target folders...");
if let Err(e) = std::fs::create_dir_all(&extras_folder) {
eprintln!(" Error creating extras folder: {}", e);
} else {
println!(" ✅ Created {:?}", extras_folder);
}
if let Err(e) = std::fs::create_dir_all(&commentary_folder) {
eprintln!(" Error creating commentary folder: {}", e);
} else {
println!(" ✅ Created {:?}", commentary_folder);
}
// Move extra files
println!("\nMoving files tagged as 'extra'...");
match tag_manager.move_tagged_files("extra", &extras_folder).await {
Ok(count) => {
println!(" ✅ Moved {} file(s) to extras folder", count);
// Log audit event
logger
.log_event(movie_mapper::service::audit_logger::AuditAction::MoveFile {
original_path: format!("{}/video1.mp4", directory.display()),
new_path: format!("{}/video1.mp4", extras_folder.display()),
folder: "extras".to_string(),
})
.unwrap();
}
Err(e) => {
eprintln!(" Error moving files: {}", e);
}
}
// Move commentary files
println!("\nMoving files tagged as 'commentary'...");
match tag_manager
.move_tagged_files("commentary", &commentary_folder)
.await
{
Ok(count) => {
println!(" ✅ Moved {} file(s) to commentary folder", count);
}
Err(e) => {
eprintln!(" Error moving files: {}", e);
}
}
// Show final state
println!("\nFinal tag state:");
for (filename, _tags) in &sample_files {
let file_path = directory.join(filename);
let current_tags = tag_manager.get_tags(&file_path);
println!(" '{}': {:?}", filename, current_tags);
}
println!("\nAudit logging complete. Check .audit file in directory.");
}