diff options
-rw-r--r-- | import/src/infojson.rs | 1 | ||||
-rw-r--r-- | import/src/lib.rs | 19 | ||||
-rw-r--r-- | import/src/matroska.rs | 10 |
3 files changed, 17 insertions, 13 deletions
diff --git a/import/src/infojson.rs b/import/src/infojson.rs index 50ec66d..3a8d76e 100644 --- a/import/src/infojson.rs +++ b/import/src/infojson.rs @@ -13,6 +13,7 @@ use std::collections::HashMap; pub struct YVideo { pub id: String, pub title: String, + pub alt_title: Option<String>, pub formats: Option<Vec<YFormat>>, pub thumbnails: Option<Vec<YThumbnail>>, pub thumbnail: Option<String>, diff --git a/import/src/lib.rs b/import/src/lib.rs index 0fc3a0d..3d638d6 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -278,6 +278,11 @@ fn import_media_file( let Some(m) = (*matroska_metadata(path)?).to_owned() else { return Ok(()); }; + let infojson = m + .infojson + .map(|d| serde_json::from_slice::<infojson::YVideo>(&d)) + .transpose() + .context("infojson parsing")?; let info = m.info.ok_or(anyhow!("no info"))?; let tracks = m.tracks.ok_or(anyhow!("no tracks"))?; @@ -311,8 +316,7 @@ fn import_media_file( let mut filename_toks = filename.split("."); let filepath_stem = filename_toks.next().unwrap(); - let slug = m - .infojson + let slug = infojson .as_ref() // TODO maybe also include the slug after the primary "id" key .map(|ij| format!("{}-{}", ij.extractor.to_lowercase(), ij.id)) @@ -398,7 +402,7 @@ fn import_media_file( }) .collect::<Vec<_>>(); - if let Some(infojson) = m.infojson { + if let Some(infojson) = infojson { node.kind = if !tracks .iter() .any(|t| matches!(t.kind, SourceTrackKind::Video { .. })) @@ -413,9 +417,12 @@ fn import_media_file( }; node.title = Some(infojson.title); node.subtitle = infojson - .uploader - .as_ref() - .map(|u| clean_uploader_name(u).to_owned()); + .alt_title + .or(infojson + .uploader + .as_ref() + .map(|u| clean_uploader_name(u).to_owned())) + .or(node.subtitle.clone()); if let Some(desc) = infojson.description { node.description = Some(desc) } diff --git a/import/src/matroska.rs b/import/src/matroska.rs index 4ab1148..1593463 100644 --- a/import/src/matroska.rs +++ b/import/src/matroska.rs @@ -3,7 +3,6 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::infojson::{self, YVideo}; use anyhow::{Context, Result}; use bincode::{Decode, Encode}; use ebml_struct::{ @@ -31,10 +30,10 @@ pub(crate) struct MatroskaMetadata { pub cover: Option<Asset>, pub chapters: Option<Chapters>, pub tags: Option<Tags>, - pub infojson: Option<YVideo>, + pub infojson: Option<Vec<u8>>, } pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<Option<MatroskaMetadata>>> { - cache_memory(&["mkmeta-v1", path.to_string_lossy().as_ref()], || { + cache_memory(&["mkmeta-v2", 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]) { @@ -74,10 +73,7 @@ pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<Option<MatroskaMetada for f in attachments.files { match f.name.as_str() { "info.json" => { - infojson = Some( - serde_json::from_slice::<infojson::YVideo>(&f.data) - .context("infojson")?, - ); + infojson = Some(f.data); } "cover.webp" | "cover.png" | "cover.jpg" | "cover.jpeg" | "cover.avif" => { |