1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// 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::{Context, Result};
use bytes::Bytes;
use crate::{
app::App,
download::Downloader,
storage::{
subscriptions::get_subscriptions,
video_database::{getters::get_videos, VideoStatus},
},
};
macro_rules! get {
($videos:expr, $status:ident) => {
$videos
.iter()
.filter(|vid| vid.status == VideoStatus::$status)
.count()
};
(@changing $videos:expr, $status:ident) => {
$videos
.iter()
.filter(|vid| vid.status == VideoStatus::$status && vid.status_change)
.count()
};
}
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);
let watch_videos_len = get!(all_videos, Watch);
let cached_videos_len = get!(all_videos, Cached);
let watched_videos_len = get!(all_videos, Watched);
let drop_videos_len = get!(all_videos, Drop);
let dropped_videos_len = get!(all_videos, Dropped);
// changing
let picked_videos_changing = get!(@changing all_videos, Pick);
let watch_videos_changing = get!(@changing all_videos, Watch);
let cached_videos_changing = get!(@changing all_videos, Cached);
let watched_videos_changing = get!(@changing all_videos, Watched);
let drop_videos_changing = get!(@changing all_videos, Drop);
let dropped_videos_changing = get!(@changing all_videos, Dropped);
let subscriptions = get_subscriptions(&app).await?;
let subscriptions_len = subscriptions.0.len();
let cache_usage_raw = Downloader::get_current_cache_allocation(app)
.await
.context("Failed to get current cache allocation")?;
let cache_usage = Bytes::new(cache_usage_raw);
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}
Cache usage: {cache_usage}"
);
Ok(())
}
pub fn config(app: &App) -> Result<()> {
let config_str = toml::to_string(&app.config)?;
print!("{}", config_str);
Ok(())
}
|