Better comparison of music tags (#485)
This commit is contained in:
parent
1a51d2a17a
commit
5296e1c708
|
@ -12,6 +12,7 @@
|
||||||
- Improve custom selecting of records(allows to use Rust red regex) - [#489](https://github.com/qarmin/czkawka/pull/478)
|
- 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 support for finding zeroed files - [#461](https://github.com/qarmin/czkawka/pull/461)
|
||||||
- Remove HashMB mode - [#476](https://github.com/qarmin/czkawka/pull/476)
|
- 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
|
## Version 3.3.1 - 22.11.2021r
|
||||||
- Fix crash when moving buttons [#457](https://github.com/qarmin/czkawka/pull/457)
|
- Fix crash when moving buttons [#457](https://github.com/qarmin/czkawka/pull/457)
|
||||||
|
|
|
@ -477,12 +477,10 @@ impl SameMusic {
|
||||||
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
||||||
for file_entry in vec_file_entry {
|
for file_entry in vec_file_entry {
|
||||||
let mut title = file_entry.title.to_lowercase().trim().to_string();
|
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 !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.entry(title.clone()).or_insert_with(Vec::new);
|
||||||
hash_map.get_mut(title.as_str()).unwrap().push(file_entry);
|
hash_map.get_mut(title.as_str()).unwrap().push(file_entry);
|
||||||
}
|
}
|
||||||
|
@ -510,9 +508,7 @@ impl SameMusic {
|
||||||
for file_entry in vec_file_entry {
|
for file_entry in vec_file_entry {
|
||||||
let mut artist = file_entry.artist.to_lowercase().trim().to_string();
|
let mut artist = file_entry.artist.to_lowercase().trim().to_string();
|
||||||
if self.approximate_comparison {
|
if self.approximate_comparison {
|
||||||
if let Some(index) = artist.find('(') {
|
get_approximate_conversion(&mut artist);
|
||||||
artist = artist[0..index].trim().to_string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !artist.is_empty() {
|
if !artist.is_empty() {
|
||||||
hash_map.entry(artist.clone()).or_insert_with(Vec::new);
|
hash_map.entry(artist.clone()).or_insert_with(Vec::new);
|
||||||
|
@ -542,9 +538,7 @@ impl SameMusic {
|
||||||
for file_entry in vec_file_entry {
|
for file_entry in vec_file_entry {
|
||||||
let mut album_title = file_entry.album_title.to_lowercase().trim().to_string();
|
let mut album_title = file_entry.album_title.to_lowercase().trim().to_string();
|
||||||
if self.approximate_comparison {
|
if self.approximate_comparison {
|
||||||
if let Some(index) = album_title.find('(') {
|
get_approximate_conversion(&mut album_title);
|
||||||
album_title = album_title[0..index].trim().to_string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !album_title.is_empty() {
|
if !album_title.is_empty() {
|
||||||
hash_map.entry(album_title.clone()).or_insert_with(Vec::new);
|
hash_map.entry(album_title.clone()).or_insert_with(Vec::new);
|
||||||
|
@ -574,9 +568,7 @@ impl SameMusic {
|
||||||
for file_entry in vec_file_entry {
|
for file_entry in vec_file_entry {
|
||||||
let mut album_artist = file_entry.album_artist.to_lowercase().trim().to_string();
|
let mut album_artist = file_entry.album_artist.to_lowercase().trim().to_string();
|
||||||
if self.approximate_comparison {
|
if self.approximate_comparison {
|
||||||
if let Some(index) = album_artist.find('(') {
|
get_approximate_conversion(&mut album_artist);
|
||||||
album_artist = album_artist[0..index].trim().to_string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !album_artist.is_empty() {
|
if !album_artist.is_empty() {
|
||||||
hash_map.entry(album_artist.clone()).or_insert_with(Vec::new);
|
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 vec_file_entry in self.duplicated_music_entries.iter() {
|
||||||
for file_entry in vec_file_entry {
|
for file_entry in vec_file_entry {
|
||||||
println!(
|
println!(
|
||||||
"T: {} - A: {} - AT: {} - AA: {} - Y: {} - P: {}",
|
"T: {} - A: {} - Y: {} - AT: {} - AA: {} - P: {}",
|
||||||
file_entry.title,
|
file_entry.title,
|
||||||
file_entry.artist,
|
file_entry.artist,
|
||||||
|
file_entry.year,
|
||||||
file_entry.album_title,
|
file_entry.album_title,
|
||||||
file_entry.album_artist,
|
file_entry.album_artist,
|
||||||
file_entry.year,
|
|
||||||
file_entry.path.display()
|
file_entry.path.display()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -767,3 +759,56 @@ impl PrintResults for SameMusic {
|
||||||
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
column.add_attribute(&renderer, "foreground", ColumnsSameMusic::TextColor as i32);
|
||||||
tree_view.append_column(&column);
|
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 renderer = gtk::CellRendererText::new();
|
||||||
let column: gtk::TreeViewColumn = TreeViewColumn::new();
|
let column: gtk::TreeViewColumn = TreeViewColumn::new();
|
||||||
column.pack_start(&renderer, true);
|
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);
|
column.add_attribute(&renderer, "foreground", ColumnsSameMusic::TextColor as i32);
|
||||||
tree_view.append_column(&column);
|
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 renderer = gtk::CellRendererText::new();
|
||||||
let column: gtk::TreeViewColumn = TreeViewColumn::new();
|
let column: gtk::TreeViewColumn = TreeViewColumn::new();
|
||||||
column.pack_start(&renderer, true);
|
column.pack_start(&renderer, true);
|
||||||
|
|
|
@ -1855,7 +1855,6 @@ Author: Rafał Mikrut
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="margin-start">5</property>
|
<property name="margin-start">5</property>
|
||||||
<property name="margin-end">5</property>
|
<property name="margin-end">5</property>
|
||||||
<property name="margin-bottom">2</property>
|
|
||||||
<property name="spacing">8</property>
|
<property name="spacing">8</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCheckButton" id="check_button_music_title">
|
<object class="GtkCheckButton" id="check_button_music_title">
|
||||||
|
@ -1940,6 +1939,9 @@ Author: Rafał Mikrut
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</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>
|
<child>
|
||||||
<object class="GtkCheckButton" id="check_button_music_approximate_comparison">
|
<object class="GtkCheckButton" id="check_button_music_approximate_comparison">
|
||||||
<property name="label" translatable="yes">Approximate Comparison</property>
|
<property name="label" translatable="yes">Approximate Comparison</property>
|
||||||
|
|
Loading…
Reference in a new issue