aboutsummaryrefslogtreecommitdiff
path: root/import/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'import/src/main.rs')
-rw-r--r--import/src/main.rs36
1 files changed, 29 insertions, 7 deletions
diff --git a/import/src/main.rs b/import/src/main.rs
index bf5c49c..71c3c1e 100644
--- a/import/src/main.rs
+++ b/import/src/main.rs
@@ -3,13 +3,15 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
-pub mod tmdb;
pub mod infojson;
+pub mod tmdb;
use anyhow::Context;
use clap::{Parser, Subcommand};
+use infojson::YVideo;
use jellycommon::{
AssetLocation, LocalTrack, MediaInfo, MediaSource, Node, NodeKind, NodePrivate, NodePublic,
+ Rating,
};
use jellymatroska::read::EbmlReader;
use jellyremuxer::import::{import_metadata, seek_index};
@@ -118,17 +120,21 @@ fn main() -> anyhow::Result<()> {
.transpose()?;
let mut kind = NodeKind::Series;
- let (mut file_meta, mut source_path_e) = Default::default();
+ let mut file_meta = None;
+ let mut infojson = None;
if let Some(input_path) = &input {
- source_path_e = Some(path.join(format!("source.mkv")));
-
file_meta = Some({
let input = File::open(&input_path).unwrap();
let mut input = EbmlReader::new(input);
import_metadata(&mut input)?
});
+ if let Some(ij) = &file_meta.as_ref().unwrap().infojson {
+ infojson =
+ Some(serde_json::from_str::<YVideo>(ij).context("parsing info.json")?);
+ }
+
kind = if video {
NodeKind::Video
} else {
@@ -147,6 +153,7 @@ fn main() -> anyhow::Result<()> {
.unwrap();
let ident = make_ident(&title);
let path = path.join(&ident);
+ let source_path = input.as_ref().map(|_| path.join(format!("source.mkv")));
let (mut poster, mut backdrop) = (None, None);
if !args.dry {
@@ -211,6 +218,19 @@ fn main() -> anyhow::Result<()> {
.flatten();
}
+ let mut ratings = Vec::new();
+
+ ratings.extend(
+ infojson
+ .as_ref()
+ .map(|i| Rating::YoutubeViews(i.view_count)),
+ );
+ ratings.extend(
+ infojson
+ .as_ref()
+ .map(|i| Rating::YoutubeLikes(i.like_count)),
+ );
+
let node = Node {
private: NodePrivate {
import: None,
@@ -222,7 +242,7 @@ fn main() -> anyhow::Result<()> {
.clone()
.into_iter()
.map(|t| LocalTrack {
- path: source_path_e.clone().unwrap(),
+ path: source_path.clone().unwrap(),
..t
})
.collect(),
@@ -231,6 +251,7 @@ fn main() -> anyhow::Result<()> {
public: NodePublic {
parent: None,
federated: None,
+ ratings,
description: file_meta
.as_ref()
.map(|m| m.description.clone())
@@ -254,9 +275,10 @@ fn main() -> anyhow::Result<()> {
};
if args.dry {
- println!("{}", serde_json::to_string_pretty(&node)?)
+ println!("{}", serde_json::to_string_pretty(&infojson)?);
+ println!("{}", serde_json::to_string_pretty(&node)?);
} else {
- if let Some(source_path) = source_path_e {
+ if let Some(source_path) = source_path {
let input = input.clone().unwrap();
if r#move {
std::fs::rename(&input, &source_path)?;