diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-09 19:10:29 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-09 19:10:29 +0200 |
| commit | aed6c78520dce5f875372c6338e1e89c564b5df1 (patch) | |
| tree | 929310d510b6c532d3e0a1b04e5386955b181234 /crates | |
| parent | fix(yt/db/insert/playlist): Always delete a video file, even when marked-picked (diff) | |
| download | yt-aed6c78520dce5f875372c6338e1e89c564b5df1.zip | |
feat(yt/commands/stats): Init basic framework
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/yt/src/commands/implm.rs | 1 | ||||
| -rw-r--r-- | crates/yt/src/commands/mod.rs | 12 | ||||
| -rw-r--r-- | crates/yt/src/commands/stats/implm.rs | 48 | ||||
| -rw-r--r-- | crates/yt/src/commands/stats/mod.rs | 16 |
4 files changed, 75 insertions, 2 deletions
diff --git a/crates/yt/src/commands/implm.rs b/crates/yt/src/commands/implm.rs index 7c60c6a..d8ef146 100644 --- a/crates/yt/src/commands/implm.rs +++ b/crates/yt/src/commands/implm.rs @@ -27,6 +27,7 @@ impl Command { } Command::Show { cmd } => cmd.implm(&app).await?, Command::Status { cmd } => cmd.implm(&app).await?, + Command::Stats { cmd } => cmd.implm(&app).await?, Command::Subscriptions { cmd } => cmd.implm(&app).await?, Command::Update { cmd } => cmd.implm(&app).await?, Command::Videos { cmd } => cmd.implm(&app).await?, diff --git a/crates/yt/src/commands/mod.rs b/crates/yt/src/commands/mod.rs index 234b5b3..5eb1fad 100644 --- a/crates/yt/src/commands/mod.rs +++ b/crates/yt/src/commands/mod.rs @@ -19,8 +19,9 @@ use crate::{ commands::{ cache::CacheCommand, config::ConfigCommand, database::DatabaseCommand, download::DownloadCommand, playlist::PlaylistCommand, select::SelectCommand, - show::ShowCommand, status::StatusCommand, subscriptions::SubscriptionCommand, - update::UpdateCommand, videos::VideosCommand, watch::WatchCommand, + show::ShowCommand, stats::StatsCommand, status::StatusCommand, + subscriptions::SubscriptionCommand, update::UpdateCommand, videos::VideosCommand, + watch::WatchCommand, }, config::Config, storage::db::subscription::{Subscription, Subscriptions}, @@ -35,6 +36,7 @@ mod download; mod playlist; mod select; mod show; +mod stats; mod status; mod subscriptions; mod update; @@ -93,6 +95,12 @@ pub(super) enum Command { cmd: StatusCommand, }, + /// Show general stats about your `yt` usage + Stats { + #[command(flatten)] + cmd: StatsCommand, + }, + /// Manipulate subscription #[command(visible_alias = "subs")] Subscriptions { diff --git a/crates/yt/src/commands/stats/implm.rs b/crates/yt/src/commands/stats/implm.rs new file mode 100644 index 0000000..3fc9afe --- /dev/null +++ b/crates/yt/src/commands/stats/implm.rs @@ -0,0 +1,48 @@ +// yt - A fully featured command line YouTube client +// +// Copyright (C) 2025 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::App, + commands::StatsCommand, + storage::db::{insert::video, txn_log::TxnLog}, +}; + +use anyhow::Result; + +macro_rules! sort_by_operation { + ($opts:expr, $operation:path) => { + { + let mut new = Vec::with_capacity($opts.inner().len()); + + for (ts, op) in $opts.inner() { + if matches!(op, $operation { .. }) { + new.push((ts, op)); + } + } + + new + } + } +} + +impl StatsCommand { + pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> { + let ops = TxnLog::<video::Operation>::get(app).await?; + + let only_add = sort_by_operation!(ops, video::Operation::Add); + + eprintln!("Number of operations: {}.", ops.inner().len()); + eprintln!("Number of added videos: {}.", only_add.len()); + + // TODO(@bpeetz): Also show watch-time over time, and move other things from `yt status` here. <2026-05-26> + + Ok(()) + } +} diff --git a/crates/yt/src/commands/stats/mod.rs b/crates/yt/src/commands/stats/mod.rs new file mode 100644 index 0000000..bd1eb9d --- /dev/null +++ b/crates/yt/src/commands/stats/mod.rs @@ -0,0 +1,16 @@ +// yt - A fully featured command line YouTube client +// +// Copyright (C) 2025 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 clap::Parser; + +mod implm; + +#[derive(Parser, Debug)] +pub(super) struct StatsCommand {} |
