From bfc5552a8eba07897c2ed626b49c085d97fdfa0d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 30 Jan 2025 16:45:06 +0100 Subject: external ids and urls --- import/src/matroska.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'import/src/matroska.rs') diff --git a/import/src/matroska.rs b/import/src/matroska.rs index bb8d927..6a33420 100644 --- a/import/src/matroska.rs +++ b/import/src/matroska.rs @@ -16,6 +16,7 @@ use jellybase::{ cache::{cache_file, cache_memory}, }; use jellycommon::Asset; +use log::info; use std::{ fs::File, io::{BufReader, ErrorKind, Read, Write}, @@ -32,8 +33,15 @@ pub(crate) struct MatroskaMetadata { pub tags: Option, pub infojson: Option, } -pub(crate) fn matroska_metadata(path: &Path) -> Result> { +pub(crate) fn matroska_metadata(path: &Path) -> Result>> { cache_memory(&["mkmeta-v1", path.to_string_lossy().as_ref()], || { + let mut magic = [0; 4]; + File::open(path)?.read_exact(&mut magic).ok(); + if !matches!(magic, [0x1A, 0x45, 0xDF, 0xA3]) { + return Ok(None); + } + + info!("reading media file {path:?}"); let mut file = BufReader::new(File::open(path)?); let mut file = file.by_ref().take(u64::MAX); @@ -100,13 +108,13 @@ pub(crate) fn matroska_metadata(path: &Path) -> Result> { } } } - Ok(MatroskaMetadata { + Ok(Some(MatroskaMetadata { chapters, cover, info, infojson, tags, tracks, - }) + })) }) } -- cgit v1.2.3-70-g09d2