aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crates/yt/src/commands/cache/implm.rs30
-rw-r--r--crates/yt/src/commands/cache/mod.rs9
-rw-r--r--crates/yt/src/commands/implm.rs1
-rw-r--r--crates/yt/src/commands/mod.rs15
-rw-r--r--crates/yt/tests/videos/downloading.rs2
5 files changed, 52 insertions, 5 deletions
diff --git a/crates/yt/src/commands/cache/implm.rs b/crates/yt/src/commands/cache/implm.rs
new file mode 100644
index 0000000..f71fe94
--- /dev/null
+++ b/crates/yt/src/commands/cache/implm.rs
@@ -0,0 +1,30 @@
+use crate::{
+ app::App,
+ commands::CacheCommand,
+ storage::db::{
+ insert::Operations,
+ video::{Video, VideoStatusMarker},
+ },
+};
+
+use anyhow::Result;
+
+impl CacheCommand {
+ pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
+ match self {
+ CacheCommand::Clear {} => {
+ let mut videos = Video::in_states(app, &[VideoStatusMarker::Cached]).await?;
+
+ let mut ops = Operations::new("Cache clear");
+
+ for vid in &mut videos {
+ vid.remove_download_path(&mut ops);
+ }
+
+ ops.commit(app).await?;
+ }
+ }
+
+ Ok(())
+ }
+}
diff --git a/crates/yt/src/commands/cache/mod.rs b/crates/yt/src/commands/cache/mod.rs
new file mode 100644
index 0000000..b6afa39
--- /dev/null
+++ b/crates/yt/src/commands/cache/mod.rs
@@ -0,0 +1,9 @@
+use clap::Subcommand;
+
+mod implm;
+
+#[derive(Debug, Subcommand)]
+pub(super) enum CacheCommand {
+ /// Remove all downloaded video files.
+ Clear {},
+}
diff --git a/crates/yt/src/commands/implm.rs b/crates/yt/src/commands/implm.rs
index 119b721..ff29ce5 100644
--- a/crates/yt/src/commands/implm.rs
+++ b/crates/yt/src/commands/implm.rs
@@ -7,6 +7,7 @@ use anyhow::Result;
impl Command {
pub(crate) async fn implm(self, app: crate::app::App) -> Result<()> {
match self {
+ Command::Cache { cmd } => cmd.implm(&app).await?,
Command::Config { cmd } => cmd.implm(&app)?,
Command::Database { cmd } => cmd.implm(&app).await?,
Command::Download { cmd } => cmd.implm(Arc::new(app)).await?,
diff --git a/crates/yt/src/commands/mod.rs b/crates/yt/src/commands/mod.rs
index 7984f1c..2b847f7 100644
--- a/crates/yt/src/commands/mod.rs
+++ b/crates/yt/src/commands/mod.rs
@@ -7,10 +7,10 @@ use tokio::runtime::Runtime;
use crate::{
app::App,
commands::{
- config::ConfigCommand, database::DatabaseCommand, download::DownloadCommand,
- playlist::PlaylistCommand, select::SelectCommand, show::ShowCommand, status::StatusCommand,
- subscriptions::SubscriptionCommand, update::UpdateCommand, videos::VideosCommand,
- watch::WatchCommand,
+ cache::CacheCommand, config::ConfigCommand, database::DatabaseCommand,
+ download::DownloadCommand, playlist::PlaylistCommand, select::SelectCommand,
+ show::ShowCommand, status::StatusCommand, subscriptions::SubscriptionCommand,
+ update::UpdateCommand, videos::VideosCommand, watch::WatchCommand,
},
config::Config,
storage::db::subscription::Subscriptions,
@@ -18,6 +18,7 @@ use crate::{
pub(super) mod implm;
+mod cache;
mod config;
mod database;
mod download;
@@ -33,6 +34,12 @@ mod watch;
#[derive(Subcommand, Debug)]
#[allow(private_interfaces)] // Only the main `implm` method should be accessible.
pub(super) enum Command {
+ /// Manipulate the download cache
+ Cache {
+ #[command(subcommand)]
+ cmd: CacheCommand,
+ },
+
/// Show, the configuration options in effect.
Config {
#[command(flatten)]
diff --git a/crates/yt/tests/videos/downloading.rs b/crates/yt/tests/videos/downloading.rs
index 4b923d4..7cb437c 100644
--- a/crates/yt/tests/videos/downloading.rs
+++ b/crates/yt/tests/videos/downloading.rs
@@ -14,7 +14,7 @@ fn test_downloading() {
let usage = get_cache_usage(&env);
assert!(usage > 0.0);
- env.run(&["database", "invalidate"]);
+ env.run(&["cache", "clear"]);
let usage = get_cache_usage(&env);