CLI utility to ingest embedded json metadata from yt-dlp downloads to a SQLite database file
yt-dlp
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: Better errors for extraction & shorter index sub-error message

0xBA5E64 74e97431 9ffa3308

+11 -12
+11 -12
src/lib.rs
··· 1 1 use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 2 + use matroska::MatroskaError; 2 3 use sqlx::{Pool, Sqlite}; 3 4 use std::path::PathBuf; 4 5 use thiserror::Error; ··· 6 7 7 8 #[derive(Error, Debug)] 8 9 pub enum ExtractError { 9 - #[error("Failed to open file")] 10 - FileOpenError, 11 - #[error("Failed to parse file")] 12 - FileParseError, 13 - #[error("Failed to find embedded json in file")] 14 - FindJsonEmbedError, 15 - #[error("Failed to parse json")] 16 - JsonParseError, 10 + #[error("Failed to open Matroska file: {0}")] 11 + MatroskaOpenError(MatroskaError), 12 + #[error("Failed to find json attachment")] 13 + FindAttachedJsonError, 14 + #[error("Failed to parse json: {0}")] 15 + JsonParseError(serde_json::Error), 17 16 } 18 17 19 18 #[derive(Error, Debug)] 20 19 pub enum IndexError { 21 - #[error("Error during metadata extraction: {0}")] 20 + #[error("Json Extraction Error: {0}")] 22 21 MetadataExtractionError(ExtractError), 23 22 #[error("Failed to perform database insert")] 24 23 DatabaseError, ··· 28 27 29 28 fn extract_json_metadata(file: &PathBuf) -> Result<serde_json::Value, ExtractError> { 30 29 // Parse the Matroska file 31 - let matroska = matroska::open(file).map_err(|_| ExtractError::FileParseError)?; 30 + let matroska = matroska::open(file).map_err(ExtractError::MatroskaOpenError)?; 32 31 // Find the json attachment 33 32 let json_attachment: matroska::Attachment = matroska 34 33 .attachments 35 34 .into_iter() 36 35 .find(|x| x.name.ends_with(".json")) 37 - .ok_or(ExtractError::FindJsonEmbedError)?; 36 + .ok_or(ExtractError::FindAttachedJsonError)?; 38 37 39 38 // Parse it as JSON and return the result 40 - serde_json::from_slice(&json_attachment.data).map_err(|_| ExtractError::JsonParseError) 39 + serde_json::from_slice(&json_attachment.data).map_err(ExtractError::JsonParseError) 41 40 } 42 41 43 42 pub async fn index_video(path: &PathBuf, db_pool: &Pool<Sqlite>) -> Result<(), IndexError> {