Better ignore same size files (#501)
This commit is contained in:
parent
975b285c1f
commit
c041ab416e
|
@ -391,21 +391,6 @@ impl SimilarImages {
|
||||||
fn sort_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
fn sort_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
||||||
let hash_map_modification = SystemTime::now();
|
let hash_map_modification = SystemTime::now();
|
||||||
|
|
||||||
if self.exclude_images_with_same_size {
|
|
||||||
let mut old_hash_map = Default::default();
|
|
||||||
mem::swap(&mut self.images_to_check, &mut old_hash_map);
|
|
||||||
|
|
||||||
let mut new_hash_map: BTreeMap<u64, FileEntry> = Default::default();
|
|
||||||
|
|
||||||
for (_name, file_entry) in old_hash_map {
|
|
||||||
new_hash_map.insert(file_entry.size, file_entry);
|
|
||||||
}
|
|
||||||
self.images_to_check = Default::default();
|
|
||||||
for (_size, file_entry) in new_hash_map {
|
|
||||||
self.images_to_check.insert(file_entry.path.to_string_lossy().to_string(), file_entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let loaded_hash_map;
|
let loaded_hash_map;
|
||||||
|
|
||||||
let mut records_already_cached: BTreeMap<String, FileEntry> = Default::default();
|
let mut records_already_cached: BTreeMap<String, FileEntry> = Default::default();
|
||||||
|
@ -637,6 +622,24 @@ impl SimilarImages {
|
||||||
|
|
||||||
self.similar_vectors = collected_similar_images.values().cloned().collect();
|
self.similar_vectors = collected_similar_images.values().cloned().collect();
|
||||||
|
|
||||||
|
if self.exclude_images_with_same_size {
|
||||||
|
let mut new_vector = Default::default();
|
||||||
|
mem::swap(&mut self.similar_vectors, &mut new_vector);
|
||||||
|
for vec_file_entry in new_vector {
|
||||||
|
let mut bt_sizes: BTreeSet<u64> = Default::default();
|
||||||
|
let mut vec_values = Vec::new();
|
||||||
|
for file_entry in vec_file_entry {
|
||||||
|
if !bt_sizes.contains(&file_entry.size) {
|
||||||
|
bt_sizes.insert(file_entry.size);
|
||||||
|
vec_values.push(file_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if vec_values.len() > 1 {
|
||||||
|
self.similar_vectors.push(vec_values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - selecting data from BtreeMap".to_string());
|
Common::print_time(hash_map_modification, SystemTime::now(), "sort_images - selecting data from BtreeMap".to_string());
|
||||||
|
|
||||||
// Clean unused data
|
// Clean unused data
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::{File, Metadata};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -75,6 +75,7 @@ pub struct SimilarVideos {
|
||||||
use_cache: bool,
|
use_cache: bool,
|
||||||
tolerance: i32,
|
tolerance: i32,
|
||||||
delete_outdated_cache: bool,
|
delete_outdated_cache: bool,
|
||||||
|
exclude_videos_with_same_size: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Info struck with helpful information's about results
|
/// Info struck with helpful information's about results
|
||||||
|
@ -111,9 +112,14 @@ impl SimilarVideos {
|
||||||
use_cache: true,
|
use_cache: true,
|
||||||
tolerance: 10,
|
tolerance: 10,
|
||||||
delete_outdated_cache: false,
|
delete_outdated_cache: false,
|
||||||
|
exclude_videos_with_same_size: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_exclude_videos_with_same_size(&mut self, exclude_videos_with_same_size: bool) {
|
||||||
|
self.exclude_videos_with_same_size = exclude_videos_with_same_size;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_delete_outdated_cache(&mut self, delete_outdated_cache: bool) {
|
pub fn set_delete_outdated_cache(&mut self, delete_outdated_cache: bool) {
|
||||||
self.delete_outdated_cache = delete_outdated_cache;
|
self.delete_outdated_cache = delete_outdated_cache;
|
||||||
}
|
}
|
||||||
|
@ -477,11 +483,21 @@ impl SimilarVideos {
|
||||||
let mut collected_similar_videos: Vec<Vec<FileEntry>> = Default::default();
|
let mut collected_similar_videos: Vec<Vec<FileEntry>> = Default::default();
|
||||||
for i in match_group {
|
for i in match_group {
|
||||||
let mut temp_vector: Vec<FileEntry> = Vec::new();
|
let mut temp_vector: Vec<FileEntry> = Vec::new();
|
||||||
|
let mut bt_size: BTreeSet<u64> = Default::default();
|
||||||
for j in i.duplicates() {
|
for j in i.duplicates() {
|
||||||
temp_vector.push(hashmap_with_file_entries.get(&j.to_string_lossy().to_string()).unwrap().clone());
|
let file_entry = hashmap_with_file_entries.get(&j.to_string_lossy().to_string()).unwrap();
|
||||||
|
if self.exclude_videos_with_same_size {
|
||||||
|
if !bt_size.contains(&file_entry.size) {
|
||||||
|
bt_size.insert(file_entry.size);
|
||||||
|
temp_vector.push(file_entry.clone());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
temp_vector.push(file_entry.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if temp_vector.len() > 1 {
|
||||||
|
collected_similar_videos.push(temp_vector);
|
||||||
}
|
}
|
||||||
assert!(temp_vector.len() > 1);
|
|
||||||
collected_similar_videos.push(temp_vector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.similar_vectors = collected_similar_videos;
|
self.similar_vectors = collected_similar_videos;
|
||||||
|
|
|
@ -46,6 +46,7 @@ pub fn connect_button_search(
|
||||||
let combo_box_duplicate_hash_type = gui_data.main_notebook.combo_box_duplicate_hash_type.clone();
|
let combo_box_duplicate_hash_type = gui_data.main_notebook.combo_box_duplicate_hash_type.clone();
|
||||||
let buttons_array = gui_data.bottom_buttons.buttons_array.clone();
|
let buttons_array = gui_data.bottom_buttons.buttons_array.clone();
|
||||||
let check_button_image_ignore_same_size = gui_data.main_notebook.check_button_image_ignore_same_size.clone();
|
let check_button_image_ignore_same_size = gui_data.main_notebook.check_button_image_ignore_same_size.clone();
|
||||||
|
let check_button_video_ignore_same_size = gui_data.main_notebook.check_button_video_ignore_same_size.clone();
|
||||||
let buttons_names = gui_data.bottom_buttons.buttons_names.clone();
|
let buttons_names = gui_data.bottom_buttons.buttons_names.clone();
|
||||||
let buttons_search_clone = gui_data.bottom_buttons.buttons_search.clone();
|
let buttons_search_clone = gui_data.bottom_buttons.buttons_search.clone();
|
||||||
let check_button_duplicates_use_prehash_cache = gui_data.settings.check_button_duplicates_use_prehash_cache.clone();
|
let check_button_duplicates_use_prehash_cache = gui_data.settings.check_button_duplicates_use_prehash_cache.clone();
|
||||||
|
@ -318,6 +319,8 @@ pub fn connect_button_search(
|
||||||
|
|
||||||
let delete_outdated_cache = check_button_settings_similar_videos_delete_outdated_cache.is_active();
|
let delete_outdated_cache = check_button_settings_similar_videos_delete_outdated_cache.is_active();
|
||||||
|
|
||||||
|
let ignore_same_size = check_button_video_ignore_same_size.is_active();
|
||||||
|
|
||||||
let futures_sender_similar_videos = futures_sender_similar_videos.clone();
|
let futures_sender_similar_videos = futures_sender_similar_videos.clone();
|
||||||
// Find similar videos
|
// Find similar videos
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
@ -332,6 +335,7 @@ pub fn connect_button_search(
|
||||||
sf.set_use_cache(use_cache);
|
sf.set_use_cache(use_cache);
|
||||||
sf.set_tolerance(tolerance);
|
sf.set_tolerance(tolerance);
|
||||||
sf.set_delete_outdated_cache(delete_outdated_cache);
|
sf.set_delete_outdated_cache(delete_outdated_cache);
|
||||||
|
sf.set_exclude_videos_with_same_size(ignore_same_size);
|
||||||
sf.find_similar_videos(Some(&stop_receiver), Some(&futures_sender_similar_videos));
|
sf.find_similar_videos(Some(&stop_receiver), Some(&futures_sender_similar_videos));
|
||||||
let _ = glib_stop_sender.send(Message::SimilarVideos(sf));
|
let _ = glib_stop_sender.send(Message::SimilarVideos(sf));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue