update packages, delete hls files, when free space is under 1GB
This commit is contained in:
parent
13cf6d2f08
commit
c02a13b392
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -1859,9 +1859,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.21"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"sval",
|
||||
@ -2021,9 +2021,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7"
|
||||
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
|
@ -54,7 +54,7 @@ serde_json = "1.0"
|
||||
serde_with = "3.8"
|
||||
shlex = "1.1"
|
||||
static-files = "0.2"
|
||||
sysinfo ={ version = "0.30", features = ["linux-netdevs"] }
|
||||
sysinfo ={ version = "0.30", features = ["linux-netdevs", "linux-tmpfs"] }
|
||||
sqlx = { version = "0.7", features = ["runtime-tokio", "sqlite"] }
|
||||
time = { version = "0.3", features = ["formatting", "macros"] }
|
||||
tokio = { version = "1.29", features = ["full"] }
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
fmt,
|
||||
fmt, fs, io,
|
||||
path::Path,
|
||||
process::Child,
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
@ -12,8 +13,11 @@ use std::{
|
||||
use signal_child::Signalable;
|
||||
|
||||
use log::*;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use sysinfo::Disks;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::player::{
|
||||
output::{player, write_hls},
|
||||
@ -330,6 +334,12 @@ pub fn start_channel(manager: ChannelManager) -> Result<(), ProcessError> {
|
||||
let filler_list = manager.filler_list.clone();
|
||||
let channel_id = config.general.channel_id;
|
||||
|
||||
drain_hls_path(
|
||||
&config.global.hls_path,
|
||||
&config.output.output_cmd.clone().unwrap_or_default(),
|
||||
channel_id,
|
||||
)?;
|
||||
|
||||
debug!(target: Target::all(), channel = channel_id; "Start ffplayout v{VERSION}, channel: <yellow>{channel_id}</>");
|
||||
|
||||
// Fill filler list, can also be a single file.
|
||||
@ -344,3 +354,57 @@ pub fn start_channel(manager: ChannelManager) -> Result<(), ProcessError> {
|
||||
_ => player(manager),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drain_hls_path(path: &Path, params: &Vec<String>, channel_id: i32) -> io::Result<()> {
|
||||
let disks = Disks::new_with_refreshed_list();
|
||||
// 1059061760
|
||||
// 1000000000
|
||||
|
||||
for disk in &disks {
|
||||
if disk.mount_point().to_string_lossy().len() > 1
|
||||
&& path.starts_with(disk.mount_point())
|
||||
&& disk.available_space() < 1073741824
|
||||
&& path.is_dir()
|
||||
{
|
||||
warn!(target: Target::file_mail(), channel = channel_id; "HLS storage space is less then 1GB, drain TS files...");
|
||||
delete_ts(path, params)?
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn delete_ts<P: AsRef<Path> + Clone + std::fmt::Debug>(
|
||||
path: P,
|
||||
params: &Vec<String>,
|
||||
) -> io::Result<()> {
|
||||
let ts_file = params
|
||||
.iter()
|
||||
.filter(|f| f.to_lowercase().ends_with(".ts") || f.to_lowercase().ends_with(".m3u8"))
|
||||
.collect::<Vec<&String>>();
|
||||
|
||||
for entry in WalkDir::new(path.clone())
|
||||
.into_iter()
|
||||
.flat_map(|e| e.ok())
|
||||
.filter(|f| f.path().is_file())
|
||||
.filter(|f| paths_match(&ts_file, &f.path().to_string_lossy()))
|
||||
.map(|p| p.path().to_string_lossy().to_string())
|
||||
{
|
||||
fs::remove_file(entry)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn paths_match(patterns: &Vec<&String>, actual_path: &str) -> bool {
|
||||
for pattern in patterns {
|
||||
let pattern_escaped = regex::escape(&pattern);
|
||||
let pattern_regex = pattern_escaped.replace(r"%d", r"\d+");
|
||||
let re = Regex::new(&pattern_regex).unwrap();
|
||||
|
||||
if re.is_match(actual_path) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -167,6 +167,7 @@ pub struct PlayoutConfig {
|
||||
pub storage: Storage,
|
||||
pub text: Text,
|
||||
pub task: Task,
|
||||
#[serde(alias = "out")]
|
||||
pub output: Output,
|
||||
}
|
||||
|
||||
@ -578,6 +579,7 @@ impl PlayoutConfig {
|
||||
|
||||
if channel_id > 1 || !global.shared_storage {
|
||||
global.playlist_path = global.playlist_path.join(channel_id.to_string());
|
||||
global.hls_path = global.hls_path.join(channel_id.to_string());
|
||||
}
|
||||
|
||||
if !global.playlist_path.is_dir() {
|
||||
|
2
frontend
2
frontend
@ -1 +1 @@
|
||||
Subproject commit 761e2816f94a98dd8d400320555c84b99813e1ce
|
||||
Subproject commit ec05d1e3ef0ffe120edea1ddf286b9c64ae550e5
|
Loading…
Reference in New Issue
Block a user