aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src
diff options
context:
space:
mode:
Diffstat (limited to 'remuxer/src')
-rw-r--r--remuxer/src/import/mod.rs48
1 files changed, 44 insertions, 4 deletions
diff --git a/remuxer/src/import/mod.rs b/remuxer/src/import/mod.rs
index 8c89b4d..ab3be3d 100644
--- a/remuxer/src/import/mod.rs
+++ b/remuxer/src/import/mod.rs
@@ -5,7 +5,7 @@
*/
pub mod seek_index;
-use anyhow::{anyhow, bail, Result};
+use anyhow::{anyhow, bail, Context, Result};
use jellycommon::{LocalTrack, SourceTrack, SourceTrackKind};
use jellymatroska::{
matroska::MatroskaTag,
@@ -22,7 +22,8 @@ pub struct MatroskaMetadata {
pub tagline: Option<String>,
pub tracks: Vec<SourceTrack>,
pub track_sources: Vec<LocalTrack>,
- pub image: Option<(String, Vec<u8>)>,
+ pub cover: Option<(String, Vec<u8>)>,
+ pub infojson: Option<String>,
pub duration: f64,
}
@@ -126,6 +127,45 @@ fn import_read_segment(segment: &mut Unflatten) -> Result<MatroskaMetadata> {
}
}
}
+ MatroskaTag::Attachments(_) => {
+ let mut children = children.unwrap();
+ while let Some(Ok(Unflat { children, item, .. })) = children.n() {
+ match item {
+ MatroskaTag::AttachedFile(_) => {
+ let (mut name, mut data, mut mime) = Default::default();
+ let mut children = children.unwrap();
+ while let Some(Ok(Unflat {
+ children: _, item, ..
+ })) = children.n()
+ {
+ match item {
+ MatroskaTag::FileName(n) => name = Some(n),
+ MatroskaTag::FileData(d) => data = Some(d),
+ MatroskaTag::FileMimeType(m) => mime = Some(m),
+ _ => debug!("(rsaa) tag ignored: {item:?}"),
+ }
+ }
+ let (name, data, mime) = (
+ name.ok_or(anyhow!("attachment without name"))?,
+ data.ok_or(anyhow!("attachment without data"))?,
+ mime.ok_or(anyhow!("attachment without mime type"))?,
+ );
+ info!("attachment found: {name:?} type {mime:?}");
+ match (name.as_str(), mime.as_str()) {
+ ("info.json", "application/json") => {
+ m.infojson =
+ Some(String::from_utf8(data).context("info.json invalid")?)
+ }
+ (_, "image/jpeg" | "image/png" | "image/webp") => {
+ m.cover = Some((mime, data))
+ }
+ _ => (),
+ }
+ }
+ _ => debug!("(rsa) tag ignored: {item:?}"),
+ }
+ }
+ }
MatroskaTag::Cues(_) => {}
MatroskaTag::Chapters(_) => {}
MatroskaTag::Tracks(_) => {
@@ -218,12 +258,12 @@ fn import_read_segment(segment: &mut Unflatten) -> Result<MatroskaMetadata> {
codec_private,
})
}
- _ => debug!("(rst) tag ignored: {item:?}"),
+ _ => warn!("(rst) tag ignored: {item:?}"),
}
}
}
MatroskaTag::Cluster(_) => {}
- _ => debug!("(rs) tag ignored: {item:?}"),
+ _ => warn!("(rs) tag ignored: {item:?}"),
};
}
if let Some(duration) = duration {