|
|
|
@ -477,12 +477,10 @@ impl SameMusic {
|
|
|
|
|
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
|
|
|
|
for file_entry in vec_file_entry {
|
|
|
|
|
let mut title = file_entry.title.to_lowercase().trim().to_string();
|
|
|
|
|
if self.approximate_comparison {
|
|
|
|
|
get_approximate_conversion(&mut title);
|
|
|
|
|
}
|
|
|
|
|
if !title.is_empty() {
|
|
|
|
|
if self.approximate_comparison {
|
|
|
|
|
if let Some(index) = title.find('(') {
|
|
|
|
|
title = title[0..index].trim().to_string();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hash_map.entry(title.clone()).or_insert_with(Vec::new);
|
|
|
|
|
hash_map.get_mut(title.as_str()).unwrap().push(file_entry);
|
|
|
|
|
}
|
|
|
|
@ -510,9 +508,7 @@ impl SameMusic {
|
|
|
|
|
for file_entry in vec_file_entry {
|
|
|
|
|
let mut artist = file_entry.artist.to_lowercase().trim().to_string();
|
|
|
|
|
if self.approximate_comparison {
|
|
|
|
|
if let Some(index) = artist.find('(') {
|
|
|
|
|
artist = artist[0..index].trim().to_string();
|
|
|
|
|
}
|
|
|
|
|
get_approximate_conversion(&mut artist);
|
|
|
|
|
}
|
|
|
|
|
if !artist.is_empty() {
|
|
|
|
|
hash_map.entry(artist.clone()).or_insert_with(Vec::new);
|
|
|
|
@ -542,9 +538,7 @@ impl SameMusic {
|
|
|
|
|
for file_entry in vec_file_entry {
|
|
|
|
|
let mut album_title = file_entry.album_title.to_lowercase().trim().to_string();
|
|
|
|
|
if self.approximate_comparison {
|
|
|
|
|
if let Some(index) = album_title.find('(') {
|
|
|
|
|
album_title = album_title[0..index].trim().to_string();
|
|
|
|
|
}
|
|
|
|
|
get_approximate_conversion(&mut album_title);
|
|
|
|
|
}
|
|
|
|
|
if !album_title.is_empty() {
|
|
|
|
|
hash_map.entry(album_title.clone()).or_insert_with(Vec::new);
|
|
|
|
@ -574,9 +568,7 @@ impl SameMusic {
|
|
|
|
|
for file_entry in vec_file_entry {
|
|
|
|
|
let mut album_artist = file_entry.album_artist.to_lowercase().trim().to_string();
|
|
|
|
|
if self.approximate_comparison {
|
|
|
|
|
if let Some(index) = album_artist.find('(') {
|
|
|
|
|
album_artist = album_artist[0..index].trim().to_string();
|
|
|
|
|
}
|
|
|
|
|
get_approximate_conversion(&mut album_artist);
|
|
|
|
|
}
|
|
|
|
|
if !album_artist.is_empty() {
|
|
|
|
|
hash_map.entry(album_artist.clone()).or_insert_with(Vec::new);
|
|
|
|
@ -752,12 +744,12 @@ impl PrintResults for SameMusic {
|
|
|
|
|
for vec_file_entry in self.duplicated_music_entries.iter() {
|
|
|
|
|
for file_entry in vec_file_entry {
|
|
|
|
|
println!(
|
|
|
|
|
"T: {} - A: {} - AT: {} - AA: {} - Y: {} - P: {}",
|
|
|
|
|
"T: {} - A: {} - Y: {} - AT: {} - AA: {} - P: {}",
|
|
|
|
|
file_entry.title,
|
|
|
|
|
file_entry.artist,
|
|
|
|
|
file_entry.year,
|
|
|
|
|
file_entry.album_title,
|
|
|
|
|
file_entry.album_artist,
|
|
|
|
|
file_entry.year,
|
|
|
|
|
file_entry.path.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -767,3 +759,56 @@ impl PrintResults for SameMusic {
|
|
|
|
|
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_approximate_conversion(what: &mut String) {
|
|
|
|
|
let mut new_what = String::with_capacity(what.len());
|
|
|
|
|
let mut tab_number = 0;
|
|
|
|
|
let mut space_before = true;
|
|
|
|
|
for character in what.chars().into_iter() {
|
|
|
|
|
match character {
|
|
|
|
|
'(' => {
|
|
|
|
|
tab_number += 1;
|
|
|
|
|
}
|
|
|
|
|
')' => {
|
|
|
|
|
if tab_number == 0 {
|
|
|
|
|
// Nothing to do, not even save it to output
|
|
|
|
|
} else {
|
|
|
|
|
tab_number -= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
' ' => {
|
|
|
|
|
if !space_before {
|
|
|
|
|
new_what.push(' ');
|
|
|
|
|
space_before = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ch => {
|
|
|
|
|
if tab_number == 0 {
|
|
|
|
|
space_before = false;
|
|
|
|
|
new_what.push(ch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if new_what.ends_with(' ') {
|
|
|
|
|
new_what.pop();
|
|
|
|
|
}
|
|
|
|
|
*what = new_what;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use crate::same_music::get_approximate_conversion;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_strings() {
|
|
|
|
|
let mut what = "roman ( ziemniak ) ".to_string();
|
|
|
|
|
get_approximate_conversion(&mut what);
|
|
|
|
|
assert_eq!(what, "roman");
|
|
|
|
|
|
|
|
|
|
let mut what = " HH) ".to_string();
|
|
|
|
|
get_approximate_conversion(&mut what);
|
|
|
|
|
assert_eq!(what, "HH");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|