From ab45910e5643aa8390797ae98af94eac690b3bb5 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Mon, 25 Jan 2021 21:32:58 +0100 Subject: [PATCH] Fixed: FLAC audio channels in media info --- .../FormatAudioChannelsFixture.cs | 30 +++++++++++++++++++ .../MediaInfo/MediaInfoFormatter.cs | 10 +++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs index d3f39519b..3cd71c247 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioChannelsFixture.cs @@ -64,6 +64,21 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2); } + [Test] + public void should_use_AudioChannels_if_schema_revision_is_3_and_AudioChannelPositions_is_0() + { + var mediaInfoModel = new MediaInfoModel + { + AudioFormat = "FLAC", + AudioChannelsContainer = 6, + AudioChannelPositions = "0/0/0", + AudioChannelPositionsTextContainer = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m); + } + [Test] public void should_sum_AudioChannelPositions() { @@ -128,6 +143,21 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m); } + [Test] + public void should_format_6_channel_zero_as_51_if_flac() + { + var mediaInfoModel = new MediaInfoModel + { + AudioFormat = "FLAC", + AudioChannelsContainer = 6, + AudioChannelPositions = "0/0/0", + AudioChannelPositionsTextContainer = null, + SchemaRevision = 3 + }; + + MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m); + } + [Test] public void should_ignore_culture_on_channel_summary() { diff --git a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs index 14027c573..0008f4111 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaInfo/MediaInfoFormatter.cs @@ -18,12 +18,12 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo { var audioChannels = FormatAudioChannelsFromAudioChannelPositions(mediaInfo); - if (audioChannels == null) + if (audioChannels == null || audioChannels == 0.0m) { audioChannels = FormatAudioChannelsFromAudioChannelPositionsText(mediaInfo); } - if (audioChannels == null) + if (audioChannels == null || audioChannels == 0.0m) { audioChannels = FormatAudioChannelsFromAudioChannels(mediaInfo); } @@ -550,6 +550,12 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo return audioChannelsContainer - 1 + 0.1m; } + // FLAC 6 channels is likely 5.1 + if (audioFormat.ContainsIgnoreCase("FLAC") && audioChannelsContainer == 6) + { + return 5.1m; + } + if (mediaInfo.SchemaRevision > 5) { return audioChannelsStream > 0 ? audioChannelsStream : audioChannelsContainer;