about summary refs log tree commit diff stats
path: root/src/storage
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-14 12:32:23 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-14 12:34:56 +0200
commit145a776039248a9460e9473e4bc9ef3d533b60c1 (patch)
tree7b2a948ae1f08335eba477c26bf1d5e83cdac24b /src/storage
parentfix(downloader): Don't display changed cache size on first run (diff)
downloadyt-145a776039248a9460e9473e4bc9ef3d533b60c1.tar.gz
yt-145a776039248a9460e9473e4bc9ef3d533b60c1.zip
feat(videos): Provide a consistent display for the `Video` struct
Before, `Video`s where colourized differently, just because the
colourization was not standardized. It now is.
Diffstat (limited to '')
-rw-r--r--src/storage/video_database/extractor_hash.rs21
-rw-r--r--src/storage/video_database/getters.rs14
-rw-r--r--src/storage/video_database/mod.rs4
3 files changed, 30 insertions, 9 deletions
diff --git a/src/storage/video_database/extractor_hash.rs b/src/storage/video_database/extractor_hash.rs
index 62a9eda..c956919 100644
--- a/src/storage/video_database/extractor_hash.rs
+++ b/src/storage/video_database/extractor_hash.rs
@@ -10,7 +10,7 @@
 
 use std::{collections::HashMap, fmt::Display, str::FromStr};
 
-use anyhow::{bail, Result};
+use anyhow::{bail, Context, Result};
 use blake3::Hash;
 use log::debug;
 use tokio::sync::OnceCell;
@@ -24,6 +24,12 @@ pub struct ExtractorHash {
     hash: Hash,
 }
 
+impl Display for ExtractorHash {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        self.hash.fmt(f)
+    }
+}
+
 #[derive(Debug, Clone)]
 pub struct ShortHash(String);
 
@@ -78,7 +84,10 @@ impl ExtractorHash {
         let needed_chars = if let Some(needed_chars) = EXTRACTOR_HASH_LENGTH.get() {
             *needed_chars
         } else {
-            let needed_chars = self.get_needed_char_len(app).await?;
+            let needed_chars = self
+                .get_needed_char_len(app)
+                .await
+                .context("Failed to calculate needed char length")?;
             EXTRACTOR_HASH_LENGTH
                 .set(needed_chars)
                 .expect("This should work at this stage");
@@ -96,7 +105,9 @@ impl ExtractorHash {
     }
 
     async fn short_hash_to_full_hash(app: &App, s: &ShortHash) -> Result<Hash> {
-        let all_hashes = get_all_hashes(app).await?;
+        let all_hashes = get_all_hashes(app)
+            .await
+            .context("Failed to fetch all extractor -hashesh from database")?;
 
         let needed_chars = s.0.len();
 
@@ -111,7 +122,9 @@ impl ExtractorHash {
 
     async fn get_needed_char_len(&self, app: &App) -> Result<usize> {
         debug!("Calculating the needed hash char length");
-        let all_hashes = get_all_hashes(app).await?;
+        let all_hashes = get_all_hashes(app)
+            .await
+            .context("Failed to fetch all extractor -hashesh from database")?;
 
         let all_char_vec_hashes = all_hashes
             .into_iter()
diff --git a/src/storage/video_database/getters.rs b/src/storage/video_database/getters.rs
index f2b0507..29dd014 100644
--- a/src/storage/video_database/getters.rs
+++ b/src/storage/video_database/getters.rs
@@ -287,7 +287,13 @@ pub async fn get_video_yt_dlp_opts(app: &App, hash: &ExtractorHash) -> Result<Yt
         ehash
     )
     .fetch_one(&app.database)
-    .await?;
+    .await
+    .with_context(|| {
+        format!(
+            "Failed to fetch the `yt_dlp_video_opts` for video: {}",
+            hash
+        )
+    })?;
 
     Ok(YtDlpOptions {
         subtitle_langs: yt_dlp_options.subtitle_langs,
@@ -305,7 +311,8 @@ pub async fn get_video_mpv_opts(app: &App, hash: &ExtractorHash) -> Result<MpvOp
         ehash
     )
     .fetch_one(&app.database)
-    .await?;
+    .await
+    .with_context(|| format!("Failed to fetch the `mpv_video_opts` for video: {}", hash))?;
 
     Ok(MpvOptions {
         playback_speed: mpv_options.playback_speed,
@@ -324,7 +331,8 @@ pub async fn get_video_opts(app: &App, hash: &ExtractorHash) -> Result<VideoOpti
         ehash
     )
     .fetch_one(&app.database)
-    .await?;
+    .await
+    .with_context(|| format!("Failed to fetch the `video_opts` for video: {}", hash))?;
 
     let mpv = MpvOptions {
         playback_speed: opts.playback_speed,
diff --git a/src/storage/video_database/mod.rs b/src/storage/video_database/mod.rs
index 0251eb1..1765f79 100644
--- a/src/storage/video_database/mod.rs
+++ b/src/storage/video_database/mod.rs
@@ -19,7 +19,7 @@ pub mod extractor_hash;
 pub mod getters;
 pub mod setters;
 
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct Video {
     pub cache_path: Option<PathBuf>,
     pub description: Option<String>,
@@ -88,7 +88,7 @@ pub struct YtDlpOptions {
 /// Cache                       // yt cache
 ///     |
 /// Watched                     // yt watch
-#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord)]
+#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
 pub enum VideoStatus {
     #[default]
     Pick,