diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-14 12:47:18 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-14 12:58:46 +0100 |
commit | 7105c4f672456a2b928279a6f24b97d2ebf65a54 (patch) | |
tree | 755a1008eb84e627c561c31405de26bca3fc37bb | |
parent | refactor(yt/config): Rename `local_comments_length` to `local_display_length` (diff) | |
download | yt-7105c4f672456a2b928279a6f24b97d2ebf65a54.tar.gz yt-7105c4f672456a2b928279a6f24b97d2ebf65a54.zip |
refactor(yt/description): Provide `get` function, returning a string
This allows code to get the description without shelling out.
-rw-r--r-- | yt/src/description/mod.rs | 37 |
1 files 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("<No description>".to_owned()) - }; +pub async fn get(app: &App) -> Result<String> { + 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("<No description>".to_owned())) } |