Make root directory a flag.

This commit is contained in:
Bill Thiede 2022-07-23 21:33:36 -07:00
parent 3a61e15449
commit 318ce583ea

View File

@ -179,6 +179,13 @@ enum Command {
about = "Tool for pruning extra videos in collection" about = "Tool for pruning extra videos in collection"
)] )]
struct SuperDeduper { struct SuperDeduper {
#[structopt(
short = "r",
long = "root",
help = "Root directory to store files.",
default_value = MOVIE_DIR,
)]
root: String,
#[structopt( #[structopt(
short = "v", short = "v",
help = "Sets the level of verbosity", help = "Sets the level of verbosity",
@ -206,14 +213,14 @@ fn main() -> Result<(), Box<dyn Error>> {
match app.cmd { match app.cmd {
Command::Samples => { Command::Samples => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
let videos = lib.videos()?; let videos = lib.videos()?;
let samples_re = Regex::new(r"(?i).*sample.*").unwrap(); let samples_re = Regex::new(r"(?i).*sample.*").unwrap();
print_videos(&videos, Some(&samples_re)); print_videos(&videos, Some(&samples_re));
} }
Command::Groups => { Command::Groups => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
let videos = lib.videos()?; let videos = lib.videos()?;
let mut video_groups: HashMap<String, Vec<(String, CompactMetadata)>> = HashMap::new(); let mut video_groups: HashMap<String, Vec<(String, CompactMetadata)>> = HashMap::new();
@ -226,30 +233,30 @@ fn main() -> Result<(), Box<dyn Error>> {
print_video_groups(&video_groups); print_video_groups(&video_groups);
} }
Command::CompactMetadata => { Command::CompactMetadata => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
lib.compact_metadata()?; lib.compact_metadata()?;
} }
Command::PrintDupes => { Command::PrintDupes => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
print_dupes(&lib); print_dupes(&lib);
} }
Command::PrintAll => { Command::PrintAll => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
let videos = lib.videos()?; let videos = lib.videos()?;
print_all(videos); print_all(videos);
} }
Command::UpdateMetadata => { Command::UpdateMetadata => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
lib.update_metadata()?; lib.update_metadata()?;
} }
Command::UpdateAndCompactMetadata => { Command::UpdateAndCompactMetadata => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
lib.update_metadata()?; lib.update_metadata()?;
lib.compact_metadata()?; lib.compact_metadata()?;
} }
Command::EmptyDirs => { Command::EmptyDirs => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(app.root);
let dirs = lib.empty_dirs()?; let dirs = lib.empty_dirs()?;
let root = Path::new(&lib.root); let root = Path::new(&lib.root);
if !dirs.is_empty() { if !dirs.is_empty() {