1
0
Fork 0
mirror of synced 2024-04-24 15:52:07 +12:00

Better comparison of music tags (#485)

This commit is contained in:
Rafał Mikrut 2021-12-04 14:49:43 +01:00 committed by GitHub
parent 1a51d2a17a
commit 5296e1c708
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 28 deletions

View file

@ -12,6 +12,7 @@
- Improve custom selecting of records(allows to use Rust red regex) - [#489](https://github.com/qarmin/czkawka/pull/478)
- Remove support for finding zeroed files - [#461](https://github.com/qarmin/czkawka/pull/461)
- Remove HashMB mode - [#476](https://github.com/qarmin/czkawka/pull/476)
- Approximate comparison of music - [#483](https://github.com/qarmin/czkawka/pull/483)
## Version 3.3.1 - 22.11.2021r
- Fix crash when moving buttons [#457](https://github.com/qarmin/czkawka/pull/457)

View file

@ -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");
}
}

View file

@ -517,6 +517,17 @@ pub fn create_tree_view_same_music(tree_view: &mut gtk::TreeView) {
column.add_attribute(&renderer, "foreground", ColumnsSameMusic::TextColor as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
let column: gtk::TreeViewColumn = TreeViewColumn::new();
column.pack_start(&renderer, true);
column.set_title("Year");
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsSameMusic::Year as i32);
column.add_attribute(&renderer, "background", ColumnsSameMusic::Color as i32);
column.add_attribute(&renderer, "foreground", ColumnsSameMusic::TextColor as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
let column: gtk::TreeViewColumn = TreeViewColumn::new();
column.pack_start(&renderer, true);
@ -539,17 +550,6 @@ pub fn create_tree_view_same_music(tree_view: &mut gtk::TreeView) {
column.add_attribute(&renderer, "foreground", ColumnsSameMusic::TextColor as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
let column: gtk::TreeViewColumn = TreeViewColumn::new();
column.pack_start(&renderer, true);
column.set_title("Year");
column.set_resizable(true);
column.set_min_width(50);
column.add_attribute(&renderer, "text", ColumnsSameMusic::Year as i32);
column.add_attribute(&renderer, "background", ColumnsSameMusic::Color as i32);
column.add_attribute(&renderer, "foreground", ColumnsSameMusic::TextColor as i32);
tree_view.append_column(&column);
let renderer = gtk::CellRendererText::new();
let column: gtk::TreeViewColumn = TreeViewColumn::new();
column.pack_start(&renderer, true);

View file

@ -1855,7 +1855,6 @@ Author: Rafał Mikrut
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-bottom">2</property>
<property name="spacing">8</property>
<child>
<object class="GtkCheckButton" id="check_button_music_title">
@ -1940,6 +1939,9 @@ Author: Rafał Mikrut
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-bottom">2</property>
<child>
<object class="GtkCheckButton" id="check_button_music_approximate_comparison">
<property name="label" translatable="yes">Approximate Comparison</property>