From ff42378834422244e3076a6a7cc791cc548d1cc5 Mon Sep 17 00:00:00 2001 From: Brett Baker Date: Wed, 13 Nov 2024 08:45:00 -0500 Subject: [PATCH] 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". --- FFMpegCore/FFProbe/MediaAnalysis.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 887baeb..af37cf2 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -30,9 +30,12 @@ private MediaFormat ParseFormat(Format analysisFormat) }; } + private string GetValue(string tagName, Dictionary? tags, string defaultValue) => + tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue; + 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 end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime);