1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use clap::Parser;
use jellycommon::ItemInfo;
use jellymatroska::read::EbmlReader;
use jellyremuxer::import::import_read;
use log::warn;
use std::{fs::File, io::Write, path::PathBuf};
#[derive(Parser)]
struct Args {
#[arg(short = 'I', long)]
item: PathBuf,
#[arg(short, long)]
banner: Option<PathBuf>,
#[arg(short, long)]
title: Option<String>,
#[arg(short = 'D', long)]
description_head: Option<String>,
#[arg(short = 'd', long)]
description: Option<String>,
#[arg(short = 'N', long)]
dry: bool,
#[arg(short = 'c', long)]
clear_inputs: bool,
#[arg(short = 'i', long, num_args(0..))]
input: Vec<PathBuf>,
}
fn main() -> anyhow::Result<()> {
env_logger::builder()
.filter_level(log::LevelFilter::Info)
.parse_env("LOG")
.init();
let args = Args::parse();
let mut iteminfo: ItemInfo = match File::open(&args.item) {
Ok(f) => serde_json::from_reader(f)?,
Err(e) => {
warn!("could not load item info: {e}");
warn!("using the default instead");
ItemInfo {
duration: 0.0,
banner: None,
description_head: "Lorem ipsum!".to_string(),
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".to_string(),
title: args.item.to_str().unwrap().to_string(),
tracks: Default::default(),
}
}
};
if let Some(title) = args.title {
iteminfo.title = title;
}
if let Some(banner) = args.banner {
iteminfo.banner = Some(banner);
}
if let Some(d) = args.description {
iteminfo.description = d;
}
if let Some(d) = args.description_head {
iteminfo.description_head = d;
}
if args.clear_inputs {
iteminfo.tracks = Default::default()
}
for input_path in args.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(args.item)?;
f.write_all(k.as_bytes())?;
}
Ok(())
}
|