Change control flow for some matches

This commit is contained in:
Sayantan Santra 2022-12-08 19:07:15 -06:00
parent 46bbb3edee
commit d293934ba5

View file

@ -81,11 +81,21 @@ fn main() {
// Iterate over filenames
for filename in filenames {
// Check if the file exists on disk
if Path::new(filename.as_str()).exists() == false {
// Check if the file/directory exists on disk
match settings["directory"] {
false => {
if Path::new(filename.as_str()).is_file() == false {
eprintln!("{} wasn't found on disk, skipping...", filename);
continue;
}
}
true => {
if Path::new(filename.as_str()).is_dir() == false {
eprintln!("{} wasn't found on disk, skipping...", filename);
continue;
}
}
}
// Process the filename for movie entries
let (mut extension, movie_list) = process_movie(&filename, &tmdb, pattern);
@ -143,12 +153,9 @@ fn process_movie(filename: &String, tmdb: &TMDb, pattern: &str) -> (String, Vec<
search.title(metadata.title());
// Check if year is present in filename
match metadata.year() {
Some(year) => {
if let Some(year) = metadata.year() {
search.year(year as u64);
}
_ => {}
}
let mut results = Vec::new();
if let Ok(search_results) = search.execute() {
@ -166,16 +173,13 @@ fn process_movie(filename: &String, tmdb: &TMDb, pattern: &str) -> (String, Vec<
let with_credits: Result<Movie, _> =
tmdb.fetch().id(movie_details.id).append_credits().execute();
if let Ok(movie) = with_credits {
match movie.credits {
Some(cre) => {
if let Some(cre) = movie.credits {
let mut directors = cre.crew;
directors.retain(|x| x.job == "Director");
for person in directors {
movie_details.director = person.name;
}
}
None => {}
}
}
}
movie_list.push(movie_details);
@ -200,7 +204,7 @@ fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str, bo
// Remove the entry corresponding to the running process
args.remove(0);
let mut filenames = Vec::new();
let mut settings = HashMap::from([("dry_run", false)]);
let mut settings = HashMap::from([("dry_run", false), ("directory", false)]);
for arg in args {
match arg.as_str() {
"--help" => {
@ -224,6 +228,10 @@ fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str, bo
println!("Doing a dry run...");
settings.entry("dry_run").and_modify(|x| *x = true);
}
"--directory" => {
println!("Running in directory mode...");
settings.entry("directory").and_modify(|x| *x = true);
}
_ => {
filenames.push(arg);
}