mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-25 11:48:37 -06:00
change: Put variable inside format string directly when possible
This commit is contained in:
parent
0e92c693f7
commit
8b6e83a55a
3 changed files with 20 additions and 23 deletions
|
@ -62,10 +62,7 @@ pub async fn process_file(
|
|||
|
||||
// Check if it should be ignored
|
||||
if preprocessed && new_name_base.is_empty() {
|
||||
eprintln!(
|
||||
" Ignoring {} as per previous choice for related files...",
|
||||
file_base
|
||||
);
|
||||
eprintln!(" Ignoring {file_base} as per previous choice for related files...");
|
||||
return (filename_without_ext, "".to_string(), false);
|
||||
}
|
||||
|
||||
|
@ -75,9 +72,9 @@ pub async fn process_file(
|
|||
// Process only if it's a valid file format
|
||||
let mut extension = metadata.extension().unwrap_or("").to_string();
|
||||
if ["mp4", "avi", "mkv", "flv", "m4a", "srt", "ssa"].contains(&extension.as_str()) {
|
||||
println!(" Processing {}...", file_base);
|
||||
println!(" Processing {file_base}...");
|
||||
} else {
|
||||
println!(" Ignoring {}...", file_base);
|
||||
println!(" Ignoring {file_base}...");
|
||||
return (filename_without_ext, "".to_string(), false);
|
||||
}
|
||||
|
||||
|
@ -91,7 +88,7 @@ pub async fn process_file(
|
|||
let results = match reply {
|
||||
Ok(res) => Ok(res.results),
|
||||
Err(e) => {
|
||||
eprintln!(" There was an error while searching {}!", file_base);
|
||||
eprintln!(" There was an error while searching {file_base}!");
|
||||
Err(e)
|
||||
}
|
||||
};
|
||||
|
@ -126,13 +123,13 @@ pub async fn process_file(
|
|||
|
||||
// If nothing is found, skip
|
||||
if movie_list.is_empty() {
|
||||
eprintln!(" Could not find any entries matching {}!", file_base);
|
||||
eprintln!(" Could not find any entries matching {file_base}!");
|
||||
return (filename_without_ext, "".to_string(), true);
|
||||
}
|
||||
|
||||
// Choose from the possible entries
|
||||
let choice = match Select::new(
|
||||
format!(" Possible choices for {}:", file_base).as_str(),
|
||||
format!(" Possible choices for {file_base}:").as_str(),
|
||||
movie_list,
|
||||
)
|
||||
.prompt()
|
||||
|
@ -174,18 +171,18 @@ pub async fn process_file(
|
|||
// Add extension and stuff to the new name
|
||||
let mut new_name_with_ext = new_name_base.clone();
|
||||
if !extension.is_empty() {
|
||||
new_name_with_ext = format!("{}.{}", new_name_with_ext, extension);
|
||||
new_name_with_ext = format!("{new_name_with_ext}.{extension}");
|
||||
}
|
||||
let mut new_name = new_name_with_ext.clone();
|
||||
if parent != *"" {
|
||||
new_name = format!("{}/{}", parent, new_name);
|
||||
new_name = format!("{parent}/{new_name}");
|
||||
}
|
||||
|
||||
// Process the renaming
|
||||
if *filename == new_name {
|
||||
println!(" [file] '{}' already has correct name.", file_base);
|
||||
println!(" [file] '{file_base}' already has correct name.");
|
||||
} else {
|
||||
println!(" [file] '{}' -> '{}'", file_base, new_name_with_ext);
|
||||
println!(" [file] '{file_base}' -> '{new_name_with_ext}'");
|
||||
// Only do the rename of --dry-run isn't passed
|
||||
if !dry_run {
|
||||
if !Path::new(new_name.as_str()).is_file() {
|
||||
|
@ -230,7 +227,7 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
|
|||
exit(0);
|
||||
}
|
||||
"--version" | "-v" => {
|
||||
println!("movie-rename {}", VERSION);
|
||||
println!("movie-rename {VERSION}");
|
||||
exit(0);
|
||||
}
|
||||
"--dry-run" | "-n" => {
|
||||
|
@ -248,7 +245,7 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
|
|||
}
|
||||
other => {
|
||||
if other.starts_with('-') {
|
||||
eprintln!("Unknown argument passed: {}", other);
|
||||
eprintln!("Unknown argument passed: {other}");
|
||||
exit(1);
|
||||
} else {
|
||||
entries.push(arg);
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -50,14 +50,14 @@ async fn main() {
|
|||
// Process the filename for movie entries
|
||||
process_file(&entry, &tmdb, pattern, settings["dry_run"], None).await;
|
||||
} else {
|
||||
eprintln!("The file {} wasn't found on disk, skipping...", entry);
|
||||
eprintln!("The file {entry} wasn't found on disk, skipping...");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Directory
|
||||
true => {
|
||||
if Path::new(entry.as_str()).is_dir() {
|
||||
println!("Processing files inside the directory {}...", entry);
|
||||
println!("Processing files inside the directory {entry}...");
|
||||
let mut movie_list = HashMap::new();
|
||||
|
||||
if let Ok(files_in_dir) = fs::read_dir(entry.as_str()) {
|
||||
|
@ -84,7 +84,7 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
eprintln!("There was an error accessing the directory {}!", entry);
|
||||
eprintln!("There was an error accessing the directory {entry}!");
|
||||
continue;
|
||||
}
|
||||
if movie_list.len() == 1 {
|
||||
|
@ -92,9 +92,9 @@ async fn main() {
|
|||
let movie_name = movie_list.into_values().next().unwrap();
|
||||
|
||||
if entry_clean == movie_name {
|
||||
println!("[directory] '{}' already has correct name.", entry_clean);
|
||||
println!("[directory] '{entry_clean}' already has correct name.");
|
||||
} else {
|
||||
println!("[directory] '{}' -> '{}'", entry_clean, movie_name);
|
||||
println!("[directory] '{entry_clean}' -> '{movie_name}'");
|
||||
if !settings["dry_run"] {
|
||||
if !Path::new(movie_name.as_str()).is_dir() {
|
||||
fs::rename(entry, movie_name)
|
||||
|
@ -105,10 +105,10 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
eprintln!("Could not determine how to rename the directory {}!", entry);
|
||||
eprintln!("Could not determine how to rename the directory {entry}!");
|
||||
}
|
||||
} else {
|
||||
eprintln!("The directory {} wasn't found on disk, skipping...", entry);
|
||||
eprintln!("The directory {entry} wasn't found on disk, skipping...");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ impl fmt::Display for MovieEntry {
|
|||
buffer.push_str(&format!("Directed by: {}, ", self.director));
|
||||
buffer.push_str(&format!("TMDB ID: {}", self.id));
|
||||
// buffer.push_str(&format!("Synopsis: {}", self.overview));
|
||||
write!(f, "{}", buffer)
|
||||
write!(f, "{buffer}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue