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
/// 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);