mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-26 12:18:37 -06:00
Visual changes
This commit is contained in:
parent
159e9d49eb
commit
29fd0c3646
3 changed files with 38 additions and 26 deletions
|
@ -79,7 +79,7 @@ pub fn process_file(
|
||||||
|
|
||||||
// Choose from the possible entries
|
// Choose from the possible entries
|
||||||
let choice = Select::new(
|
let choice = Select::new(
|
||||||
format!("Possible choices for {}", file_base).as_str(),
|
format!("Possible choices for {}:", file_base).as_str(),
|
||||||
movie_list,
|
movie_list,
|
||||||
)
|
)
|
||||||
.prompt()
|
.prompt()
|
||||||
|
@ -112,9 +112,9 @@ pub fn process_file(
|
||||||
|
|
||||||
// Process the renaming
|
// Process the renaming
|
||||||
if *filename == new_name {
|
if *filename == new_name {
|
||||||
println!("[file] {} already has correct name.", filename);
|
println!("[file] '{}' already has correct name.", file_base);
|
||||||
} 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 == false {
|
||||||
fs::rename(filename, new_name.as_str()).expect("Unable to rename file!");
|
fs::rename(filename, new_name.as_str()).expect("Unable to rename file!");
|
||||||
|
|
|
@ -76,10 +76,11 @@ fn main() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if movie_count == 1 {
|
if movie_count == 1 {
|
||||||
if entry == movie_name {
|
let entry_clean = entry.trim_end_matches("/");
|
||||||
println!("[directory] {} already has correct name.", entry);
|
if entry_clean == movie_name {
|
||||||
|
println!("[directory] '{}' already has correct name.", entry_clean);
|
||||||
} else {
|
} else {
|
||||||
println!("[directory] {} -> {}", entry, movie_name);
|
println!("[directory] '{}' -> '{}'", entry_clean, movie_name);
|
||||||
if settings["dry_run"] == false {
|
if settings["dry_run"] == false {
|
||||||
fs::rename(entry, movie_name).expect("Unable to rename directory!");
|
fs::rename(entry, movie_name).expect("Unable to rename directory!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ pub struct MovieEntry {
|
||||||
pub director: String,
|
pub director: String,
|
||||||
pub year: String,
|
pub year: String,
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub overview: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MovieEntry {
|
impl MovieEntry {
|
||||||
|
@ -19,8 +18,7 @@ impl MovieEntry {
|
||||||
id: movie.id,
|
id: movie.id,
|
||||||
director: String::from("N/A"),
|
director: String::from("N/A"),
|
||||||
year: String::from(movie.release_date.split('-').next().unwrap_or("N/A")),
|
year: String::from(movie.release_date.split('-').next().unwrap_or("N/A")),
|
||||||
language: movie.original_language,
|
language: get_long_lang(movie.original_language.as_str()),
|
||||||
overview: movie.overview.unwrap_or(String::from("N/A")),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +42,14 @@ impl MovieEntry {
|
||||||
// Implement display trait for movie entries
|
// Implement display trait for movie entries
|
||||||
impl fmt::Display for MovieEntry {
|
impl fmt::Display for MovieEntry {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{} ({})", self.title, self.year)
|
let mut buffer = String::new();
|
||||||
|
buffer.push_str(&format!("{} ", self.title));
|
||||||
|
buffer.push_str(&format!("({}), ", self.year));
|
||||||
|
buffer.push_str(&format!("Language: {}, ", self.language));
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,25 +59,15 @@ pub struct Language {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Language {
|
impl Language {
|
||||||
// Create Language entries from &str pairs
|
|
||||||
fn from(short: &str, long: &str) -> Language {
|
|
||||||
Language {
|
|
||||||
short: short.to_string(),
|
|
||||||
long: long.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a vector of Language entries of all supported languages
|
// Generate a vector of Language entries of all supported languages
|
||||||
pub fn generate_list() -> Vec<Language> {
|
pub fn generate_list() -> Vec<Language> {
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
list.push(Language::from("en", "English"));
|
for lang in ["en", "hi", "bn", "fr", "ja", "de", "sp", "none"] {
|
||||||
list.push(Language::from("hi", "Hindi"));
|
list.push(Language {
|
||||||
list.push(Language::from("bn", "Bengali"));
|
short: lang.to_string(),
|
||||||
list.push(Language::from("fr", "French"));
|
long: get_long_lang(lang),
|
||||||
list.push(Language::from("ja", "Japanese"));
|
});
|
||||||
list.push(Language::from("de", "German"));
|
}
|
||||||
list.push(Language::from("sp", "Spanish"));
|
|
||||||
list.push(Language::from("none", "None"));
|
|
||||||
list
|
list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,3 +78,19 @@ impl fmt::Display for Language {
|
||||||
write!(f, "{}", self.long)
|
write!(f, "{}", self.long)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get long name of a language
|
||||||
|
fn get_long_lang(short: &str) -> String {
|
||||||
|
let long = match short {
|
||||||
|
"en" => "English",
|
||||||
|
"hi" => "Hindi",
|
||||||
|
"bn" => "Bengali",
|
||||||
|
"fr" => "French",
|
||||||
|
"ja" => "Japanese",
|
||||||
|
"de" => "German",
|
||||||
|
"sp" => "Spanish",
|
||||||
|
"none" => "None",
|
||||||
|
other => other,
|
||||||
|
};
|
||||||
|
long.to_string()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue