diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/watch/events.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/watch/events.rs b/src/watch/events.rs index 9ba26cd..c9f8373 100644 --- a/src/watch/events.rs +++ b/src/watch/events.rs @@ -42,12 +42,12 @@ impl MpvEventHandler { } /// Checks, whether new videos are ready to be played - pub async fn possibly_add_new_videos(&mut self, app: &App, mpv: &Mpv) -> Result<()> { + pub async fn possibly_add_new_videos(&mut self, app: &App, mpv: &Mpv) -> Result<usize> { let play_things = get_videos(app, &[VideoStatus::Cached], Some(false)).await?; // There is nothing to watch if play_things.len() == 0 { - return Ok(()); + return Ok(0); } let play_things = play_things @@ -62,6 +62,7 @@ impl MpvEventHandler { self.current_playlist.reserve(play_things.len()); + let num = play_things.len(); for play_thing in play_things { debug!("Adding '{}' to playlist.", play_thing.title); @@ -75,11 +76,17 @@ impl MpvEventHandler { self.current_playlist.push(play_thing.extractor_hash); } + Ok(num) + } + + fn message(mpv: &Mpv, message: &str, time: &str) -> Result<()> { + mpv.execute("show-text", &[format!("\"{}\"", message).as_str(), time])?; Ok(()) } async fn mark_video_watched(&mut self, app: &App, hash: &ExtractorHash) -> Result<()> { let video = get_video_by_hash(app, hash).await?; + debug!("MPV handler will mark video '{}' watched.", video.title); set_video_watched(&app, &video).await?; Ok(()) } @@ -215,25 +222,29 @@ impl MpvEventHandler { .take(app.config.watch.local_comments_length) .collect(); - mpv.execute("show-text", &[&format!("'{}'", comments), "6000"])?; + Self::message(mpv, &comments, "6000")?; } &["yt-description"] => { // let description = description(app).await?; - mpv.execute("script-message", &["osc-message", "'<YT Description>'"])?; + Self::message(&mpv, "<YT Description>", "6000")?; } &["yt-mark-watch-later"] => { self.mark_cvideo_inactive(app).await?; mpv.execute("write-watch-later-config", &[])?; mpv.execute("playlist-remove", &["current"])?; + + Self::message(&mpv, "Marked the video to be watched later", "3000")?; } &["yt-mark-done-and-go-next"] => { - self.mark_cvideo_inactive(app).await?; self.mark_cvideo_watched(app).await?; + self.mark_cvideo_inactive(app).await?; mpv.execute("playlist-remove", &["current"])?; + Self::message(&mpv, "Marked the video watched", "3000")?; } &["yt-check-new-videos"] => { - self.possibly_add_new_videos(app, mpv).await?; + let num = self.possibly_add_new_videos(app, mpv).await?; + Self::message(&mpv, format!("Added {} videos", num).as_str(), "3000")?; } other => { debug!("Unknown message: {}", other.join(" ")) |