diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-21 10:49:23 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-21 11:28:43 +0200 |
commit | 1debeb77f7986de1b659dcfdc442de6415e1d9f5 (patch) | |
tree | 4df3e7c3f6a2d1ec116e4088c5ace7f143a8b05f /src/status/mod.rs | |
download | yt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.tar.gz yt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.zip |
chore: Initial Commit
This repository was migrated out of my nixos-config.
Diffstat (limited to 'src/status/mod.rs')
-rw-r--r-- | src/status/mod.rs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/status/mod.rs b/src/status/mod.rs new file mode 100644 index 0000000..1b24279 --- /dev/null +++ b/src/status/mod.rs @@ -0,0 +1,91 @@ +// 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 anyhow::Result; + +use crate::{ + app::App, + storage::{ + subscriptions::get_subscriptions, + video_database::{getters::get_videos, Video, VideoStatus}, + }, +}; + +macro_rules! get { + ($videos:expr, $status:ident) => { + $videos + .iter() + .filter(|vid| vid.status == VideoStatus::$status) + .collect::<Vec<&Video>>() + }; + (@changing $videos:expr, $status:ident) => { + $videos + .iter() + .filter(|vid| vid.status == VideoStatus::$status && vid.status_change) + .collect::<Vec<&Video>>() + }; +} + +pub async fn show(app: &App) -> Result<()> { + let all_videos = get_videos( + app, + &[ + VideoStatus::Pick, + // + VideoStatus::Watch, + VideoStatus::Cached, + VideoStatus::Watched, + // + VideoStatus::Drop, + VideoStatus::Dropped, + ], + None, + ) + .await?; + + // lengths + let picked_videos_len = (get!(all_videos, Pick)).len(); + + let watch_videos_len = (get!(all_videos, Watch)).len(); + let cached_videos_len = (get!(all_videos, Cached)).len(); + let watched_videos_len = (get!(all_videos, Watched)).len(); + + let drop_videos_len = (get!(all_videos, Drop)).len(); + let dropped_videos_len = (get!(all_videos, Dropped)).len(); + + // changing + let picked_videos_changing = (get!(@changing all_videos, Pick)).len(); + + let watch_videos_changing = (get!(@changing all_videos, Watch)).len(); + let cached_videos_changing = (get!(@changing all_videos, Cached)).len(); + let watched_videos_changing = (get!(@changing all_videos, Watched)).len(); + + let drop_videos_changing = (get!(@changing all_videos, Drop)).len(); + let dropped_videos_changing = (get!(@changing all_videos, Dropped)).len(); + + let subscriptions = get_subscriptions(&app).await?; + let subscriptions_len = subscriptions.0.len(); + println!( + "\ +Picked Videos: {picked_videos_len} ({picked_videos_changing} changing) + +Watch Videos: {watch_videos_len} ({watch_videos_changing} changing) +Cached Videos: {cached_videos_len} ({cached_videos_changing} changing) +Watched Videos: {watched_videos_len} ({watched_videos_changing} changing) + +Drop Videos: {drop_videos_len} ({drop_videos_changing} changing) +Dropped Videos: {dropped_videos_len} ({dropped_videos_changing} changing) + + + Subscriptions: {subscriptions_len}" + ); + + Ok(()) +} |