diff options
author | metamuffin <metamuffin@disroot.org> | 2023-07-31 19:53:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-07-31 19:53:01 +0200 |
commit | aeafba7847e189313df3025e6d6f291999b57350 (patch) | |
tree | bf7affdca28208695648bc9b18856cbb7049d1e8 /tools/src/bin/import.rs | |
parent | 0c651f11920350a4aa96aa24f8fe15b28390aed2 (diff) | |
download | jellything-aeafba7847e189313df3025e6d6f291999b57350.tar jellything-aeafba7847e189313df3025e6d6f291999b57350.tar.bz2 jellything-aeafba7847e189313df3025e6d6f291999b57350.tar.zst |
update server to new schema
Diffstat (limited to 'tools/src/bin/import.rs')
-rw-r--r-- | tools/src/bin/import.rs | 216 |
1 files changed, 89 insertions, 127 deletions
diff --git a/tools/src/bin/import.rs b/tools/src/bin/import.rs index 3050f71..f740fec 100644 --- a/tools/src/bin/import.rs +++ b/tools/src/bin/import.rs @@ -5,17 +5,12 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ use anyhow::Context; use clap::{Parser, Subcommand}; -use jellycommon::{CommmonInfo, DirectoryInfo, ItemInfo}; +use jellycommon::{MediaInfo, Node, NodeKind, NodePrivate, NodePublic}; use jellymatroska::read::EbmlReader; use jellyremuxer::import::import_read; use jellytools::tmdb::{tmdb_details, tmdb_image, tmdb_search}; -use log::{info, warn}; -use std::{ - fs::File, - io::{stdin, Write}, - path::{Path, PathBuf}, - process::exit, -}; +use log::info; +use std::{fs::File, io::stdin, path::PathBuf, process::exit}; #[derive(Parser)] struct Args { @@ -37,12 +32,6 @@ enum Action { #[arg(short, long)] series: bool, }, - Episode { - path: PathBuf, - index: usize, - title: String, - input: PathBuf, - }, Set { #[arg(short = 'I', long)] item: PathBuf, @@ -131,89 +120,68 @@ fn main() -> anyhow::Result<()> { }) .transpose()?; - let common = CommmonInfo { - poster, - backdrop, - description: Some(details.overview), - tagline: details.tagline, - title: details.title.clone().or(details.name.clone()).unwrap(), - index: None, - }; - info!("is this correct? [y/n]"); if stdin().lines().next().unwrap().unwrap() != "y" { exit(0) } - let k = if let Some(input) = input { - let mut iteminfo = ItemInfo { - common, - duration: Default::default(), - tracks: Default::default(), - }; - info!("{iteminfo:#?}"); + let kind; + let media; + let source; + + if let Some(input) = input { let source_path = path.join(format!("source.mkv")); // std::fs::rename(&input, &source_path)?; // std::os::unix::fs::symlink(&input, &source_path)?; std::fs::copy(&input, &source_path)?; - import_source(&mut iteminfo, &source_path)?; - serde_json::to_string_pretty(&iteminfo)? + let input = File::open(&source_path).unwrap(); + let mut input = EbmlReader::new(input); + let (tracks, local_tracks, _seek_index) = + import_read(&source_path.to_path_buf(), &mut input)?; + kind = NodeKind::Movie; + media = Some(MediaInfo { + tracks, + duration: 0., + }); + source = Some(jellycommon::MediaSource::Local { + tracks: local_tracks, + }); } else { - serde_json::to_string_pretty(&DirectoryInfo { - common, - kind: jellycommon::DirectoryKind::Series, - })? + kind = NodeKind::Series; + media = None; + source = None; + }; + + let node = Node { + private: NodePrivate { + backdrop: backdrop.clone(), + poster: poster.clone(), + source, + }, + public: NodePublic { + description: Some(details.overview), + tagline: details.tagline, + title: details.title.clone().or(details.name.clone()).unwrap(), + index: None, + kind, + children: Vec::new(), + media, + }, }; if args.dry { - println!("{k}") + println!("{node:?}") } else { - let mut f = File::create(path.join(if series { + let f = File::create(path.join(if series { "directory.json".to_string() } else { format!("{ident}.jelly",) }))?; - f.write_all(k.as_bytes())?; + serde_json::to_writer_pretty(f, &node)?; } Ok(()) } - Action::Episode { - path, - index, - title, - input, - } => { - let ident = make_ident(&title); - let common = CommmonInfo { - poster: None, - backdrop: None, - description: None, - tagline: None, - title, - index: Some(index), - }; - let mut iteminfo = ItemInfo { - common, - duration: Default::default(), - tracks: Default::default(), - }; - let path = path.join(&ident); - std::fs::create_dir_all(&path)?; - let source_path = path.join(format!("source.mkv")); - // std::fs::rename(&input, &source_path)?; - // std::os::unix::fs::symlink(&input, &source_path)?; - std::fs::copy(&input, &source_path)?; - import_source(&mut iteminfo, &source_path)?; - let k = serde_json::to_string_pretty(&iteminfo)?; - if args.dry { - println!("{k}") - } else { - let mut f = File::create(path.join(format!("{ident}.jelly",)))?; - f.write_all(k.as_bytes())?; - } - Ok(()) - } Action::Set { poster, clear_inputs, @@ -223,55 +191,55 @@ fn main() -> anyhow::Result<()> { item, title, } => { - let mut iteminfo: ItemInfo = match File::open(item.clone()) { - Ok(f) => serde_json::from_reader(f)?, - Err(e) => { - warn!("could not load item info: {e}"); - warn!("using the default instead"); - ItemInfo { - common: CommmonInfo { - poster: None, - backdrop: None, - tagline: None, - description: None, - title: item.to_str().unwrap().to_string(), - index: None, - }, - duration: 0.0, - tracks: Default::default(), - } - } - }; + // let mut iteminfo: ItemInfo = match File::open(item.clone()) { + // Ok(f) => serde_json::from_reader(f)?, + // Err(e) => { + // warn!("could not load item info: {e}"); + // warn!("using the default instead"); + // ItemInfo { + // common: CommmonInfo { + // poster: None, + // backdrop: None, + // tagline: None, + // description: None, + // title: item.to_str().unwrap().to_string(), + // index: None, + // }, + // duration: 0.0, + // tracks: Default::default(), + // } + // } + // }; - if let Some(title) = title { - iteminfo.title = title; - } - if let Some(poster) = poster { - iteminfo.poster = Some(poster); - } - if let Some(d) = description { - iteminfo.description = Some(d); - } - if let Some(d) = tagline { - iteminfo.tagline = Some(d); - } - if clear_inputs { - iteminfo.tracks = Default::default() - } + // if let Some(title) = title { + // iteminfo.title = title; + // } + // if let Some(poster) = poster { + // iteminfo.poster = Some(poster); + // } + // if let Some(d) = description { + // iteminfo.description = Some(d); + // } + // if let Some(d) = tagline { + // iteminfo.tagline = Some(d); + // } + // if clear_inputs { + // iteminfo.tracks = Default::default() + // } - for input_path in input { - let input = File::open(input_path.clone()).unwrap(); - let mut input = EbmlReader::new(input); - import_read(&input_path, &mut input, &mut iteminfo)?; - } + // // for input_path in input { + // // let input = File::open(input_path.clone()).unwrap(); + // // let mut input = EbmlReader::new(input); + // // import_read(&input_path, &mut input, &mut iteminfo)?; + // // } - let k = serde_json::to_string_pretty(&iteminfo)?; - if args.dry { - println!("{k}") - } else { - let mut f = File::create(item)?; - f.write_all(k.as_bytes())?; - } + // let k = serde_json::to_string_pretty(&iteminfo)?; + // if args.dry { + // println!("{k}") + // } else { + // let mut f = File::create(item)?; + // f.write_all(k.as_bytes())?; + // } Ok(()) } } @@ -289,9 +257,3 @@ fn make_ident(s: &str) -> String { } out } -fn import_source(iteminfo: &mut ItemInfo, source_path: &Path) -> anyhow::Result<()> { - let input = File::open(&source_path).unwrap(); - let mut input = EbmlReader::new(input); - import_read(&source_path.to_path_buf(), &mut input, iteminfo)?; - Ok(()) -} |