mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-25 11:48:37 -06:00
Fixed clippy warnings
This commit is contained in:
parent
c0760526fa
commit
14e5899f36
2 changed files with 22 additions and 23 deletions
|
@ -24,12 +24,11 @@ pub fn process_file(
|
|||
// Get the basename
|
||||
let mut file_base = String::from(filename);
|
||||
let mut parent = String::from("");
|
||||
match filename.rsplit_once("/") {
|
||||
Some(parts) => {
|
||||
if let Some(parts) = filename.rsplit_once('/') {
|
||||
{
|
||||
parent = parts.0.to_string();
|
||||
file_base = parts.1.to_string();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
println!(" Processing {}...", file_base);
|
||||
|
||||
|
@ -81,7 +80,7 @@ pub fn process_file(
|
|||
}
|
||||
|
||||
// If nothing is found, skip
|
||||
if movie_list.len() == 0 {
|
||||
if movie_list.is_empty() {
|
||||
eprintln!(" Could not find any entries matching {}!", file_base);
|
||||
return ("".to_string(), true);
|
||||
}
|
||||
|
@ -98,7 +97,7 @@ pub fn process_file(
|
|||
let mut is_subtitle = false;
|
||||
if ["srt", "ssa"].contains(&extension.as_str()) {
|
||||
// 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 {
|
||||
println!(
|
||||
" 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)
|
||||
.prompt()
|
||||
.expect(" Invalid choice!");
|
||||
if lang_choice.short != "none".to_string() {
|
||||
if lang_choice.short != *"none" {
|
||||
extension = format!("{}.{}", lang_choice.short, extension);
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +120,11 @@ pub fn process_file(
|
|||
// Create the new name
|
||||
let new_name_base = choice.rename_format(pattern.to_string());
|
||||
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);
|
||||
}
|
||||
let mut new_name = String::from(new_name_with_ext.clone());
|
||||
if parent != "".to_string() {
|
||||
let mut new_name = new_name_with_ext.clone();
|
||||
if parent != *"" {
|
||||
new_name = format!("{}/{}", parent, new_name);
|
||||
}
|
||||
|
||||
|
@ -135,8 +134,8 @@ pub fn process_file(
|
|||
} else {
|
||||
println!(" [file] '{}' -> '{}'", file_base, new_name_with_ext);
|
||||
// Only do the rename of --dry-run isn't passed
|
||||
if dry_run == false {
|
||||
if Path::new(new_name.as_str()).is_file() == false {
|
||||
if !dry_run {
|
||||
if !Path::new(new_name.as_str()).is_file() {
|
||||
fs::rename(filename, new_name.as_str()).expect(" Unable to rename file!");
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
other => {
|
||||
if other.starts_with("-") {
|
||||
if other.starts_with('-') {
|
||||
eprintln!("Unknown argument passed: {}", other);
|
||||
exit(1);
|
||||
} else {
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -16,13 +16,13 @@ fn main() {
|
|||
|
||||
// Try to read config file, or display error
|
||||
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.push_str("/.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.");
|
||||
exit(2);
|
||||
}
|
||||
|
@ -31,14 +31,14 @@ fn main() {
|
|||
let api_key = config.next().unwrap_or("");
|
||||
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.");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
// Create TMDb object for API calls
|
||||
let tmdb = TMDb {
|
||||
api_key: api_key,
|
||||
api_key,
|
||||
language: "en",
|
||||
};
|
||||
|
||||
|
@ -49,7 +49,7 @@ fn main() {
|
|||
match settings["directory"] {
|
||||
// Normal file
|
||||
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_file(&entry, &tmdb, pattern, settings["dry_run"]);
|
||||
} else {
|
||||
|
@ -59,7 +59,7 @@ fn main() {
|
|||
}
|
||||
// Directory
|
||||
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);
|
||||
let mut movie_count = 0;
|
||||
let mut movie_name = String::new();
|
||||
|
@ -73,11 +73,11 @@ fn main() {
|
|||
settings["dry_run"],
|
||||
);
|
||||
|
||||
if movie_name_temp == "n/a".to_string() {
|
||||
if movie_name_temp == *"n/a" {
|
||||
continue;
|
||||
}
|
||||
|
||||
if is_subtitle == false {
|
||||
if !is_subtitle {
|
||||
movie_count += 1;
|
||||
movie_name = movie_name_temp;
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ fn main() {
|
|||
continue;
|
||||
}
|
||||
if movie_count == 1 {
|
||||
let entry_clean = entry.trim_end_matches("/");
|
||||
let entry_clean = entry.trim_end_matches('/');
|
||||
if entry_clean == movie_name {
|
||||
println!("[directory] '{}' already has correct name.", entry_clean);
|
||||
} else {
|
||||
println!("[directory] '{}' -> '{}'", entry_clean, movie_name);
|
||||
if settings["dry_run"] == false {
|
||||
if Path::new(movie_name.as_str()).is_dir() == false {
|
||||
if !settings["dry_run"] {
|
||||
if !Path::new(movie_name.as_str()).is_dir() {
|
||||
fs::rename(entry, movie_name)
|
||||
.expect("Unable to rename directory!");
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue