fix ordered sort

This commit is contained in:
jb-alvarado 2023-09-08 11:32:12 +02:00
parent dfb9d2db9e
commit 467a562867

View File

@ -11,7 +11,7 @@ use std::{
}; };
use chrono::Timelike; use chrono::Timelike;
use lexical_sort::natural_lexical_cmp; use lexical_sort::{natural_lexical_cmp, StringSort};
use rand::{seq::SliceRandom, thread_rng, Rng}; use rand::{seq::SliceRandom, thread_rng, Rng};
use simplelog::*; use simplelog::*;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -154,13 +154,20 @@ pub fn generate_from_template(
for path in source.paths { for path in source.paths {
debug!("Search files in <b><magenta>{path:?}</></b>"); debug!("Search files in <b><magenta>{path:?}</></b>");
for entry in WalkDir::new(path) let mut file_list = WalkDir::new(path.clone())
.into_iter() .into_iter()
.flat_map(|e| e.ok()) .flat_map(|e| e.ok())
.filter(|f| f.path().is_file()) .filter(|f| f.path().is_file())
.filter(|f| include_file_extension(config, f.path())) .filter(|f| include_file_extension(config, f.path()))
{ .map(|p| p.path().to_string_lossy().to_string())
let media = Media::new(0, &entry.path().to_string_lossy(), true); .collect::<Vec<String>>();
if !source.shuffle {
file_list.string_sort_unstable(natural_lexical_cmp);
}
for entry in file_list {
let media = Media::new(0, &entry, true);
source_list.push(media); source_list.push(media);
} }
} }
@ -170,8 +177,6 @@ pub fn generate_from_template(
random_list(source_list, duration) random_list(source_list, duration)
} else { } else {
source_list.sort_by(|d1, d2| natural_lexical_cmp(&d1.source, &d2.source));
ordered_list(source_list, duration) ordered_list(source_list, duration)
}; };