null check on title to not fail Media Analysis

If the title is missing from the analysis metadata, the analysis fails.  Added null check and default value of "TitleValueNotSet".
This commit is contained in:
Brett Baker 2024-11-13 08:45:00 -05:00
parent 72eddfca6d
commit ff42378834

View file

@ -30,9 +30,12 @@ private MediaFormat ParseFormat(Format analysisFormat)
}; };
} }
private string GetValue(string tagName, Dictionary<string, string>? tags, string defaultValue) =>
tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue;
private ChapterData ParseChapter(Chapter analysisChapter) private ChapterData ParseChapter(Chapter analysisChapter)
{ {
var title = analysisChapter.Tags.FirstOrDefault(t => t.Key == "title").Value; var title = GetValue("title", analysisChapter.Tags, "TitleValueNotSet");
var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime); var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime);
var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime); var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime);