diff options
Diffstat (limited to 'import/src/matroska.rs')
-rw-r--r-- | import/src/matroska.rs | 14 |
1 files changed, 11 insertions, 3 deletions
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<Tags>, pub infojson: Option<YVideo>, } -pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<MatroskaMetadata>> { +pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<Option<MatroskaMetadata>>> { 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<Arc<MatroskaMetadata>> { } } } - Ok(MatroskaMetadata { + Ok(Some(MatroskaMetadata { chapters, cover, info, infojson, tags, tracks, - }) + })) }) } |