aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-14 12:49:07 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-14 12:58:47 +0100
commit5133e7e1be3e581ee9853a59f7d05e29900f9458 (patch)
tree779e20981d4a0f07eb103cbdffb25d22cb9eb89b
parentrefactor(yt/description): Provide `get` function, returning a string (diff)
downloadyt-5133e7e1be3e581ee9853a59f7d05e29900f9458.zip
feat(yt/watch/events): Wire up the `yt-description-*` client commands
-rw-r--r--yt/src/watch/events/handlers/mod.rs41
-rw-r--r--yt/src/watch/events/mod.rs10
2 files changed, 38 insertions, 13 deletions
diff --git a/yt/src/watch/events/handlers/mod.rs b/yt/src/watch/events/handlers/mod.rs
index 3215fff..715896d 100644
--- a/yt/src/watch/events/handlers/mod.rs
+++ b/yt/src/watch/events/handlers/mod.rs
@@ -10,7 +10,7 @@
use std::{env::current_exe, mem};
-use crate::{app::App, comments, storage::video_database::setters::set_state_change};
+use crate::{app::App, comments, description, storage::video_database::setters::set_state_change};
use super::MpvEventHandler;
@@ -94,7 +94,7 @@ impl MpvEventHandler {
// }}}
// ClientMessage {{{
- pub async fn handle_client_message_yt_comments_external(app: &App) -> Result<()> {
+ async fn run_self_in_external_command(app: &App, args: &[&str]) -> Result<()> {
let binary =
current_exe().context("Failed to determine the current executable to re-execute")?;
@@ -106,8 +106,8 @@ impl MpvEventHandler {
bail!("focusing the next output failed!");
}
- let status = Command::new("alacritty")
- .args([
+ let arguments = [
+ &[
"--title",
"floating please",
"--command",
@@ -120,10 +120,12 @@ impl MpvEventHandler {
.database_path
.to_str()
.context("Failed to parse the database_path as a utf8-string")?,
- "comments",
- ])
- .status()
- .await?;
+ ],
+ args,
+ ]
+ .concat();
+
+ let status = Command::new("alacritty").args(arguments).status().await?;
if !status.success() {
bail!("Falied to start `yt comments`");
}
@@ -139,13 +141,34 @@ impl MpvEventHandler {
Ok(())
}
+
+ pub async fn handle_client_message_yt_description_external(app: &App) -> Result<()> {
+ Self::run_self_in_external_command(app, &["description"]).await?;
+ Ok(())
+ }
+ pub async fn handle_client_message_yt_description_local(app: &App, mpv: &Mpv) -> Result<()> {
+ let description: String = description::get(app)
+ .await?
+ .replace(['"', '\''], "")
+ .chars()
+ .take(app.config.watch.local_displays_length)
+ .collect();
+
+ Self::message(mpv, &description, "6000")?;
+ Ok(())
+ }
+
+ pub async fn handle_client_message_yt_comments_external(app: &App) -> Result<()> {
+ Self::run_self_in_external_command(app, &["comments"]).await?;
+ Ok(())
+ }
pub async fn handle_client_message_yt_comments_local(app: &App, mpv: &Mpv) -> Result<()> {
let comments: String = comments::get(app)
.await?
.render(false)
.replace(['"', '\''], "")
.chars()
- .take(app.config.watch.local_comments_length)
+ .take(app.config.watch.local_displays_length)
.collect();
Self::message(mpv, &comments, "6000")?;
diff --git a/yt/src/watch/events/mod.rs b/yt/src/watch/events/mod.rs
index d2a94a0..2f74639 100644
--- a/yt/src/watch/events/mod.rs
+++ b/yt/src/watch/events/mod.rs
@@ -146,7 +146,7 @@ impl MpvEventHandler {
let playlist_position = {
let raw = mpv.get_property::<i64>("playlist-pos")?;
if raw == -1 {
- unreachable!( "This should only be called when a current video exists. Current state: '{:#?}'", self);
+ unreachable!("Tried to get the currently playing video hash, but failed to access the mpv 'playlist-pos' property! This is a bug, as this function should only be called, when a current video exists. Current state: '{:#?}'", self);
} else {
usize::try_from(raw + offset).with_context(|| format!("Failed to calculate playlist position because of usize overflow: '{raw} + {offset}'"))?
}
@@ -291,9 +291,11 @@ impl MpvEventHandler {
&["yt-comments-local"] => {
Self::handle_client_message_yt_comments_local(app, mpv).await?;
}
- &["yt-description"] => {
- // let description = description(app).await?;
- Self::message(mpv, "<YT Description>", "6000")?;
+ &["yt-description-external"] => {
+ Self::handle_client_message_yt_description_external(app).await?;
+ },
+ &["yt-description-local"] => {
+ Self::handle_client_message_yt_description_local(app, mpv).await?;
}
&["yt-mark-watch-later"] => {
self.handle_client_message_yt_mark_watch_later(mpv)?;