diff --git a/src/lib.rs b/src/lib.rs index 4c1a2ff..bc46c89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -371,16 +371,23 @@ impl Movies { /// If there is a yearless movie and one or more movies with a year exist, then the yearless /// movie will be removed 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 mut movie_counter = HashMap::new(); let mut movies_without_date_counter = HashMap::new(); for m in &self.movies { let (path, _cmd) = m.files.first().unwrap(); - let parent = clean_path_parent(path) - .to_string_lossy() - .to_ascii_lowercase() - .replace("-", " ") - .replace("'", "") + let parent = MULTIPLE_SPACES + .replace_all( + &clean_path_parent(path) + .to_string_lossy() + .to_ascii_lowercase() + .replace("-", " ") + .replace("'", " "), + " ", + ) .to_string(); if date_re.is_match(&parent) { movie_counter.entry(parent).or_insert(Vec::new()).push(m);