diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 00000000..79251f51 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,22 @@ +name: Rust + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 97006783..7c79fce8 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -155,14 +155,18 @@ fn overlay(node: &mut Media, chain: &mut Filters, config: &GlobalConfig) { config.processing.logo ); - if node.last_ad.unwrap() { - logo_chain.push_str(",fade=in:st=0:d=1.0:alpha=1") + if let Some(last) = &node.last { + if last.category == "advertisement" { + logo_chain.push_str(",fade=in:st=0:d=1.0:alpha=1") + } } - if node.next_ad.unwrap() { - logo_chain.push_str( - format!(",fade=out:st={}:d=1.0:alpha=1", node.out - node.seek - 1.0).as_str(), - ) + if let Some(next) = &node.next { + if next.category == "advertisement" { + logo_chain.push_str( + format!(",fade=out:st={}:d=1.0:alpha=1", node.out - node.seek - 1.0).as_str(), + ) + } } logo_chain diff --git a/src/input/playlist.rs b/src/input/playlist.rs index 73333967..b5e9d32f 100644 --- a/src/input/playlist.rs +++ b/src/input/playlist.rs @@ -7,8 +7,8 @@ use simplelog::*; use tokio::runtime::Handle; use crate::utils::{ - check_sync, gen_dummy, get_delta, get_sec, is_close, json_reader::read_json, - modified_time, seek_and_length, GlobalConfig, Media, DUMMY_LEN, + check_sync, gen_dummy, get_delta, get_sec, is_close, json_reader::read_json, modified_time, + seek_and_length, GlobalConfig, Media, DUMMY_LEN, }; #[derive(Debug)] @@ -142,23 +142,13 @@ impl CurrentProgram { } } - fn is_ad(&mut self, i: usize, next: bool) -> Option { - if next { - if i + 1 < self.nodes.len() && self.nodes[i + 1].category == "advertisement".to_string() - { - return Some(true); - } else { - return Some(false); - } - } else { - if i > 0 - && i < self.nodes.len() - && self.nodes[i - 1].category == "advertisement".to_string() - { - return Some(true); - } else { - return Some(false); - } + fn last_next_node(&mut self) { + if self.index + 1 < self.nodes.len() { + self.current_node.next = Some(Box::new(self.nodes[self.index + 1].clone())); + } + + if self.index > 0 && self.index < self.nodes.len() { + self.current_node.last = Some(Box::new(self.nodes[self.index - 1].clone())); } } @@ -252,8 +242,7 @@ impl Iterator for CurrentProgram { } } - self.current_node.last_ad = self.is_ad(self.index, false); - self.current_node.next_ad = self.is_ad(self.index, true); + self.last_next_node(); return Some(self.current_node.clone()); } @@ -267,8 +256,7 @@ impl Iterator for CurrentProgram { } self.current_node = timed_source(self.nodes[self.index].clone(), &self.config, is_last); - self.current_node.last_ad = self.is_ad(self.index, false); - self.current_node.next_ad = self.is_ad(self.index, true); + self.last_next_node(); self.index += 1; // update playlist should happen after current clip, @@ -277,9 +265,9 @@ impl Iterator for CurrentProgram { Some(self.current_node.clone()) } else { let last_playlist = self.json_path.clone(); + let last = self.current_node.clone(); self.check_for_next_playlist(); let (_, total_delta) = get_delta(&self.config.playlist.start_sec.unwrap()); - let mut last_ad = self.is_ad(self.index, false); if last_playlist == self.json_path && total_delta.abs() > self.config.general.stop_threshold @@ -299,16 +287,16 @@ impl Iterator for CurrentProgram { self.current_node = gen_source(self.current_node.clone()); self.nodes.push(self.current_node.clone()); - last_ad = self.is_ad(self.index, false); - self.current_node.last_ad = last_ad; + self.current_node.last = Some(Box::new(last)); self.current_node.add_filter(); return Some(self.current_node.clone()); } - self.current_node = gen_source(self.nodes[0].clone()); - self.current_node.last_ad = last_ad; - self.current_node.next_ad = self.is_ad(0, true); + self.index = 0; + self.current_node = gen_source(self.nodes[self.index].clone()); + self.last_next_node(); + self.current_node.last = Some(Box::new(last)); self.index = 1; diff --git a/src/output/mod.rs b/src/output/mod.rs index 0ba5a797..0849a5fd 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -172,6 +172,7 @@ pub fn player(rt_handle: &Handle, is_terminated: Arc>) { ProcessCleanup::new(server_term.clone(), is_terminated.clone(), enc_proc); 'source_iter: for node in get_source { + println!("{:?}", &node.clone()); let cmd = match node.cmd { Some(cmd) => cmd, None => break, diff --git a/src/utils/json_reader.rs b/src/utils/json_reader.rs index 8fcd8697..a08a83fc 100644 --- a/src/utils/json_reader.rs +++ b/src/utils/json_reader.rs @@ -93,8 +93,6 @@ pub fn read_json( for (i, item) in playlist.program.iter_mut().enumerate() { item.begin = Some(start_sec); item.index = Some(i); - item.last_ad = Some(false); - item.next_ad = Some(false); item.process = Some(true); item.filter = Some(vec![]); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a822fad0..1b046f54 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -42,8 +42,8 @@ pub struct Media { pub cmd: Option>, pub filter: Option>, pub probe: Option, - pub last_ad: Option, - pub next_ad: Option, + pub last: Option>, + pub next: Option>, pub process: Option, } @@ -72,8 +72,8 @@ impl Media { cmd: Some(vec!["-i".to_string(), src]), filter: Some(vec![]), probe: probe, - last_ad: Some(false), - next_ad: Some(false), + last: None, + next: None, process: Some(true), } }