1
0
Fork 0
mirror of synced 2024-04-25 00:02:07 +12:00

Better ignore same size files (#501)

This commit is contained in:
Rafał Mikrut 2021-12-13 20:13:49 +01:00 committed by GitHub
parent 975b285c1f
commit c041ab416e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 19 deletions

View file

@ -391,21 +391,6 @@ impl SimilarImages {
fn sort_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
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 mut records_already_cached: BTreeMap<String, FileEntry> = Default::default();
@ -637,6 +622,24 @@ impl SimilarImages {
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());
// Clean unused data

View file

@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fs::OpenOptions;
use std::fs::{File, Metadata};
use std::io::Write;
@ -75,6 +75,7 @@ pub struct SimilarVideos {
use_cache: bool,
tolerance: i32,
delete_outdated_cache: bool,
exclude_videos_with_same_size: bool,
}
/// Info struck with helpful information's about results
@ -111,9 +112,14 @@ impl SimilarVideos {
use_cache: true,
tolerance: 10,
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) {
self.delete_outdated_cache = delete_outdated_cache;
}
@ -477,11 +483,21 @@ impl SimilarVideos {
let mut collected_similar_videos: Vec<Vec<FileEntry>> = Default::default();
for i in match_group {
let mut temp_vector: Vec<FileEntry> = Vec::new();
let mut bt_size: BTreeSet<u64> = Default::default();
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;

View file

@ -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 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_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_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();
@ -318,6 +319,8 @@ pub fn connect_button_search(
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();
// Find similar videos
thread::spawn(move || {
@ -332,6 +335,7 @@ pub fn connect_button_search(
sf.set_use_cache(use_cache);
sf.set_tolerance(tolerance);
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));
let _ = glib_stop_sender.send(Message::SimilarVideos(sf));
});