Fixed clippy warnings

This commit is contained in:
Sayantan Santra 2023-04-26 17:27:39 -05:00
parent c0760526fa
commit 14e5899f36
2 changed files with 22 additions and 23 deletions

View file

@ -24,12 +24,11 @@ pub fn process_file(
// Get the basename // Get the basename
let mut file_base = String::from(filename); let mut file_base = String::from(filename);
let mut parent = String::from(""); let mut parent = String::from("");
match filename.rsplit_once("/") { if let Some(parts) = filename.rsplit_once('/') {
Some(parts) => { {
parent = parts.0.to_string(); parent = parts.0.to_string();
file_base = parts.1.to_string(); file_base = parts.1.to_string();
} }
None => {}
} }
println!(" Processing {}...", file_base); println!(" Processing {}...", file_base);
@ -81,7 +80,7 @@ pub fn process_file(
} }
// If nothing is found, skip // If nothing is found, skip
if movie_list.len() == 0 { if movie_list.is_empty() {
eprintln!(" Could not find any entries matching {}!", file_base); eprintln!(" Could not find any entries matching {}!", file_base);
return ("".to_string(), true); return ("".to_string(), true);
} }
@ -98,7 +97,7 @@ pub fn process_file(
let mut is_subtitle = false; let mut is_subtitle = false;
if ["srt", "ssa"].contains(&extension.as_str()) { if ["srt", "ssa"].contains(&extension.as_str()) {
// Try to detect if there's already language info in the filename, else ask user to choose // Try to detect if there's already language info in the filename, else ask user to choose
let filename_parts: Vec<&str> = filename.rsplit(".").collect(); let filename_parts: Vec<&str> = filename.rsplit('.').collect();
if filename_parts.len() >= 3 && filename_parts[1].len() == 2 { if filename_parts.len() >= 3 && filename_parts[1].len() == 2 {
println!( println!(
" Keeping language {} as detected in the subtitle file's extension...", " Keeping language {} as detected in the subtitle file's extension...",
@ -111,7 +110,7 @@ pub fn process_file(
Select::new(" Choose the language for the subtitle file:", lang_list) Select::new(" Choose the language for the subtitle file:", lang_list)
.prompt() .prompt()
.expect(" Invalid choice!"); .expect(" Invalid choice!");
if lang_choice.short != "none".to_string() { if lang_choice.short != *"none" {
extension = format!("{}.{}", lang_choice.short, extension); extension = format!("{}.{}", lang_choice.short, extension);
} }
} }
@ -121,11 +120,11 @@ pub fn process_file(
// Create the new name // Create the new name
let new_name_base = choice.rename_format(pattern.to_string()); let new_name_base = choice.rename_format(pattern.to_string());
let mut new_name_with_ext = new_name_base.clone(); let mut new_name_with_ext = new_name_base.clone();
if extension != "" { 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 = String::from(new_name_with_ext.clone()); let mut new_name = new_name_with_ext.clone();
if parent != "".to_string() { if parent != *"" {
new_name = format!("{}/{}", parent, new_name); new_name = format!("{}/{}", parent, new_name);
} }
@ -135,8 +134,8 @@ pub fn process_file(
} else { } 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 // Only do the rename of --dry-run isn't passed
if dry_run == false { if !dry_run {
if Path::new(new_name.as_str()).is_file() == false { if !Path::new(new_name.as_str()).is_file() {
fs::rename(filename, new_name.as_str()).expect(" Unable to rename file!"); fs::rename(filename, new_name.as_str()).expect(" Unable to rename file!");
} else { } else {
eprintln!(" Destination file already exists, skipping..."); eprintln!(" Destination file already exists, skipping...");
@ -195,7 +194,7 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
settings.entry("directory").and_modify(|x| *x = true); settings.entry("directory").and_modify(|x| *x = true);
} }
other => { other => {
if other.starts_with("-") { if other.starts_with('-') {
eprintln!("Unknown argument passed: {}", other); eprintln!("Unknown argument passed: {}", other);
exit(1); exit(1);
} else { } else {

View file

@ -16,13 +16,13 @@ fn main() {
// Try to read config file, or display error // Try to read config file, or display error
let mut config_file = env::var("XDG_CONFIG_HOME").unwrap_or("$HOME".to_string()); let mut config_file = env::var("XDG_CONFIG_HOME").unwrap_or("$HOME".to_string());
if config_file == String::from("$HOME") { if config_file == *"$HOME" {
config_file = env::var("$HOME").unwrap(); config_file = env::var("$HOME").unwrap();
config_file.push_str("/.config"); config_file.push_str("/.config");
} }
config_file.push_str("/movie-rename/config"); config_file.push_str("/movie-rename/config");
if Path::new(config_file.as_str()).is_file() == false { if !Path::new(config_file.as_str()).is_file() {
eprintln!("Error reading the config file. Pass --help to see help."); eprintln!("Error reading the config file. Pass --help to see help.");
exit(2); exit(2);
} }
@ -31,14 +31,14 @@ fn main() {
let api_key = config.next().unwrap_or(""); let api_key = config.next().unwrap_or("");
let pattern = config.next().unwrap_or("{title} ({year}) - {director}"); let pattern = config.next().unwrap_or("{title} ({year}) - {director}");
if api_key == "" { if api_key.is_empty() {
eprintln!("Could not read the API key. Pass --help to see help."); eprintln!("Could not read the API key. Pass --help to see help.");
exit(2); exit(2);
} }
// Create TMDb object for API calls // Create TMDb object for API calls
let tmdb = TMDb { let tmdb = TMDb {
api_key: api_key, api_key,
language: "en", language: "en",
}; };
@ -49,7 +49,7 @@ fn main() {
match settings["directory"] { match settings["directory"] {
// Normal file // Normal file
false => { false => {
if Path::new(entry.as_str()).is_file() == true { if Path::new(entry.as_str()).is_file() {
// Process the filename for movie entries // Process the filename for movie entries
process_file(&entry, &tmdb, pattern, settings["dry_run"]); process_file(&entry, &tmdb, pattern, settings["dry_run"]);
} else { } else {
@ -59,7 +59,7 @@ fn main() {
} }
// Directory // Directory
true => { true => {
if Path::new(entry.as_str()).is_dir() == 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_count = 0; let mut movie_count = 0;
let mut movie_name = String::new(); let mut movie_name = String::new();
@ -73,11 +73,11 @@ fn main() {
settings["dry_run"], settings["dry_run"],
); );
if movie_name_temp == "n/a".to_string() { if movie_name_temp == *"n/a" {
continue; continue;
} }
if is_subtitle == false { if !is_subtitle {
movie_count += 1; movie_count += 1;
movie_name = movie_name_temp; movie_name = movie_name_temp;
} }
@ -88,13 +88,13 @@ fn main() {
continue; continue;
} }
if movie_count == 1 { if movie_count == 1 {
let entry_clean = entry.trim_end_matches("/"); let entry_clean = entry.trim_end_matches('/');
if entry_clean == movie_name { if entry_clean == movie_name {
println!("[directory] '{}' already has correct name.", entry_clean); println!("[directory] '{}' already has correct name.", entry_clean);
} else { } else {
println!("[directory] '{}' -> '{}'", entry_clean, movie_name); println!("[directory] '{}' -> '{}'", entry_clean, movie_name);
if settings["dry_run"] == false { if !settings["dry_run"] {
if Path::new(movie_name.as_str()).is_dir() == false { if !Path::new(movie_name.as_str()).is_dir() {
fs::rename(entry, movie_name) fs::rename(entry, movie_name)
.expect("Unable to rename directory!"); .expect("Unable to rename directory!");
} else { } else {