mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-25 19:58:36 -06:00
feat: Added an option to automatically choose the first option
This commit is contained in:
parent
790ec225ea
commit
16118a8d5a
3 changed files with 40 additions and 19 deletions
|
@ -30,6 +30,7 @@ sudo make install
|
|||
- Default pattern is `{title} ({year}) - {director}`. Extension is always kept.
|
||||
- Passing `--directory` or `-d` assumes that the arguments are directory names, which contain exactly one movie and optionally subtitles.
|
||||
- Passing `--dry-run` or `-n` does a dry tun and only prints out the new names, without actually doing anything.
|
||||
- Passing `--i-feel-lucky` or `-l` automatically chooses the first option. Useful when you use the program as part of a script.
|
||||
- Passing `-nd` or `-dn` does a dry run in directory mode.
|
||||
- Passing `--help` or `-h` shows help and exits.
|
||||
- Passing `--version` or `-v` shows version and exits.
|
||||
|
|
|
@ -21,6 +21,7 @@ pub async fn process_file(
|
|||
tmdb: &Client,
|
||||
pattern: &str,
|
||||
dry_run: bool,
|
||||
lucky: bool,
|
||||
movie_list: Option<&HashMap<String, Option<String>>>,
|
||||
// The last bool tells whether the entry should be added to the movie_list or not
|
||||
// The first String is filename without extension, and the second String is
|
||||
|
@ -129,8 +130,13 @@ pub async fn process_file(
|
|||
return (filename_without_ext, None, true);
|
||||
}
|
||||
|
||||
let choice;
|
||||
if lucky {
|
||||
// Take first choice if in lucky mode
|
||||
choice = movie_list.into_iter().next().unwrap();
|
||||
} else {
|
||||
// Choose from the possible entries
|
||||
let choice = match Select::new(
|
||||
choice = match Select::new(
|
||||
format!(" Possible choices for {file_base}:").as_str(),
|
||||
movie_list,
|
||||
)
|
||||
|
@ -146,6 +152,7 @@ pub async fn process_file(
|
|||
return (filename_without_ext, None, flag);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Create the new name
|
||||
new_name_base = choice.rename_format(String::from(pattern));
|
||||
|
@ -206,13 +213,13 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
|
|||
// Remove the entry corresponding to the running process
|
||||
args.remove(0);
|
||||
let mut entries = Vec::new();
|
||||
let mut settings = HashMap::from([("dry_run", false), ("directory", false)]);
|
||||
let mut settings = HashMap::from([("dry_run", false), ("directory", false), ("lucky", false)]);
|
||||
for arg in args {
|
||||
match arg.as_str() {
|
||||
"--help" | "-h" => {
|
||||
println!(" The expected syntax is:");
|
||||
println!(
|
||||
" movie-rename <filename(s)> [-n|--dry-run] [-d|--directory] [-v|--version]"
|
||||
" movie-rename <filename(s)> [-n|--dry-run] [-d|--directory] [-l|--i-feel-lucky] [-v|--version]"
|
||||
);
|
||||
println!(
|
||||
" There needs to be a config file named config in the $XDG_CONFIG_HOME/movie-rename/ directory."
|
||||
|
@ -240,6 +247,10 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
|
|||
println!("Doing a dry run...");
|
||||
settings.entry("dry_run").and_modify(|x| *x = true);
|
||||
}
|
||||
"--i-feel-lucky" | "-l" => {
|
||||
println!("Choosing the first option automatically...");
|
||||
settings.entry("lucky").and_modify(|x| *x = true);
|
||||
}
|
||||
"--directory" | "-d" => {
|
||||
println!("Running in directory mode...");
|
||||
settings.entry("directory").and_modify(|x| *x = true);
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -48,7 +48,15 @@ async fn main() {
|
|||
false => {
|
||||
if Path::new(entry.as_str()).is_file() {
|
||||
// Process the filename for movie entries
|
||||
process_file(&entry, &tmdb, pattern, settings["dry_run"], None).await;
|
||||
process_file(
|
||||
&entry,
|
||||
&tmdb,
|
||||
pattern,
|
||||
settings["dry_run"],
|
||||
settings["lucky"],
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
eprintln!("The file {entry} wasn't found on disk, skipping...");
|
||||
continue;
|
||||
|
@ -70,6 +78,7 @@ async fn main() {
|
|||
&tmdb,
|
||||
pattern,
|
||||
settings["dry_run"],
|
||||
settings["lucky"],
|
||||
Some(&movie_list),
|
||||
)
|
||||
.await;
|
||||
|
|
Loading…
Reference in a new issue