aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--import/src/main.rs44
-rw-r--r--remuxer/src/import/mod.rs48
2 files changed, 79 insertions, 13 deletions
diff --git a/import/src/main.rs b/import/src/main.rs
index 806ebfb..bf90eb2 100644
--- a/import/src/main.rs
+++ b/import/src/main.rs
@@ -10,10 +10,10 @@ use clap::{Parser, Subcommand};
use jellycommon::{AssetLocation, MediaInfo, MediaSource, Node, NodeKind, NodePrivate, NodePublic};
use jellymatroska::read::EbmlReader;
use jellyremuxer::import::{import_metadata, seek_index::import_seek_index};
-use log::info;
+use log::{info, warn};
use std::{
fs::{remove_file, File},
- io::stdin,
+ io::{stdin, Write},
path::PathBuf,
process::exit,
};
@@ -154,21 +154,47 @@ fn main() -> anyhow::Result<()> {
if !args.dry {
std::fs::create_dir_all(&path)?;
- poster = tmdb_details
+ poster = file_meta
.as_ref()
- .map(|d| {
- d.poster_path
+ .map(|m| {
+ m.cover
.as_ref()
- .map(|p| {
- let pu = path.join("poster.jpeg");
+ .map(|(mime, data)| {
+ let pu = path.join(format!(
+ "cover.{}",
+ match mime.as_str() {
+ "image/webp" => "webp",
+ "image/jpeg" => "jpeg",
+ "image/png" => "png",
+ _ => {
+ warn!("unknown mime, just using webp");
+ "webp"
+ }
+ }
+ ));
let mut f = File::create(&pu)?;
- tmdb_image(&p, &mut f)?;
+ f.write_all(&data)?;
Ok::<_, anyhow::Error>(pu)
})
.transpose()
})
.transpose()?
- .flatten();
+ .flatten()
+ .or(tmdb_details
+ .as_ref()
+ .map(|d| {
+ d.poster_path
+ .as_ref()
+ .map(|p| {
+ let pu = path.join("poster.jpeg");
+ let mut f = File::create(&pu)?;
+ tmdb_image(&p, &mut f)?;
+ Ok::<_, anyhow::Error>(pu)
+ })
+ .transpose()
+ })
+ .transpose()?
+ .flatten());
backdrop = tmdb_details
.as_ref()
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 {