diff options
Diffstat (limited to 'yt/src/comments')
| -rw-r--r-- | yt/src/comments/description.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/yt/src/comments/description.rs b/yt/src/comments/description.rs new file mode 100644 index 0000000..e743e46 --- /dev/null +++ b/yt/src/comments/description.rs @@ -0,0 +1,43 @@ +// yt - A fully featured command line YouTube client +// +// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> +// SPDX-License-Identifier: GPL-3.0-or-later +// +// This file is part of Yt. +// +// You should have received a copy of the License along with this program. +// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +use crate::{ + App, + comments::output::display_fmt_and_less, + storage::video_database::{Video, get}, + unreachable::Unreachable, +}; + +use anyhow::{Result, bail}; +use yt_dlp::wrapper::info_json::InfoJson; + +pub async fn description(app: &App) -> Result<()> { + let description = get(app).await?; + display_fmt_and_less(description).await?; + + Ok(()) +} + +pub async fn get(app: &App) -> Result<String> { + let currently_playing_video: Video = + if let Some(video) = get::currently_focused_video(app).await? { + video + } else { + bail!("Could not find a currently playing video!"); + }; + + let info_json: InfoJson = get::video_info_json(¤tly_playing_video)?.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())) +} |
