diff options
Diffstat (limited to 'import')
| -rw-r--r-- | import/src/infojson.rs | 31 | ||||
| -rw-r--r-- | import/src/main.rs | 36 | 
2 files changed, 44 insertions, 23 deletions
| diff --git a/import/src/infojson.rs b/import/src/infojson.rs index 6f98eaa..0ed496c 100644 --- a/import/src/infojson.rs +++ b/import/src/infojson.rs @@ -37,7 +37,7 @@ pub struct YVideo {      pub uploader_url: String,      pub upload_date: String,      pub availability: String, // "public" | "private" | "unlisted", -    pub original_url: String, +    pub original_url: Option<String>,      pub webpage_url_basename: String,      pub webpage_url_domain: String,      pub extractor: String, @@ -50,7 +50,6 @@ pub struct YVideo {      pub playlist_uploader_id: String,      pub n_entries: usize,      pub playlist_index: usize, -    pub playlist_autonumber: usize,      pub display_id: String,      pub fulltitle: String,      pub duration_string: String, @@ -64,31 +63,31 @@ pub struct YCaption {      pub url: String,      pub ext: String, //"vtt" | "json3" | "srv1" | "srv2" | "srv3" | "ttml",      pub protocol: Option<String>, -    pub name: String, +    pub name: Option<String>,  }  #[derive(Debug, Serialize, Deserialize)]  pub struct YFormat {      pub format_id: String, -    pub format_note: String, +    pub format_note: Option<String>,      pub ext: String,      pub protocol: String, -    pub acodec: String, -    pub vcodec: String, +    pub acodec: Option<String>, +    pub vcodec: Option<String>,      pub url: String, -    pub width: u32, -    pub height: u32, -    pub fps: f64, -    pub columns: u32, -    pub fragments: Vec<YFragment>, -    pub resolution: Vec<String>, +    pub width: Option<u32>, +    pub height: Option<u32>, +    pub fps: Option<f64>, +    pub columns: Option<u32>, +    pub fragments: Option<Vec<YFragment>>, +    pub resolution: String,      pub dynamic_range: Option<String>, -    pub aspect_ratio: f64, +    pub aspect_ratio: Option<f64>,      pub http_headers: HashMap<String, String>,      pub audio_ext: String,      pub video_ext: String, -    pub vbr: usize, -    pub abr: usize, +    pub vbr: Option<f64>, +    pub abr: Option<f64>,      pub format: String,  } @@ -118,6 +117,6 @@ pub struct YChapter {  #[derive(Debug, Serialize, Deserialize)]  pub struct YHeatmapSample {      pub start_time: f64, -    pub end_time: String, +    pub end_time: f64,      pub value: f64,  } 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)?; | 
