natural sort on folder list, add advanced playlist gen to frontend

This commit is contained in:
jb-alvarado 2023-09-08 10:32:46 +02:00
parent 94fa75a23d
commit dfb9d2db9e
4 changed files with 10 additions and 7 deletions

1
Cargo.lock generated
View File

@ -1182,6 +1182,7 @@ dependencies = [
"ffprobe",
"file-rotate",
"lettre",
"lexical-sort",
"log",
"openssl",
"rand",

@ -1 +1 @@
Subproject commit 2f3234221a0aef8e70d9e2b5e9bbfb1fe51921fc
Subproject commit 2ca3aa73b2992f6997276f5c8fb906f9ee703bf2

View File

@ -14,6 +14,7 @@ crossbeam-channel = "0.5"
ffprobe = "0.3"
file-rotate = "0.7"
lettre = "0.10"
lexical-sort = "0.3"
log = "0.4"
rand = "0.8"
regex = "1"

View File

@ -11,6 +11,7 @@ use std::{
};
use chrono::Timelike;
use lexical_sort::natural_lexical_cmp;
use rand::{seq::SliceRandom, thread_rng, Rng};
use simplelog::*;
use walkdir::WalkDir;
@ -143,7 +144,7 @@ pub fn generate_from_template(
let mut index: usize = 0;
for source in template.sources {
let mut full_list = vec![];
let mut source_list = vec![];
let duration = (source.duration.hour() as f64 * 3600.0)
+ (source.duration.minute() as f64 * 60.0)
+ source.duration.second() as f64;
@ -160,18 +161,18 @@ pub fn generate_from_template(
.filter(|f| include_file_extension(config, f.path()))
{
let media = Media::new(0, &entry.path().to_string_lossy(), true);
full_list.push(media);
source_list.push(media);
}
}
let mut timed_list = if source.shuffle {
full_list.shuffle(&mut rng);
source_list.shuffle(&mut rng);
random_list(full_list, duration)
random_list(source_list, duration)
} else {
full_list.sort_by(|d1, d2| d1.source.cmp(&d2.source));
source_list.sort_by(|d1, d2| natural_lexical_cmp(&d1.source, &d2.source));
ordered_list(full_list, duration)
ordered_list(source_list, duration)
};
let total_length = sum_durations(&timed_list);