mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-27 04:38:35 -06:00
Handle case where year isn't present in filename
This commit is contained in:
parent
22db11a956
commit
c95095f35f
1 changed files with 35 additions and 8 deletions
43
src/main.rs
43
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use load_file::{self, load_str};
|
use load_file::{self, load_str};
|
||||||
use std::{collections::HashMap, env, fmt, fs, process::exit};
|
use std::{collections::HashMap, env, fmt, fs, path::Path, process::exit};
|
||||||
use tmdb::{model::*, themoviedb::*};
|
use tmdb::{model::*, themoviedb::*};
|
||||||
use torrent_name_parser::Metadata;
|
use torrent_name_parser::Metadata;
|
||||||
use youchoose;
|
use youchoose;
|
||||||
|
@ -81,9 +81,21 @@ fn main() {
|
||||||
|
|
||||||
// Iterate over filenames
|
// Iterate over filenames
|
||||||
for filename in filenames {
|
for filename in filenames {
|
||||||
|
// Check if the file exists on disk
|
||||||
|
if Path::new(filename.as_str()).exists() == false {
|
||||||
|
eprintln!("{} wasn't found on disk, skipping...", filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Process the filename for movie entries
|
// Process the filename for movie entries
|
||||||
let (mut extension, movie_list) = process_movie(&filename, &tmdb, pattern);
|
let (mut extension, movie_list) = process_movie(&filename, &tmdb, pattern);
|
||||||
|
|
||||||
|
// If nothing is found, skip
|
||||||
|
if movie_list.len() == 0 {
|
||||||
|
eprintln!("Could not find any entries matching {}", filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Choose from the possible entries
|
// Choose from the possible entries
|
||||||
let mut menu = youchoose::Menu::new(movie_list.iter())
|
let mut menu = youchoose::Menu::new(movie_list.iter())
|
||||||
.preview(display)
|
.preview(display)
|
||||||
|
@ -127,13 +139,28 @@ fn process_movie(filename: &String, tmdb: &TMDb, pattern: &str) -> (String, Vec<
|
||||||
// Parse the filename for metadata
|
// Parse the filename for metadata
|
||||||
let metadata = Metadata::from(filename.as_str()).expect("Could not parse filename");
|
let metadata = Metadata::from(filename.as_str()).expect("Could not parse filename");
|
||||||
// Search using the TMDb API
|
// Search using the TMDb API
|
||||||
let results = tmdb
|
let mut search = tmdb.search();
|
||||||
.search()
|
search.title(metadata.title());
|
||||||
.title(metadata.title())
|
|
||||||
.year(metadata.year().unwrap() as u64)
|
// Check if year is present in filename
|
||||||
.execute()
|
match metadata.year() {
|
||||||
.unwrap()
|
Some(year) => {
|
||||||
.results;
|
search.year(year as u64);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
eprintln!(
|
||||||
|
"Year is currently needed for the search to work, please add year in the filename." // TODO Add support for missing year
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut results = Vec::new();
|
||||||
|
if let Ok(search_results) = search.execute() {
|
||||||
|
results = search_results.results;
|
||||||
|
} else {
|
||||||
|
eprintln!("There was an error while searching {}", filename);
|
||||||
|
}
|
||||||
|
|
||||||
let mut movie_list: Vec<MovieEntry> = Vec::new();
|
let mut movie_list: Vec<MovieEntry> = Vec::new();
|
||||||
// Create movie entry from the result
|
// Create movie entry from the result
|
||||||
for result in results {
|
for result in results {
|
||||||
|
|
Loading…
Reference in a new issue