From f98665d992e3af91e52318e0c6e9334c891343bd Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 22 Feb 2025 11:30:51 +0100 Subject: refactor(yt/description): Move to the `comments` subdirectory --- yt/src/comments/description.rs | 43 +++++++++++++++++++++++++++++++++++++ yt/src/description/mod.rs | 48 ------------------------------------------ yt/src/main.rs | 3 +-- 3 files changed, 44 insertions(+), 50 deletions(-) create mode 100644 yt/src/comments/description.rs delete mode 100644 yt/src/description/mod.rs 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 +// 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 . + +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 { + 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("".to_owned())) +} diff --git a/yt/src/description/mod.rs b/yt/src/description/mod.rs deleted file mode 100644 index f31c027..0000000 --- a/yt/src/description/mod.rs +++ /dev/null @@ -1,48 +0,0 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz -// 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 . - -use crate::{ - App, - comments::output::display_fmt_and_less, - storage::video_database::{ - Video, - getters::{get_currently_playing_video, get_video_info_json}, - }, - 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 { - 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 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())) -} diff --git a/yt/src/main.rs b/yt/src/main.rs index ed24262..6106117 100644 --- a/yt/src/main.rs +++ b/yt/src/main.rs @@ -42,7 +42,6 @@ pub mod cache; pub mod comments; pub mod config; pub mod constants; -pub mod description; pub mod download; pub mod select; pub mod status; @@ -239,7 +238,7 @@ async fn main() -> Result<()> { comments::comments(&app).await?; } Command::Description {} => { - description::description(&app).await?; + comments::description(&app).await?; } } -- cgit 1.4.1