diff --git a/src/danmaku/mod.rs b/src/danmaku/mod.rs index 45f2152..fa82211 100644 --- a/src/danmaku/mod.rs +++ b/src/danmaku/mod.rs @@ -290,8 +290,8 @@ impl Danmaku { let mut printed = false; while launch { let (co, ni, da) = dm_queue.get(0).ok_or_else(|| launch = false).unwrap_or(&empty_dm); - if !da.is_empty() { - if !self.cm.quiet && !printed { + if !da.is_empty() && !printed { + if !self.cm.quiet { println!("[{}] {}", &ni, &da); printed = true; } diff --git a/src/dmlive.rs b/src/dmlive.rs index aa776f7..fb28ff2 100644 --- a/src/dmlive.rs +++ b/src/dmlive.rs @@ -59,18 +59,10 @@ impl DMLive { let signal_task = async { let _ = tokio::signal::ctrl_c().await; }; - let play_task = async { - loop { - if self.play().await.map_err(|e| info!("play error: {}", e)).unwrap_or(false) { - break; - } - tokio::time::sleep(Duration::from_millis(1000)).await; - } - }; tokio::select! { _ = self.dispatch_task() => {}, _ = self.mc.run() => {}, - _ = play_task => {}, + _ = self.play() => {}, _ = signal_task => {}, } match self.ipc_manager.stop().await { @@ -144,24 +136,27 @@ impl DMLive { } } - pub async fn play(&self) -> anyhow::Result { - match self.cm.run_mode { - crate::config::RunMode::Play => { - if matches!(self.cm.site, crate::config::Site::BiliVideo) { - self.play_video().await?; - tokio::time::sleep(Duration::from_secs(u64::MAX)).await; - } else { - self.play_live().await?; + pub async fn play(&self) -> anyhow::Result<()> { + loop { + match self.cm.run_mode { + crate::config::RunMode::Play => { + if matches!(self.cm.site, crate::config::Site::BiliVideo) { + self.play_video().await?; + tokio::time::sleep(Duration::from_secs(u64::MAX)).await; + } else { + self.play_live().await?; + } } - } - crate::config::RunMode::Record => { - self.play_live().await?; - if matches!(self.cm.site, crate::config::Site::BiliVideo) { - return Ok(true); + crate::config::RunMode::Record => { + self.play_live().await?; + if matches!(self.cm.site, crate::config::Site::BiliVideo) { + return Err(anyhow::anyhow!("recording finished")); + } } } + tokio::time::sleep(Duration::from_millis(1000)).await; } - Ok(false) + // Ok(()) } pub async fn play_live(&self) -> anyhow::Result<()> {