diff options
-rw-r--r-- | Cargo.lock | 81 | ||||
-rw-r--r-- | common/src/lib.rs | 7 | ||||
-rw-r--r-- | server/src/library.rs | 4 | ||||
-rw-r--r-- | server/src/main.rs | 2 | ||||
-rw-r--r-- | tools/Cargo.toml | 3 | ||||
-rw-r--r-- | tools/src/bin/gen_meta.rs | 112 |
6 files changed, 201 insertions, 8 deletions
@@ -191,6 +191,43 @@ dependencies = [ ] [[package]] +name = "clap" +version = "4.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +dependencies = [ + "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + +[[package]] name = "cookie" version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -609,6 +646,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -811,8 +854,10 @@ name = "jellytools" version = "0.1.0" dependencies = [ "anyhow", + "clap", "jellycommon", "log", + "serde_json", "webm-iterable", ] @@ -990,6 +1035,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1154,6 +1205,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] name = "proc-macro2" version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1575,6 +1650,12 @@ dependencies = [ ] [[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] name = "subtle" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/common/src/lib.rs b/common/src/lib.rs index 6c8bceb..77e90a5 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -15,14 +15,15 @@ pub struct ItemInfo { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Source { - file: PathBuf, - tracks: BTreeMap<u64, SourceTrack>, + pub file: PathBuf, + pub tracks: BTreeMap<u64, SourceTrack>, } #[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "snake_case", tag = "kind")] pub enum SourceTrack { Video { - name: String, + language: String, codec: String, width: usize, height: usize, diff --git a/server/src/library.rs b/server/src/library.rs index f33508f..c46937a 100644 --- a/server/src/library.rs +++ b/server/src/library.rs @@ -86,7 +86,9 @@ impl Node { .read_dir()? .filter_map(|e| { let e = e.unwrap(); - if e.path().extension() == Some(OsStr::new("metadata.json")) + eprintln!("{:?}",e.path()); + eprintln!("{:?}",e.path().extension()); + if e.path().extension() == Some(OsStr::new("json")) || e.metadata().unwrap().is_dir() { Some(e.path()) diff --git a/server/src/main.rs b/server/src/main.rs index 855e278..36571f0 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -16,7 +16,7 @@ async fn assets_style() -> (ContentType, String) { ( ContentType::CSS, if cfg!(debug_assertions) { - read_to_string("src/frontend/style/layout.css").unwrap() + read_to_string("server/src/frontend/style/layout.css").unwrap() } else { CSS_BUNDLE.to_string() }, diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 239aae8..ece3140 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -4,12 +4,13 @@ version = "0.1.0" edition = "2021" [dependencies] +clap = { version = "4.0.32", features = ["derive"] } jellycommon = { path = "../common" } webm-iterable = "0.4.2" log = "0.4.17" anyhow = "1.0.68" - +serde_json = "1.0.91" [[bin]] path = "src/bin/gen_meta.rs" diff --git a/tools/src/bin/gen_meta.rs b/tools/src/bin/gen_meta.rs index 3783460..b09f4a1 100644 --- a/tools/src/bin/gen_meta.rs +++ b/tools/src/bin/gen_meta.rs @@ -1,4 +1,112 @@ +use anyhow::{anyhow, bail}; +use clap::Parser; +use jellycommon::{ItemInfo, Source, SourceTrack}; +use std::{collections::BTreeMap, fs::File, io::Write, path::PathBuf}; +use webm_iterable::{ + matroska_spec::{Master, MatroskaSpec}, + WebmIterator, +}; -fn main() { - +#[derive(Parser)] +struct Args { + #[clap(short = 'I', long)] + identifier: String, + #[clap(short = 'O', long)] + write_json: bool, + #[clap(short, long)] + title: String, + #[clap(short = 'i', long)] + inputs: Vec<PathBuf>, +} + +fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + let mut source = vec![]; + for fname in args.inputs { + let mut tracks = BTreeMap::new(); + let mut input = File::open(fname.clone()).unwrap(); + for tag in WebmIterator::new(&mut input, &[MatroskaSpec::TrackEntry(Master::Start)]) { + let tag = tag?; + match tag { + MatroskaSpec::TrackEntry(master) => { + let ( + mut index, + mut language, + mut codec, + mut kind, + mut sample_rate, + mut channels, + mut width, + mut height, + ) = (None, None, None, None, None, None, None, None); + for c in master.get_children() { + match c { + MatroskaSpec::CodecID(b) => codec = Some(b), + MatroskaSpec::Language(v) => language = Some(v), + MatroskaSpec::TrackNumber(v) => index = Some(v), + MatroskaSpec::TrackType(v) => kind = Some(v), + MatroskaSpec::Audio(master) => { + for c in master.get_children() { + match c { + MatroskaSpec::Channels(v) => channels = Some(v as usize), + MatroskaSpec::SamplingFrequency(v) => sample_rate = Some(v), + _ => (), + } + } + } + MatroskaSpec::Video(master) => { + for c in master.get_children() { + match c { + MatroskaSpec::PixelWidth(v) => width = Some(v as usize), + MatroskaSpec::PixelHeight(v) => height = Some(v as usize), + _ => (), + } + } + } + _ => (), + } + } + tracks.insert( + index.unwrap(), + match kind.ok_or(anyhow!("track type required"))? { + 1 => SourceTrack::Video { + language: language.unwrap(), + codec: codec.unwrap(), + width: width.unwrap(), + height: height.unwrap(), + }, + 2 => SourceTrack::Audio { + channels: channels.unwrap(), + codec: codec.unwrap(), + sample_rate: sample_rate.unwrap(), + language: language.unwrap(), + }, + _ => bail!("invalid track type"), + }, + ); + } + MatroskaSpec::Tags(Master::End) => break, + _ => (), + } + } + source.push(Source { + file: fname.clone(), + tracks, + }) + } + + let k = serde_json::to_string_pretty(&ItemInfo { + title: args.title, + source, + })?; + + if args.write_json { + let mut f = File::create(format!("{}.json", args.identifier))?; + f.write_all(k.as_bytes())?; + } else { + println!("{k}") + } + + Ok(()) } |