diff --git a/src/lib.rs b/src/lib.rs index 3c81972..8bfcf9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,33 +1,24 @@ -use std::cmp::Ordering; -use std::collections::HashMap; -use std::collections::HashSet; -use std::env; -use std::ffi::OsStr; -use std::fmt; -use std::fmt::Display; -use std::fmt::Formatter; -use std::fs::File; -use std::io::BufReader; -use std::io::BufWriter; -use std::path::Path; -use std::path::PathBuf; -use std::process::Command; -use std::str::FromStr; +use std::{ + cmp::Ordering, + collections::{HashMap, HashSet}, + env, + ffi::OsStr, + fmt, + fmt::{Display, Formatter}, + fs::File, + io::{BufReader, BufWriter}, + path::{Path, PathBuf}, + process::Command, + str::FromStr, +}; -use failure::bail; -use failure::Error; -use failure::ResultExt; +use failure::{bail, Error, ResultExt}; use glob::glob; use lazy_static::lazy_static; -use log::error; -use log::info; -use rayon::iter::ParallelBridge; -use rayon::prelude::ParallelIterator; +use log::{error, info}; +use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; use regex::Regex; -use serde::de; -use serde::de::Deserializer; -use serde::Deserialize; -use serde::Serialize; +use serde::{de, de::Deserializer, Deserialize, Serialize}; use serde_json::Value; const FULL_METADATA_FILENAME: &str = "metadata.json"; @@ -161,8 +152,8 @@ enum Stream { }, #[serde(rename = "subtitle")] Subtitle { - codec_name: String, - codec_long_name: String, + codec_name: Option, + codec_long_name: Option, tags: Option, }, #[serde(rename = "attachment")] @@ -218,8 +209,8 @@ pub struct AudioFormat { #[derive(Clone, Deserialize, Debug, PartialEq, Serialize)] pub struct SubtitleFormat { - short_name: String, - long_name: String, + short_name: Option, + long_name: Option, #[serde(skip_serializing_if = "Option::is_none")] title: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -555,8 +546,8 @@ impl MovieLibrary { } = s { Some(SubtitleFormat { - short_name: codec_name.to_string(), - long_name: codec_long_name.to_string(), + short_name: codec_name.clone(), + long_name: codec_long_name.clone(), title: tags.as_ref().and_then(|t| t.title()), language: tags.as_ref().and_then(|t| t.language()), }) @@ -655,6 +646,12 @@ impl MovieLibrary { } } }) + .inspect(|(path, json)| { + if let Err(err) = serde_json::from_str::(&json) { + error!("Can't parse metadata for {}: {}", path, err); + error!("{}", json); + } + }) .map(|(path, json)| (path, serde_json::from_str::(&json).unwrap())) .collect(); let new_videos = metadata.keys().cloned().collect();