Skip to content

Commit 78d00ee

Browse files
authored
Add finding similar audio by content (#970)
* In prehashing check for user clicks, less often * Similar audio * Remove ugly time checking * Fix using cache * Fix cache and improve performance of validating items * Remove cache type - cache should be saved to two different cache files(because ) * Working * Simple multithreading * Basic Generalization * Reference folder and swap cleaning * Split into multiple files * Commons, improved GUI message * Simplifying thread run * Check was stopped * Fix checking same files * Make read single file tag more general * Remove unnnecessary clone * Reading tags * Base * Search * Gui Fix * Gui Fix * Tooltip
1 parent 14ccb49 commit 78d00ee

32 files changed

+1880
-1592
lines changed

Cargo.lock

+26-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

czkawka_core/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pdf = "0.8"
3838

3939
# Needed by audio similarity feature
4040
rusty-chromaprint = "0.1"
41-
symphonia = { version = "0.5", features = ["mp3", "aac", "alac", "flac", "isomp4", "mkv", "ogg", "pcm", "vorbis", "wav"] }
41+
symphonia = { version = "0.5", features = ["all"] }
4242

4343
# Hashes for duplicate files
4444
blake3 = "1.3"
@@ -74,10 +74,10 @@ num_cpus = "1.15"
7474

7575
# Heif/Heic
7676
libheif-rs = { version = "0.18.0", optional = true } # Do not upgrade now, since Ubuntu 22.04 not works with newer version
77-
anyhow = { version = "1.0", optional = true }
77+
anyhow = { version = "1.0" }
7878

7979
state = "0.5"
8080

8181
[features]
8282
default = []
83-
heif = ["dep:libheif-rs", "dep:anyhow"]
83+
heif = ["dep:libheif-rs"]

czkawka_core/src/bad_extensions.rs

+7-32
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use std::mem;
66
use std::path::PathBuf;
77
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
88
use std::sync::Arc;
9-
use std::time::SystemTime;
109

1110
use crossbeam_channel::Receiver;
1211
use futures::channel::mpsc::UnboundedSender;
1312
use mime_guess::get_mime_extensions;
1413
use rayon::prelude::*;
1514

16-
use crate::common::{prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, Common};
15+
use crate::common::{prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads};
1716
use crate::common_dir_traversal::{CheckingMethod, DirTraversalBuilder, DirTraversalResult, FileEntry, ProgressData};
1817
use crate::common_directory::Directories;
1918
use crate::common_extensions::Extensions;
@@ -298,16 +297,12 @@ impl BadExtensions {
298297
.build()
299298
.run();
300299
match result {
301-
DirTraversalResult::SuccessFiles {
302-
start_time,
303-
grouped_file_entries,
304-
warnings,
305-
} => {
300+
DirTraversalResult::SuccessFiles { grouped_file_entries, warnings } => {
306301
if let Some(files_to_check) = grouped_file_entries.get(&()) {
307302
self.files_to_check = files_to_check.clone();
308303
}
309304
self.text_messages.warnings.extend(warnings);
310-
Common::print_time(start_time, SystemTime::now(), "check_files");
305+
311306
true
312307
}
313308
DirTraversalResult::SuccessFolders { .. } => {
@@ -318,24 +313,10 @@ impl BadExtensions {
318313
}
319314

320315
fn look_for_bad_extensions_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&UnboundedSender<ProgressData>>) -> bool {
321-
let system_time = SystemTime::now();
322-
323-
let check_was_stopped = AtomicBool::new(false); // Used for breaking from GUI and ending check thread
324-
325-
let progress_thread_run = Arc::new(AtomicBool::new(true));
326-
let atomic_counter = Arc::new(AtomicUsize::new(0));
327-
let progress_thread_handle = prepare_thread_handler_common(
328-
progress_sender,
329-
&progress_thread_run,
330-
&atomic_counter,
331-
1,
332-
1,
333-
self.files_to_check.len(),
334-
CheckingMethod::None,
335-
);
316+
let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) =
317+
prepare_thread_handler_common(progress_sender, 1, 1, self.files_to_check.len(), CheckingMethod::None);
336318

337-
let mut files_to_check = Default::default();
338-
mem::swap(&mut files_to_check, &mut self.files_to_check);
319+
let files_to_check = mem::take(&mut self.files_to_check);
339320

340321
let mut hashmap_workarounds: HashMap<&str, Vec<&str>> = Default::default();
341322
for (proper, found) in WORKAROUNDS {
@@ -357,8 +338,6 @@ impl BadExtensions {
357338

358339
self.information.number_of_files_with_bad_extension = self.bad_extensions_files.len();
359340

360-
Common::print_time(system_time, SystemTime::now(), "bad extension finding");
361-
362341
// Clean unused data
363342
self.files_to_check = Default::default();
364343

@@ -525,7 +504,6 @@ impl DebugPrint for BadExtensions {
525504

526505
impl SaveResults for BadExtensions {
527506
fn save_results_to_file(&mut self, file_name: &str) -> bool {
528-
let start_time: SystemTime = SystemTime::now();
529507
let file_name: String = match file_name {
530508
"" => "results.txt".to_string(),
531509
k => k.to_string(),
@@ -557,7 +535,7 @@ impl SaveResults for BadExtensions {
557535
} else {
558536
write!(writer, "Not found any files with invalid extension.").unwrap();
559537
}
560-
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
538+
561539
true
562540
}
563541
}
@@ -566,12 +544,9 @@ impl PrintResults for BadExtensions {
566544
/// Print information's about duplicated entries
567545
/// Only needed for CLI
568546
fn print_results(&self) {
569-
let start_time: SystemTime = SystemTime::now();
570547
println!("Found {} files with invalid extension.\n", self.information.number_of_files_with_bad_extension);
571548
for file_entry in &self.bad_extensions_files {
572549
println!("{} ----- {}", file_entry.path.display(), file_entry.proper_extensions);
573550
}
574-
575-
Common::print_time(start_time, SystemTime::now(), "print_entries");
576551
}
577552
}

czkawka_core/src/big_file.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ use std::fs;
33
use std::fs::{DirEntry, File, Metadata};
44
use std::io::{BufWriter, Write};
55
use std::path::{Path, PathBuf};
6-
use std::sync::atomic::AtomicBool;
6+
77
use std::sync::atomic::{AtomicUsize, Ordering};
88
use std::sync::Arc;
9-
use std::time::SystemTime;
109

1110
use crossbeam_channel::Receiver;
1211
use futures::channel::mpsc::UnboundedSender;
1312
use humansize::format_size;
1413
use humansize::BINARY;
1514
use rayon::prelude::*;
1615

17-
use crate::common::Common;
1816
use crate::common::{check_folder_children, prepare_thread_handler_common, send_info_and_wait_for_ending_all_threads, split_path};
1917
use crate::common_dir_traversal::{common_get_entry_data_metadata, common_read_dir, get_lowercase_name, get_modified_time, CheckingMethod, ProgressData};
2018
use crate::common_directory::Directories;
@@ -142,7 +140,6 @@ impl BigFile {
142140
}
143141

144142
fn look_for_big_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&UnboundedSender<ProgressData>>) -> bool {
145-
let start_time: SystemTime = SystemTime::now();
146143
let mut folders_to_check: Vec<PathBuf> = Vec::with_capacity(1024 * 2); // This should be small enough too not see to big difference and big enough to store most of paths without needing to resize vector
147144
let mut old_map: BTreeMap<u64, Vec<FileEntry>> = Default::default();
148145

@@ -151,9 +148,7 @@ impl BigFile {
151148
folders_to_check.push(id.clone());
152149
}
153150

154-
let progress_thread_run = Arc::new(AtomicBool::new(true));
155-
let atomic_counter = Arc::new(AtomicUsize::new(0));
156-
let progress_thread_handle = prepare_thread_handler_common(progress_sender, &progress_thread_run, &atomic_counter, 0, 0, 0, CheckingMethod::None);
151+
let (progress_thread_handle, progress_thread_run, atomic_counter, _check_was_stopped) = prepare_thread_handler_common(progress_sender, 0, 0, 0, CheckingMethod::None);
157152

158153
while !folders_to_check.is_empty() {
159154
if stop_receiver.is_some() && stop_receiver.unwrap().try_recv().is_ok() {
@@ -213,7 +208,6 @@ impl BigFile {
213208

214209
self.extract_n_biggest_files(old_map);
215210

216-
Common::print_time(start_time, SystemTime::now(), "look_for_big_files");
217211
true
218212
}
219213

@@ -308,8 +302,6 @@ impl BigFile {
308302

309303
/// Function to delete files, from filed Vector
310304
fn delete_files(&mut self) {
311-
let start_time: SystemTime = SystemTime::now();
312-
313305
match self.delete_method {
314306
DeleteMethod::Delete => {
315307
for (_, file_entry) in &self.big_files {
@@ -322,8 +314,6 @@ impl BigFile {
322314
//Just do nothing
323315
}
324316
}
325-
326-
Common::print_time(start_time, SystemTime::now(), "delete_files");
327317
}
328318
}
329319

@@ -365,7 +355,6 @@ impl DebugPrint for BigFile {
365355
impl SaveResults for BigFile {
366356
/// Saving results to provided file
367357
fn save_results_to_file(&mut self, file_name: &str) -> bool {
368-
let start_time: SystemTime = SystemTime::now();
369358
let file_name: String = match file_name {
370359
"" => "results.txt".to_string(),
371360
k => k.to_string(),
@@ -401,14 +390,13 @@ impl SaveResults for BigFile {
401390
} else {
402391
write!(writer, "Not found any files.").unwrap();
403392
}
404-
Common::print_time(start_time, SystemTime::now(), "save_results_to_file");
393+
405394
true
406395
}
407396
}
408397

409398
impl PrintResults for BigFile {
410399
fn print_results(&self) {
411-
let start_time: SystemTime = SystemTime::now();
412400
if self.search_mode == SearchMode::BiggestFiles {
413401
println!("{} the biggest files.\n\n", self.information.number_of_real_files);
414402
} else {
@@ -417,6 +405,5 @@ impl PrintResults for BigFile {
417405
for (size, file_entry) in &self.big_files {
418406
println!("{} ({}) - {}", format_size(*size, BINARY), size, file_entry.path.display());
419407
}
420-
Common::print_time(start_time, SystemTime::now(), "print_entries");
421408
}
422409
}

0 commit comments

Comments
 (0)