aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/yt/yt/src/cache/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/yt/yt/src/cache/mod.rs')
-rw-r--r--pkgs/by-name/yt/yt/src/cache/mod.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/pkgs/by-name/yt/yt/src/cache/mod.rs b/pkgs/by-name/yt/yt/src/cache/mod.rs
index f9715e40..87f42604 100644
--- a/pkgs/by-name/yt/yt/src/cache/mod.rs
+++ b/pkgs/by-name/yt/yt/src/cache/mod.rs
@@ -1,7 +1,6 @@
-use std::path::Path;
-
use anyhow::Result;
use log::info;
+use tokio::fs;
use crate::{
app::App,
@@ -10,21 +9,28 @@ use crate::{
},
};
-async fn invalidate_video(app: &App, video: &Video) -> Result<()> {
+async fn invalidate_video(app: &App, video: &Video, hard: bool) -> Result<()> {
info!("Invalidating cache of video: '{}'", video.title);
+ if hard {
+ if let Some(path) = &video.cache_path {
+ info!("Removing cached video at: '{}'", path.display());
+ fs::remove_file(path).await?;
+ }
+ }
+
set_video_cache_path(app, &video.extractor_hash, None).await?;
Ok(())
}
-pub async fn invalidate(app: &App) -> Result<()> {
+pub async fn invalidate(app: &App, hard: bool) -> Result<()> {
let all_cached_things = get_videos(app, &[VideoStatus::Cached]).await?;
info!("Got videos to invalidate: '{}'", all_cached_things.len());
for video in all_cached_things {
- invalidate_video(app, &video).await?
+ invalidate_video(app, &video, hard).await?
}
Ok(())
@@ -49,11 +55,11 @@ pub async fn maintain(app: &App, all: bool) -> Result<()> {
let cached_videos = get_videos(app, domain.as_slice()).await?;
for vid in cached_videos {
- let path: &Path = vid.cache_path.as_ref().expect("This is some");
-
- info!("Checking if path ('{}') exists", path.display());
- if !path.exists() {
- invalidate_video(app, &vid).await?;
+ if let Some(path) = vid.cache_path.as_ref() {
+ info!("Checking if path ('{}') exists", path.display());
+ if !path.exists() {
+ invalidate_video(app, &vid, false).await?;
+ }
}
}