Use DirTraversal for similar music (#559)
* Use DirTraversal for similar music * Simplify file type checking * Fix for clippy
This commit is contained in:
parent
24ad6b3857
commit
db3b1f5304
|
@ -266,6 +266,19 @@ pub enum DirTraversalResult<T: Ord + PartialOrd> {
|
||||||
Stopped,
|
Stopped,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn entry_type(metadata: &Metadata) -> EntryType {
|
||||||
|
let file_type = metadata.file_type();
|
||||||
|
if file_type.is_dir() {
|
||||||
|
EntryType::Dir
|
||||||
|
} else if file_type.is_symlink() {
|
||||||
|
EntryType::Symlink
|
||||||
|
} else if file_type.is_file() {
|
||||||
|
EntryType::File
|
||||||
|
} else {
|
||||||
|
EntryType::Other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b, F, T> DirTraversal<'a, 'b, F>
|
impl<'a, 'b, F, T> DirTraversal<'a, 'b, F>
|
||||||
where
|
where
|
||||||
F: Fn(&FileEntry) -> T,
|
F: Fn(&FileEntry) -> T,
|
||||||
|
@ -389,17 +402,7 @@ where
|
||||||
continue 'dir;
|
continue 'dir;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let entry_type;
|
match (entry_type(&metadata), collect) {
|
||||||
if metadata.is_dir() {
|
|
||||||
entry_type = EntryType::Dir;
|
|
||||||
} else if metadata.file_type().is_symlink() {
|
|
||||||
entry_type = EntryType::Symlink;
|
|
||||||
} else if metadata.is_file() {
|
|
||||||
entry_type = EntryType::File;
|
|
||||||
} else {
|
|
||||||
entry_type = EntryType::Other;
|
|
||||||
}
|
|
||||||
match (entry_type, collect) {
|
|
||||||
(EntryType::Dir, Collect::Files) | (EntryType::Dir, Collect::InvalidSymlinks) => {
|
(EntryType::Dir, Collect::Files) | (EntryType::Dir, Collect::InvalidSymlinks) => {
|
||||||
if !recursive_search {
|
if !recursive_search {
|
||||||
continue 'dir;
|
continue 'dir;
|
||||||
|
|
|
@ -1,36 +1,27 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::BufWriter;
|
use std::io::BufWriter;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime};
|
||||||
use std::{fs, mem, thread};
|
use std::{mem, thread};
|
||||||
|
|
||||||
use audiotags::Tag;
|
use audiotags::Tag;
|
||||||
use crossbeam_channel::Receiver;
|
use crossbeam_channel::Receiver;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::common::Common;
|
use crate::common::Common;
|
||||||
|
use crate::common_dir_traversal::{CheckingMethod, DirTraversalBuilder, DirTraversalResult, FileEntry, ProgressData};
|
||||||
use crate::common_directory::Directories;
|
use crate::common_directory::Directories;
|
||||||
use crate::common_extensions::Extensions;
|
use crate::common_extensions::Extensions;
|
||||||
use crate::common_items::ExcludedItems;
|
use crate::common_items::ExcludedItems;
|
||||||
use crate::common_messages::Messages;
|
use crate::common_messages::Messages;
|
||||||
use crate::common_traits::*;
|
use crate::common_traits::*;
|
||||||
use crate::fl;
|
|
||||||
use crate::localizer::generate_translation_hashmap;
|
|
||||||
use crate::similar_images::AUDIO_FILES_EXTENSIONS;
|
use crate::similar_images::AUDIO_FILES_EXTENSIONS;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ProgressData {
|
|
||||||
pub current_stage: u8,
|
|
||||||
pub max_stage: u8,
|
|
||||||
pub music_checked: usize,
|
|
||||||
pub music_to_check: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Clone, Debug)]
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||||
pub enum DeleteMethod {
|
pub enum DeleteMethod {
|
||||||
None,
|
None,
|
||||||
|
@ -53,7 +44,7 @@ bitflags! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct FileEntry {
|
pub struct MusicEntry {
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
|
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
|
@ -69,6 +60,23 @@ pub struct FileEntry {
|
||||||
// pub time: u32,
|
// pub time: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FileEntry {
|
||||||
|
fn into_music_entry(self) -> MusicEntry {
|
||||||
|
MusicEntry {
|
||||||
|
size: self.size,
|
||||||
|
path: self.path,
|
||||||
|
modified_date: self.modified_date,
|
||||||
|
|
||||||
|
title: "".to_string(),
|
||||||
|
|
||||||
|
artist: "".to_string(),
|
||||||
|
album_title: "".to_string(),
|
||||||
|
album_artist: "".to_string(),
|
||||||
|
year: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Info struck with helpful information's about results
|
/// Info struck with helpful information's about results
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Info {
|
pub struct Info {
|
||||||
|
@ -87,9 +95,9 @@ pub struct SameMusic {
|
||||||
text_messages: Messages,
|
text_messages: Messages,
|
||||||
information: Info,
|
information: Info,
|
||||||
music_to_check: Vec<FileEntry>,
|
music_to_check: Vec<FileEntry>,
|
||||||
music_entries: Vec<FileEntry>,
|
music_entries: Vec<MusicEntry>,
|
||||||
duplicated_music_entries: Vec<Vec<FileEntry>>,
|
duplicated_music_entries: Vec<Vec<MusicEntry>>,
|
||||||
duplicated_music_entries_referenced: Vec<(FileEntry, Vec<FileEntry>)>,
|
duplicated_music_entries_referenced: Vec<(MusicEntry, Vec<MusicEntry>)>,
|
||||||
directories: Directories,
|
directories: Directories,
|
||||||
allowed_extensions: Extensions,
|
allowed_extensions: Extensions,
|
||||||
excluded_items: ExcludedItems,
|
excluded_items: ExcludedItems,
|
||||||
|
@ -149,7 +157,7 @@ impl SameMusic {
|
||||||
self.stopped_search
|
self.stopped_search
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn get_duplicated_music_entries(&self) -> &Vec<Vec<FileEntry>> {
|
pub const fn get_duplicated_music_entries(&self) -> &Vec<Vec<MusicEntry>> {
|
||||||
&self.duplicated_music_entries
|
&self.duplicated_music_entries
|
||||||
}
|
}
|
||||||
pub const fn get_music_similarity(&self) -> &MusicSimilarity {
|
pub const fn get_music_similarity(&self) -> &MusicSimilarity {
|
||||||
|
@ -208,7 +216,7 @@ impl SameMusic {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_similar_music_referenced(&self) -> &Vec<(FileEntry, Vec<FileEntry>)> {
|
pub fn get_similar_music_referenced(&self) -> &Vec<(MusicEntry, Vec<MusicEntry>)> {
|
||||||
&self.duplicated_music_entries_referenced
|
&self.duplicated_music_entries_referenced
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,193 +233,41 @@ impl SameMusic {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
fn check_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
||||||
let start_time: SystemTime = SystemTime::now();
|
|
||||||
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
|
|
||||||
|
|
||||||
if !self.allowed_extensions.using_custom_extensions() {
|
if !self.allowed_extensions.using_custom_extensions() {
|
||||||
self.allowed_extensions.extend_allowed_extensions(&AUDIO_FILES_EXTENSIONS);
|
self.allowed_extensions.extend_allowed_extensions(&AUDIO_FILES_EXTENSIONS);
|
||||||
}
|
}
|
||||||
|
let result = DirTraversalBuilder::new()
|
||||||
// Add root folders for finding
|
.root_dirs(self.directories.included_directories.clone())
|
||||||
for id in &self.directories.included_directories {
|
.group_by(|_fe| ())
|
||||||
folders_to_check.push(id.clone());
|
.stop_receiver(stop_receiver)
|
||||||
}
|
.progress_sender(progress_sender)
|
||||||
|
.minimal_file_size(self.minimal_file_size)
|
||||||
//// PROGRESS THREAD START
|
.maximal_file_size(self.maximal_file_size)
|
||||||
const LOOP_DURATION: u32 = 200; //in ms
|
.directories(self.directories.clone())
|
||||||
let progress_thread_run = Arc::new(AtomicBool::new(true));
|
.allowed_extensions(self.allowed_extensions.clone())
|
||||||
|
.excluded_items(self.excluded_items.clone())
|
||||||
let atomic_file_counter = Arc::new(AtomicUsize::new(0));
|
.recursive_search(self.recursive_search)
|
||||||
|
.max_stage(2)
|
||||||
let progress_thread_handle = if let Some(progress_sender) = progress_sender {
|
.build()
|
||||||
let progress_send = progress_sender.clone();
|
.run();
|
||||||
let progress_thread_run = progress_thread_run.clone();
|
match result {
|
||||||
let atomic_file_counter = atomic_file_counter.clone();
|
DirTraversalResult::SuccessFiles {
|
||||||
thread::spawn(move || loop {
|
start_time,
|
||||||
progress_send
|
grouped_file_entries,
|
||||||
.unbounded_send(ProgressData {
|
warnings,
|
||||||
current_stage: 0,
|
} => {
|
||||||
max_stage: 2,
|
if let Some(music_to_check) = grouped_file_entries.get(&()) {
|
||||||
music_checked: atomic_file_counter.load(Ordering::Relaxed) as usize,
|
self.music_to_check = music_to_check.clone();
|
||||||
music_to_check: 0,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
if !progress_thread_run.load(Ordering::Relaxed) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
sleep(Duration::from_millis(LOOP_DURATION as u64));
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
thread::spawn(|| {})
|
|
||||||
};
|
|
||||||
//// PROGRESS THREAD END
|
|
||||||
|
|
||||||
while !folders_to_check.is_empty() {
|
|
||||||
if stop_receiver.is_some() && stop_receiver.unwrap().try_recv().is_ok() {
|
|
||||||
// End thread which send info to gui
|
|
||||||
progress_thread_run.store(false, Ordering::Relaxed);
|
|
||||||
progress_thread_handle.join().unwrap();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let segments: Vec<_> = folders_to_check
|
|
||||||
.par_iter()
|
|
||||||
.map(|current_folder| {
|
|
||||||
let mut dir_result = vec![];
|
|
||||||
let mut warnings = vec![];
|
|
||||||
let mut fe_result = vec![];
|
|
||||||
// Read current dir childrens
|
|
||||||
let read_dir = match fs::read_dir(¤t_folder) {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(e) => {
|
|
||||||
warnings.push(fl!(
|
|
||||||
"core_cannot_open_dir",
|
|
||||||
generate_translation_hashmap(vec![("dir", current_folder.display().to_string()), ("reason", e.to_string())])
|
|
||||||
));
|
|
||||||
return (dir_result, warnings, fe_result);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check every sub folder/file/link etc.
|
|
||||||
'dir: for entry in read_dir {
|
|
||||||
let entry_data = match entry {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(e) => {
|
|
||||||
warnings.push(fl!(
|
|
||||||
"core_cannot_read_entry_dir",
|
|
||||||
generate_translation_hashmap(vec![("dir", current_folder.display().to_string()), ("reason", e.to_string())])
|
|
||||||
));
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let metadata: Metadata = match entry_data.metadata() {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(e) => {
|
|
||||||
warnings.push(fl!(
|
|
||||||
"core_cannot_read_metadata_dir",
|
|
||||||
generate_translation_hashmap(vec![("dir", current_folder.display().to_string()), ("reason", e.to_string())])
|
|
||||||
));
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if metadata.is_dir() {
|
|
||||||
if !self.recursive_search {
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
let next_folder = current_folder.join(entry_data.file_name());
|
|
||||||
if self.directories.is_excluded(&next_folder) {
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.excluded_items.is_excluded(&next_folder) {
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir_result.push(next_folder);
|
|
||||||
} else if metadata.is_file() {
|
|
||||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
|
||||||
|
|
||||||
let file_name_lowercase: String = match entry_data.file_name().into_string() {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(_inspected) => {
|
|
||||||
warnings.push(fl!(
|
|
||||||
"core_file_not_utf8_name",
|
|
||||||
generate_translation_hashmap(vec![("name", entry_data.path().display().to_string())])
|
|
||||||
));
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.to_lowercase();
|
|
||||||
|
|
||||||
if !self.allowed_extensions.matches_filename(&file_name_lowercase) {
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.minimal_file_size..=self.maximal_file_size).contains(&metadata.len()) {
|
|
||||||
let current_file_name = current_folder.join(entry_data.file_name());
|
|
||||||
if self.excluded_items.is_excluded(¤t_file_name) {
|
|
||||||
continue 'dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creating new file entry
|
|
||||||
let fe: FileEntry = FileEntry {
|
|
||||||
size: metadata.len(),
|
|
||||||
path: current_file_name.clone(),
|
|
||||||
modified_date: match metadata.modified() {
|
|
||||||
Ok(t) => match t.duration_since(UNIX_EPOCH) {
|
|
||||||
Ok(d) => d.as_secs(),
|
|
||||||
Err(_inspected) => {
|
|
||||||
warnings.push(fl!(
|
|
||||||
"core_file_modified_before_epoch",
|
|
||||||
generate_translation_hashmap(vec![("name", current_file_name.display().to_string())])
|
|
||||||
));
|
|
||||||
0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
warnings.push(fl!(
|
|
||||||
"core_file_no_modification_date",
|
|
||||||
generate_translation_hashmap(vec![("name", current_file_name.display().to_string()), ("reason", e.to_string())])
|
|
||||||
));
|
|
||||||
0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title: "".to_string(),
|
|
||||||
|
|
||||||
artist: "".to_string(),
|
|
||||||
album_title: "".to_string(),
|
|
||||||
album_artist: "".to_string(),
|
|
||||||
year: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
fe_result.push(fe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(dir_result, warnings, fe_result)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Advance the frontier
|
|
||||||
folders_to_check.clear();
|
|
||||||
|
|
||||||
// Process collected data
|
|
||||||
for (segment, warnings, fe_result) in segments {
|
|
||||||
folders_to_check.extend(segment);
|
|
||||||
self.text_messages.warnings.extend(warnings);
|
self.text_messages.warnings.extend(warnings);
|
||||||
for fe in fe_result {
|
Common::print_time(start_time, SystemTime::now(), "check_files".to_string());
|
||||||
self.music_to_check.push(fe);
|
true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
DirTraversalResult::SuccessFolders { .. } => {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
DirTraversalResult::Stopped => false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// End thread which send info to gui
|
|
||||||
progress_thread_run.store(false, Ordering::Relaxed);
|
|
||||||
progress_thread_handle.join().unwrap();
|
|
||||||
|
|
||||||
Common::print_time(start_time, SystemTime::now(), "check_files".to_string());
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_records_multithreaded(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
fn check_records_multithreaded(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
||||||
|
@ -433,10 +289,11 @@ impl SameMusic {
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
progress_send
|
progress_send
|
||||||
.unbounded_send(ProgressData {
|
.unbounded_send(ProgressData {
|
||||||
|
checking_method: CheckingMethod::None,
|
||||||
current_stage: 1,
|
current_stage: 1,
|
||||||
max_stage: 2,
|
max_stage: 2,
|
||||||
music_checked: atomic_file_counter.load(Ordering::Relaxed) as usize,
|
entries_checked: atomic_file_counter.load(Ordering::Relaxed) as usize,
|
||||||
music_to_check,
|
entries_to_check: music_to_check,
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if !progress_thread_run.load(Ordering::Relaxed) {
|
if !progress_thread_run.load(Ordering::Relaxed) {
|
||||||
|
@ -449,16 +306,18 @@ impl SameMusic {
|
||||||
};
|
};
|
||||||
//// PROGRESS THREAD END
|
//// PROGRESS THREAD END
|
||||||
|
|
||||||
let vec_file_entry = self
|
// Clean for duplicate files
|
||||||
.music_to_check
|
let music_to_check = mem::take(&mut self.music_to_check);
|
||||||
.par_iter()
|
|
||||||
|
let vec_file_entry = music_to_check
|
||||||
|
.into_par_iter()
|
||||||
.map(|file_entry| {
|
.map(|file_entry| {
|
||||||
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
atomic_file_counter.fetch_add(1, Ordering::Relaxed);
|
||||||
if stop_receiver.is_some() && stop_receiver.unwrap().try_recv().is_ok() {
|
if stop_receiver.is_some() && stop_receiver.unwrap().try_recv().is_ok() {
|
||||||
check_was_breaked.store(true, Ordering::Relaxed);
|
check_was_breaked.store(true, Ordering::Relaxed);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut file_entry = file_entry.clone();
|
let mut file_entry = file_entry.into_music_entry();
|
||||||
|
|
||||||
let tag = match Tag::new().read_from_path(&file_entry.path) {
|
let tag = match Tag::new().read_from_path(&file_entry.path) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
@ -504,9 +363,6 @@ impl SameMusic {
|
||||||
|
|
||||||
Common::print_time(start_time, SystemTime::now(), "check_records_multithreaded".to_string());
|
Common::print_time(start_time, SystemTime::now(), "check_records_multithreaded".to_string());
|
||||||
|
|
||||||
// Clean for duplicate files
|
|
||||||
self.music_to_check.clear();
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
fn check_for_duplicates(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
fn check_for_duplicates(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
||||||
|
@ -529,10 +385,11 @@ impl SameMusic {
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
progress_send
|
progress_send
|
||||||
.unbounded_send(ProgressData {
|
.unbounded_send(ProgressData {
|
||||||
|
checking_method: CheckingMethod::None,
|
||||||
current_stage: 2,
|
current_stage: 2,
|
||||||
max_stage: 2,
|
max_stage: 2,
|
||||||
music_checked: atomic_file_counter.load(Ordering::Relaxed) as usize,
|
entries_checked: atomic_file_counter.load(Ordering::Relaxed) as usize,
|
||||||
music_to_check,
|
entries_to_check: music_to_check,
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if !progress_thread_run.load(Ordering::Relaxed) {
|
if !progress_thread_run.load(Ordering::Relaxed) {
|
||||||
|
@ -545,8 +402,8 @@ impl SameMusic {
|
||||||
};
|
};
|
||||||
//// PROGRESS THREAD END
|
//// PROGRESS THREAD END
|
||||||
|
|
||||||
let mut old_duplicates: Vec<Vec<FileEntry>> = vec![self.music_entries.clone()];
|
let mut old_duplicates: Vec<Vec<MusicEntry>> = vec![self.music_entries.clone()];
|
||||||
let mut new_duplicates: Vec<Vec<FileEntry>> = Vec::new();
|
let mut new_duplicates: Vec<Vec<MusicEntry>> = Vec::new();
|
||||||
|
|
||||||
if (self.music_similarity & MusicSimilarity::TITLE) == MusicSimilarity::TITLE {
|
if (self.music_similarity & MusicSimilarity::TITLE) == MusicSimilarity::TITLE {
|
||||||
for vec_file_entry in old_duplicates {
|
for vec_file_entry in old_duplicates {
|
||||||
|
@ -557,7 +414,7 @@ impl SameMusic {
|
||||||
progress_thread_handle.join().unwrap();
|
progress_thread_handle.join().unwrap();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = 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 {
|
if self.approximate_comparison {
|
||||||
|
@ -587,7 +444,7 @@ impl SameMusic {
|
||||||
progress_thread_handle.join().unwrap();
|
progress_thread_handle.join().unwrap();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
|
||||||
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 {
|
||||||
|
@ -617,7 +474,7 @@ impl SameMusic {
|
||||||
progress_thread_handle.join().unwrap();
|
progress_thread_handle.join().unwrap();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
|
||||||
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 {
|
||||||
|
@ -647,7 +504,7 @@ impl SameMusic {
|
||||||
progress_thread_handle.join().unwrap();
|
progress_thread_handle.join().unwrap();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut hash_map: BTreeMap<String, Vec<FileEntry>> = Default::default();
|
let mut hash_map: BTreeMap<String, Vec<MusicEntry>> = Default::default();
|
||||||
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 {
|
||||||
|
@ -677,7 +534,7 @@ impl SameMusic {
|
||||||
progress_thread_handle.join().unwrap();
|
progress_thread_handle.join().unwrap();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut hash_map: BTreeMap<i32, Vec<FileEntry>> = Default::default();
|
let mut hash_map: BTreeMap<i32, Vec<MusicEntry>> = Default::default();
|
||||||
for file_entry in vec_file_entry {
|
for file_entry in vec_file_entry {
|
||||||
let year = file_entry.year;
|
let year = file_entry.year;
|
||||||
if year != 0 {
|
if year != 0 {
|
||||||
|
@ -724,7 +581,7 @@ impl SameMusic {
|
||||||
Some((files_from_referenced_folders.pop().unwrap(), normal_files))
|
Some((files_from_referenced_folders.pop().unwrap(), normal_files))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<(FileEntry, Vec<FileEntry>)>>();
|
.collect::<Vec<(MusicEntry, Vec<MusicEntry>)>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.use_reference_folders {
|
if self.use_reference_folders {
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn connect_button_search(
|
||||||
futures_sender_empty_files: futures::channel::mpsc::UnboundedSender<common_dir_traversal::ProgressData>,
|
futures_sender_empty_files: futures::channel::mpsc::UnboundedSender<common_dir_traversal::ProgressData>,
|
||||||
futures_sender_empty_folder: futures::channel::mpsc::UnboundedSender<common_dir_traversal::ProgressData>,
|
futures_sender_empty_folder: futures::channel::mpsc::UnboundedSender<common_dir_traversal::ProgressData>,
|
||||||
futures_sender_big_file: futures::channel::mpsc::UnboundedSender<big_file::ProgressData>,
|
futures_sender_big_file: futures::channel::mpsc::UnboundedSender<big_file::ProgressData>,
|
||||||
futures_sender_same_music: futures::channel::mpsc::UnboundedSender<same_music::ProgressData>,
|
futures_sender_same_music: futures::channel::mpsc::UnboundedSender<common_dir_traversal::ProgressData>,
|
||||||
futures_sender_similar_images: futures::channel::mpsc::UnboundedSender<similar_images::ProgressData>,
|
futures_sender_similar_images: futures::channel::mpsc::UnboundedSender<similar_images::ProgressData>,
|
||||||
futures_sender_similar_videos: futures::channel::mpsc::UnboundedSender<similar_videos::ProgressData>,
|
futures_sender_similar_videos: futures::channel::mpsc::UnboundedSender<similar_videos::ProgressData>,
|
||||||
futures_sender_temporary: futures::channel::mpsc::UnboundedSender<temporary::ProgressData>,
|
futures_sender_temporary: futures::channel::mpsc::UnboundedSender<temporary::ProgressData>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use czkawka_core::{big_file, broken_files, common_dir_traversal, same_music, similar_images, similar_videos, temporary};
|
use czkawka_core::{big_file, broken_files, common_dir_traversal, similar_images, similar_videos, temporary};
|
||||||
|
|
||||||
use crate::fl;
|
use crate::fl;
|
||||||
use crate::gui_data::GuiData;
|
use crate::gui_data::GuiData;
|
||||||
|
@ -15,7 +15,7 @@ pub fn connect_progress_window(
|
||||||
mut futures_receiver_empty_files: futures::channel::mpsc::UnboundedReceiver<common_dir_traversal::ProgressData>,
|
mut futures_receiver_empty_files: futures::channel::mpsc::UnboundedReceiver<common_dir_traversal::ProgressData>,
|
||||||
mut futures_receiver_empty_folder: futures::channel::mpsc::UnboundedReceiver<common_dir_traversal::ProgressData>,
|
mut futures_receiver_empty_folder: futures::channel::mpsc::UnboundedReceiver<common_dir_traversal::ProgressData>,
|
||||||
mut futures_receiver_big_files: futures::channel::mpsc::UnboundedReceiver<big_file::ProgressData>,
|
mut futures_receiver_big_files: futures::channel::mpsc::UnboundedReceiver<big_file::ProgressData>,
|
||||||
mut futures_receiver_same_music: futures::channel::mpsc::UnboundedReceiver<same_music::ProgressData>,
|
mut futures_receiver_same_music: futures::channel::mpsc::UnboundedReceiver<common_dir_traversal::ProgressData>,
|
||||||
mut futures_receiver_similar_images: futures::channel::mpsc::UnboundedReceiver<similar_images::ProgressData>,
|
mut futures_receiver_similar_images: futures::channel::mpsc::UnboundedReceiver<similar_images::ProgressData>,
|
||||||
mut futures_receiver_similar_videos: futures::channel::mpsc::UnboundedReceiver<similar_videos::ProgressData>,
|
mut futures_receiver_similar_videos: futures::channel::mpsc::UnboundedReceiver<similar_videos::ProgressData>,
|
||||||
mut futures_receiver_temporary: futures::channel::mpsc::UnboundedReceiver<temporary::ProgressData>,
|
mut futures_receiver_temporary: futures::channel::mpsc::UnboundedReceiver<temporary::ProgressData>,
|
||||||
|
@ -182,18 +182,19 @@ pub fn connect_progress_window(
|
||||||
progress_bar_current_stage.hide();
|
progress_bar_current_stage.hide();
|
||||||
label_stage.set_text(&fl!(
|
label_stage.set_text(&fl!(
|
||||||
"progress_scanning_general_file",
|
"progress_scanning_general_file",
|
||||||
generate_translation_hashmap(vec![("file_number", item.music_checked.to_string())])
|
generate_translation_hashmap(vec![("file_number", item.entries_checked.to_string())])
|
||||||
));
|
));
|
||||||
taskbar_state.borrow().set_progress_state(TBPF_INDETERMINATE);
|
taskbar_state.borrow().set_progress_state(TBPF_INDETERMINATE);
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
progress_bar_current_stage.show();
|
progress_bar_current_stage.show();
|
||||||
if item.music_to_check != 0 {
|
if item.entries_to_check != 0 {
|
||||||
progress_bar_all_stages.set_fraction((1f64 + (item.music_checked) as f64 / item.music_to_check as f64) / (item.max_stage + 1) as f64);
|
progress_bar_all_stages.set_fraction((1f64 + (item.entries_checked) as f64 / item.entries_to_check as f64) / (item.max_stage + 1) as f64);
|
||||||
progress_bar_current_stage.set_fraction((item.music_checked) as f64 / item.music_to_check as f64);
|
progress_bar_current_stage.set_fraction((item.entries_checked) as f64 / item.entries_to_check as f64);
|
||||||
taskbar_state
|
taskbar_state.borrow().set_progress_value(
|
||||||
.borrow()
|
(item.entries_to_check + item.entries_checked) as u64,
|
||||||
.set_progress_value((item.music_to_check + item.music_checked) as u64, item.music_to_check as u64 * (item.max_stage + 1) as u64);
|
item.entries_to_check as u64 * (item.max_stage + 1) as u64,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
progress_bar_all_stages.set_fraction((1f64) / (item.max_stage + 1) as f64);
|
progress_bar_all_stages.set_fraction((1f64) / (item.max_stage + 1) as f64);
|
||||||
progress_bar_current_stage.set_fraction(0f64);
|
progress_bar_current_stage.set_fraction(0f64);
|
||||||
|
@ -201,16 +202,16 @@ pub fn connect_progress_window(
|
||||||
}
|
}
|
||||||
label_stage.set_text(&fl!(
|
label_stage.set_text(&fl!(
|
||||||
"progress_scanning_music_tags",
|
"progress_scanning_music_tags",
|
||||||
generate_translation_hashmap(vec![("file_checked", item.music_checked.to_string()), ("all_files", item.music_to_check.to_string())])
|
generate_translation_hashmap(vec![("file_checked", item.entries_checked.to_string()), ("all_files", item.entries_to_check.to_string())])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
if item.music_to_check != 0 {
|
if item.entries_to_check != 0 {
|
||||||
progress_bar_all_stages.set_fraction((2f64 + (item.music_checked) as f64 / item.music_to_check as f64) / (item.max_stage + 1) as f64);
|
progress_bar_all_stages.set_fraction((2f64 + (item.entries_checked) as f64 / item.entries_to_check as f64) / (item.max_stage + 1) as f64);
|
||||||
progress_bar_current_stage.set_fraction((item.music_checked) as f64 / item.music_to_check as f64);
|
progress_bar_current_stage.set_fraction((item.entries_checked) as f64 / item.entries_to_check as f64);
|
||||||
taskbar_state.borrow().set_progress_value(
|
taskbar_state.borrow().set_progress_value(
|
||||||
(2 * item.music_to_check + item.music_checked) as u64,
|
(2 * item.entries_to_check + item.entries_checked) as u64,
|
||||||
item.music_to_check as u64 * (item.max_stage + 1) as u64,
|
item.entries_to_check as u64 * (item.max_stage + 1) as u64,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
progress_bar_all_stages.set_fraction((2f64) / (item.max_stage + 1) as f64);
|
progress_bar_all_stages.set_fraction((2f64) / (item.max_stage + 1) as f64);
|
||||||
|
@ -219,7 +220,7 @@ pub fn connect_progress_window(
|
||||||
}
|
}
|
||||||
label_stage.set_text(&fl!(
|
label_stage.set_text(&fl!(
|
||||||
"progress_scanning_music_tags_end",
|
"progress_scanning_music_tags_end",
|
||||||
generate_translation_hashmap(vec![("file_checked", item.music_checked.to_string()), ("all_files", item.music_to_check.to_string())])
|
generate_translation_hashmap(vec![("file_checked", item.entries_checked.to_string()), ("all_files", item.entries_to_check.to_string())])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -101,8 +101,8 @@ fn main() {
|
||||||
futures::channel::mpsc::UnboundedReceiver<big_file::ProgressData>,
|
futures::channel::mpsc::UnboundedReceiver<big_file::ProgressData>,
|
||||||
) = futures::channel::mpsc::unbounded();
|
) = futures::channel::mpsc::unbounded();
|
||||||
let (futures_sender_same_music, futures_receiver_same_music): (
|
let (futures_sender_same_music, futures_receiver_same_music): (
|
||||||
futures::channel::mpsc::UnboundedSender<same_music::ProgressData>,
|
futures::channel::mpsc::UnboundedSender<common_dir_traversal::ProgressData>,
|
||||||
futures::channel::mpsc::UnboundedReceiver<same_music::ProgressData>,
|
futures::channel::mpsc::UnboundedReceiver<common_dir_traversal::ProgressData>,
|
||||||
) = futures::channel::mpsc::unbounded();
|
) = futures::channel::mpsc::unbounded();
|
||||||
let (futures_sender_similar_images, futures_receiver_similar_images): (
|
let (futures_sender_similar_images, futures_receiver_similar_images): (
|
||||||
futures::channel::mpsc::UnboundedSender<similar_images::ProgressData>,
|
futures::channel::mpsc::UnboundedSender<similar_images::ProgressData>,
|
||||||
|
|
Loading…
Reference in a new issue