Remove dashes and repeated spaces when comparing names for dupes.

This commit is contained in:
Bill Thiede 2021-11-21 16:50:18 -08:00
parent b2ef1d3d3d
commit 70174e9e49

View File

@ -371,16 +371,23 @@ impl Movies {
/// If there is a yearless movie and one or more movies with a year exist, then the yearless /// If there is a yearless movie and one or more movies with a year exist, then the yearless
/// movie will be removed /// movie will be removed
pub fn duplicate_candidates(&self) -> Vec<(&Movie, Vec<&Movie>)> { pub fn duplicate_candidates(&self) -> Vec<(&Movie, Vec<&Movie>)> {
lazy_static! {
static ref MULTIPLE_SPACES: Regex = Regex::new(r"\s+").unwrap();
}
let date_re = Regex::new(r"\(\d{4}\)$").unwrap(); let date_re = Regex::new(r"\(\d{4}\)$").unwrap();
let mut movie_counter = HashMap::new(); let mut movie_counter = HashMap::new();
let mut movies_without_date_counter = HashMap::new(); let mut movies_without_date_counter = HashMap::new();
for m in &self.movies { for m in &self.movies {
let (path, _cmd) = m.files.first().unwrap(); let (path, _cmd) = m.files.first().unwrap();
let parent = clean_path_parent(path) let parent = MULTIPLE_SPACES
.to_string_lossy() .replace_all(
.to_ascii_lowercase() &clean_path_parent(path)
.replace("-", " ") .to_string_lossy()
.replace("'", "") .to_ascii_lowercase()
.replace("-", " ")
.replace("'", " "),
" ",
)
.to_string(); .to_string();
if date_re.is_match(&parent) { if date_re.is_match(&parent) {
movie_counter.entry(parent).or_insert(Vec::new()).push(m); movie_counter.entry(parent).or_insert(Vec::new()).push(m);