mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-26 20:28:36 -06:00
Change control flow for some matches
This commit is contained in:
parent
46bbb3edee
commit
d293934ba5
1 changed files with 26 additions and 18 deletions
30
src/main.rs
30
src/main.rs
|
@ -81,11 +81,21 @@ fn main() {
|
||||||
|
|
||||||
// Iterate over filenames
|
// Iterate over filenames
|
||||||
for filename in filenames {
|
for filename in filenames {
|
||||||
// Check if the file exists on disk
|
// Check if the file/directory exists on disk
|
||||||
if Path::new(filename.as_str()).exists() == false {
|
match settings["directory"] {
|
||||||
|
false => {
|
||||||
|
if Path::new(filename.as_str()).is_file() == false {
|
||||||
eprintln!("{} wasn't found on disk, skipping...", filename);
|
eprintln!("{} wasn't found on disk, skipping...", filename);
|
||||||
continue;
|
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
|
// Process the filename for movie entries
|
||||||
let (mut extension, movie_list) = process_movie(&filename, &tmdb, pattern);
|
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());
|
search.title(metadata.title());
|
||||||
|
|
||||||
// Check if year is present in filename
|
// Check if year is present in filename
|
||||||
match metadata.year() {
|
if let Some(year) = metadata.year() {
|
||||||
Some(year) => {
|
|
||||||
search.year(year as u64);
|
search.year(year as u64);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
if let Ok(search_results) = search.execute() {
|
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, _> =
|
let with_credits: Result<Movie, _> =
|
||||||
tmdb.fetch().id(movie_details.id).append_credits().execute();
|
tmdb.fetch().id(movie_details.id).append_credits().execute();
|
||||||
if let Ok(movie) = with_credits {
|
if let Ok(movie) = with_credits {
|
||||||
match movie.credits {
|
if let Some(cre) = movie.credits {
|
||||||
Some(cre) => {
|
|
||||||
let mut directors = cre.crew;
|
let mut directors = cre.crew;
|
||||||
directors.retain(|x| x.job == "Director");
|
directors.retain(|x| x.job == "Director");
|
||||||
for person in directors {
|
for person in directors {
|
||||||
movie_details.director = person.name;
|
movie_details.director = person.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
movie_list.push(movie_details);
|
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
|
// Remove the entry corresponding to the running process
|
||||||
args.remove(0);
|
args.remove(0);
|
||||||
let mut filenames = Vec::new();
|
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 {
|
for arg in args {
|
||||||
match arg.as_str() {
|
match arg.as_str() {
|
||||||
"--help" => {
|
"--help" => {
|
||||||
|
@ -224,6 +228,10 @@ fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str, bo
|
||||||
println!("Doing a dry run...");
|
println!("Doing a dry run...");
|
||||||
settings.entry("dry_run").and_modify(|x| *x = true);
|
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);
|
filenames.push(arg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue