From dfb9d2db9edbd2f8300f5e572986fc3617f99dc8 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 8 Sep 2023 10:32:46 +0200 Subject: [PATCH] natural sort on folder list, add advanced playlist gen to frontend --- Cargo.lock | 1 + ffplayout-frontend | 2 +- lib/Cargo.toml | 1 + lib/src/utils/generator.rs | 13 +++++++------ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0488fab..53aaa62f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1182,6 +1182,7 @@ dependencies = [ "ffprobe", "file-rotate", "lettre", + "lexical-sort", "log", "openssl", "rand", diff --git a/ffplayout-frontend b/ffplayout-frontend index 2f323422..2ca3aa73 160000 --- a/ffplayout-frontend +++ b/ffplayout-frontend @@ -1 +1 @@ -Subproject commit 2f3234221a0aef8e70d9e2b5e9bbfb1fe51921fc +Subproject commit 2ca3aa73b2992f6997276f5c8fb906f9ee703bf2 diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 74d1b8e8..72f85125 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -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" diff --git a/lib/src/utils/generator.rs b/lib/src/utils/generator.rs index 261defa7..f9088e46 100644 --- a/lib/src/utils/generator.rs +++ b/lib/src/utils/generator.rs @@ -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);