diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-18 23:33:29 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-18 23:33:29 +0200 |
commit | a123a1997f3ab527ab83b44ca18bec94883f46d0 (patch) | |
tree | 761c4f0e8e9bbb7834e59af3d6904dee39932923 /remuxer/src | |
parent | 5b6fd021cc84ae7f5e1719ff398ff4627493a13c (diff) | |
download | jellything-a123a1997f3ab527ab83b44ca18bec94883f46d0.tar jellything-a123a1997f3ab527ab83b44ca18bec94883f46d0.tar.bz2 jellything-a123a1997f3ab527ab83b44ca18bec94883f46d0.tar.zst |
use impl Hash for cache key instead of string
Diffstat (limited to 'remuxer/src')
-rw-r--r-- | remuxer/src/metadata.rs | 24 | ||||
-rw-r--r-- | remuxer/src/seek_index.rs | 6 |
2 files changed, 12 insertions, 18 deletions
diff --git a/remuxer/src/metadata.rs b/remuxer/src/metadata.rs index c8a5f8f..4a496fe 100644 --- a/remuxer/src/metadata.rs +++ b/remuxer/src/metadata.rs @@ -33,20 +33,17 @@ pub struct MatroskaMetadata { pub infojson: Option<Vec<u8>>, } pub fn checked_matroska_metadata(path: &Path) -> Result<Arc<Option<MatroskaMetadata>>> { - cache_memory( - &["mkmeta-check-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); - } - Ok(Some((*matroska_metadata(path)?).clone())) - }, - ) + cache_memory("mkmeta-check-v1", path, || { + let mut magic = [0; 4]; + File::open(path)?.read_exact(&mut magic).ok(); + if !matches!(magic, [0x1A, 0x45, 0xDF, 0xA3]) { + return Ok(None); + } + Ok(Some((*matroska_metadata(path)?).clone())) + }) } pub fn matroska_metadata(path: &Path) -> Result<Arc<MatroskaMetadata>> { - cache_memory(&["mkmeta-v3", path.to_string_lossy().as_ref()], || { + cache_memory("mkmeta-v3", path, || { info!("reading {path:?}"); let mut file = BufReader::new(File::open(path)?); let mut file = file.by_ref().take(u64::MAX); @@ -86,7 +83,8 @@ pub fn matroska_metadata(path: &Path) -> Result<Arc<MatroskaMetadata>> { | "cover.avif" => { cover = Some( AssetInner::Cache(cache_file( - &["att-cover", path.to_string_lossy().as_ref()], + "att-cover", + path, move |mut file| { file.write_all(&f.data)?; Ok(()) diff --git a/remuxer/src/seek_index.rs b/remuxer/src/seek_index.rs index 82f62fb..1e1ce02 100644 --- a/remuxer/src/seek_index.rs +++ b/remuxer/src/seek_index.rs @@ -15,11 +15,8 @@ use jellymatroska::{ use log::{debug, info, trace, warn}; use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path, sync::Arc}; -pub const SEEK_INDEX_VERSION: u32 = 0x5eef1de4; - #[derive(Debug, Clone, Decode, Encode)] pub struct SeekIndex { - pub version: u32, pub blocks: Vec<BlockIndex>, pub keyframes: Vec<usize>, } @@ -35,7 +32,6 @@ pub struct BlockIndex { impl Default for SeekIndex { fn default() -> Self { Self { - version: SEEK_INDEX_VERSION, blocks: Vec::new(), keyframes: Vec::new(), } @@ -43,7 +39,7 @@ impl Default for SeekIndex { } pub fn get_seek_index(path: &Path) -> anyhow::Result<Arc<BTreeMap<u64, Arc<SeekIndex>>>> { - cache_memory(&["seekindex", path.to_str().unwrap()], move || { + cache_memory("seekindex-v1", path, move || { info!("generating seek index for {path:?}"); let input = File::open(path).context("opening source file")?; let mut input = EbmlReader::new(BufReader::new(input)); |