From 145a776039248a9460e9473e4bc9ef3d533b60c1 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Mon, 14 Oct 2024 12:32:23 +0200 Subject: 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. --- src/storage/video_database/extractor_hash.rs | 21 +++++++++++++++++---- src/storage/video_database/getters.rs | 14 +++++++++++--- src/storage/video_database/mod.rs | 4 ++-- 3 files changed, 30 insertions(+), 9 deletions(-) (limited to 'src/storage/video_database') 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 { - 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 { 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 Result Result, pub description: Option, @@ -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, -- cgit 1.4.1