From 7105c4f672456a2b928279a6f24b97d2ebf65a54 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 14 Dec 2024 12:47:18 +0100 Subject: refactor(yt/description): Provide `get` function, returning a string This allows code to get the description without shelling out. --- yt/src/description/mod.rs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/yt/src/description/mod.rs b/yt/src/description/mod.rs index 527fa8e..10f0e0c 100644 --- a/yt/src/description/mod.rs +++ b/yt/src/description/mod.rs @@ -22,26 +22,27 @@ use anyhow::{bail, Result}; use yt_dlp::wrapper::info_json::InfoJson; pub async fn description(app: &App) -> Result<()> { - let description = { - let currently_playing_video: Video = - if let Some(video) = get_currently_playing_video(app).await? { - video - } else { - bail!("Could not find a currently playing video!"); - }; + let description = get(app).await?; + display_fmt_and_less(description).await?; - let info_json: InfoJson = get_video_info_json(¤tly_playing_video) - .await? - .unreachable( - "A currently *playing* must be cached. And thus the info.json should be available", - ); + Ok(()) +} - info_json - .description - .unwrap_or("".to_owned()) - }; +pub async fn get(app: &App) -> Result { + let currently_playing_video: Video = + if let Some(video) = get_currently_playing_video(app).await? { + video + } else { + bail!("Could not find a currently playing video!"); + }; - display_fmt_and_less(description).await?; + let info_json: InfoJson = get_video_info_json(¤tly_playing_video) + .await? + .unreachable( + "A currently *playing* must be cached. And thus the info.json should be available", + ); - Ok(()) + Ok(info_json + .description + .unwrap_or("".to_owned())) } -- cgit 1.4.1