Skip to content

Commit

Permalink
7
Browse files Browse the repository at this point in the history
  • Loading branch information
THMonster committed Oct 16, 2023
1 parent 52e96c0 commit ea4ae97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/danmaku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
41 changes: 18 additions & 23 deletions src/dmlive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -144,24 +136,27 @@ impl DMLive {
}
}

pub async fn play(&self) -> anyhow::Result<bool> {
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<()> {
Expand Down

0 comments on commit ea4ae97

Please sign in to comment.