Better debugging when metadata is invalid.

Handle missing subtitle encoding.
This commit is contained in:
Bill Thiede 2022-10-15 10:01:06 -07:00
parent 318ce583ea
commit 48d92f6b67

View File

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