Fixed: Use audioChannels_Original if it exists in MI

This commit is contained in:
Qstick 2020-11-15 01:07:47 -05:00 committed by Mark McDowall
parent b84f84ad0a
commit 39cb0934bc
8 changed files with 190 additions and 50 deletions

View File

@ -13,9 +13,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioChannelPositions = null,
AudioChannelPositionsText = "Front: L C R, Side: L R, LFE"
AudioChannelPositionsTextContainer = "Front: L C R, Side: L R, LFE"
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m);
@ -26,9 +26,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = null,
AudioChannelPositionsText = "Front: L R"
AudioChannelPositionsTextContainer = "Front: L R"
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2);
@ -39,9 +39,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = null,
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 2
};
@ -53,9 +53,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = null,
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
@ -67,9 +67,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = "2/0/0",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
@ -81,23 +81,73 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = "3/2/0.1",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m);
}
[Test]
public void should_format_8_channel_object_based_as_71_if_dtsx()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannelsContainer = 8,
AudioChannelsStream = 0,
AudioFormat = "DTS",
AudioAdditionalFeatures = "XLL X",
AudioChannelPositions = "Object Based",
AudioChannelPositionsTextContainer = "Object Based",
AudioChannelPositionsTextStream = "Object Based",
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m);
}
[Test]
public void should_format_8_channel_blank_as_71_if_dtsx()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannelsContainer = 8,
AudioChannelsStream = 0,
AudioFormat = "DTS",
AudioAdditionalFeatures = "XLL X",
AudioChannelPositions = "",
AudioChannelPositionsTextContainer = "",
AudioChannelPositionsTextStream = "Object Based",
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m);
}
[Test]
public void should_handle_AudioChannelPositions_three_digits()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannelsContainer = 2,
AudioChannelPositions = "3/2/0.2.1",
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m);
}
[Test]
public void should_cleanup_extraneous_text_from_AudioChannelPositions()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = "Object Based / 3/2/2.1",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
@ -109,9 +159,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = " / 2/0/0.0",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
@ -123,9 +173,23 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = "3/2/2.1 / 3/2/2.1",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m);
}
[Test]
public void should_sum_first_series_of_numbers_from_AudioChannelPositions_with_three_digits()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannelsContainer = 2,
AudioChannelPositions = "3/2/0.2.1 / 3/2/0.1",
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
@ -137,9 +201,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = "1+1",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
@ -150,11 +214,11 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
public void should_use_AudioChannelPositionText_when_AudioChannelChannelPosition_is_invalid()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 6,
{
AudioChannelsContainer = 6,
AudioChannelPositions = "15 objects",
AudioChannelPositionsText = "15 objects / Front: L C R, Side: L R, LFE",
SchemaRevision = 3
AudioChannelPositionsTextContainer = "15 objects / Front: L C R, Side: L R, LFE",
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m);
@ -165,13 +229,45 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannels = 2,
AudioChannelsContainer = 2,
AudioChannelPositions = "15 objects / 3/2.1",
AudioChannelPositionsText = null,
AudioChannelPositionsTextContainer = null,
SchemaRevision = 3
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m);
}
[Test]
public void should_use_audio_stream_text_when_exists()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannelsContainer = 6,
AudioChannelsStream = 8,
AudioChannelPositions = null,
AudioChannelPositionsTextContainer = null,
AudioChannelPositionsTextStream = "Front: L C R, Side: L R, Back: L R, LFE",
SchemaRevision = 6
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(7.1m);
}
[Test]
public void should_use_audio_stream_channels_when_exists()
{
var mediaInfoModel = new MediaInfoModel
{
AudioChannelsContainer = 6,
AudioChannelsStream = 8,
AudioChannelPositions = null,
AudioChannelPositionsTextContainer = null,
AudioChannelPositionsTextStream = null,
SchemaRevision = 6
};
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(8m);
}
}
}

View File

@ -50,7 +50,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo
info.AudioProfile.Should().BeOneOf("", "LC");
info.AudioCodecLibrary.Should().Be("");
info.AudioBitrate.Should().Be(128000);
info.AudioChannels.Should().Be(2);
info.AudioChannelsContainer.Should().Be(2);
info.AudioChannelsStream.Should().Be(0);
info.AudioChannelPositionsTextContainer.Should().Be("Front: L R");
info.AudioChannelPositionsTextStream.Should().Be("");
info.AudioLanguages.Should().Be("English");
info.Height.Should().Be(320);
info.RunTime.Seconds.Should().Be(10);
@ -89,7 +92,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo
info.AudioProfile.Should().BeOneOf("", "LC");
info.AudioCodecLibrary.Should().Be("");
info.AudioBitrate.Should().Be(128000);
info.AudioChannels.Should().Be(2);
info.AudioChannelsContainer.Should().Be(2);
info.AudioChannelsStream.Should().Be(0);
info.AudioChannelPositionsTextContainer.Should().Be("Front: L R");
info.AudioChannelPositionsTextStream.Should().Be("");
info.AudioLanguages.Should().Be("English");
info.Height.Should().Be(320);
info.RunTime.Seconds.Should().Be(10);

View File

@ -543,7 +543,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{
VideoCodec = "AVC",
AudioFormat = "DTS",
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioLanguages = "English/Spanish",
Subtitles = "English/Spanish/Italian",
SchemaRevision = 3
@ -564,7 +564,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{
VideoCodec = "AVC",
AudioFormat = "DTS",
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioLanguages = "English",
Subtitles = language,
SchemaRevision = 3
@ -583,7 +583,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{
VideoCodec = "AVC",
AudioFormat = "DTS",
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioLanguages = "English",
Subtitles = "English/Spanish/Italian",
SchemaRevision = 3
@ -963,7 +963,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{
VideoCodec = "AVC",
AudioFormat = "DTS",
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioLanguages = "English",
Subtitles = "English/Spanish/Italian",
VideoBitDepth = 10,
@ -986,7 +986,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{
VideoCodec = videoCodec,
AudioFormat = audioCodec,
AudioChannels = audioChannels,
AudioChannelsContainer = audioChannels,
AudioLanguages = audioLanguages,
Subtitles = subtitles,
VideoBitDepth = videoBitDepth,

View File

@ -312,8 +312,9 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
streamDetails.Add(video);
var audio = new XElement("audio");
var audioChannelCount = episodeFile.MediaInfo.AudioChannelsStream > 0 ? episodeFile.MediaInfo.AudioChannelsStream : episodeFile.MediaInfo.AudioChannelsContainer;
audio.Add(new XElement("bitrate", episodeFile.MediaInfo.AudioBitrate));
audio.Add(new XElement("channels", episodeFile.MediaInfo.AudioChannels));
audio.Add(new XElement("channels", audioChannelCount));
audio.Add(new XElement("codec", MediaInfoFormatter.FormatAudioCodec(episodeFile.MediaInfo, sceneName)));
audio.Add(new XElement("language", episodeFile.MediaInfo.AudioLanguages));
streamDetails.Add(audio);

View File

@ -441,6 +441,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
private static decimal? FormatAudioChannelsFromAudioChannelPositions(MediaInfoModel mediaInfo)
{
var audioChannelPositions = mediaInfo.AudioChannelPositions;
var audioFormat = mediaInfo.AudioFormat;
if (audioChannelPositions.IsNullOrWhiteSpace())
{
@ -468,7 +469,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
}
catch (Exception e)
{
Logger.Warn(e, "Unable to format audio channels using 'AudioChannelPositions', with a value of: '{0}'", audioChannelPositions);
Logger.Warn()
.Message("Unable to format audio channels using 'AudioChannelPositions', with a value of: '{0}' and '{1}'. Error {2}", audioChannelPositions, mediaInfo.AudioChannelPositionsTextContainer, e.Message)
.WriteSentryWarn("UnknownAudioChannelFormat", audioChannelPositions, mediaInfo.AudioChannelPositionsTextContainer)
.Write();
}
return null;
@ -476,21 +480,30 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
private static decimal? FormatAudioChannelsFromAudioChannelPositionsText(MediaInfoModel mediaInfo)
{
var audioChannelPositionsText = mediaInfo.AudioChannelPositionsText;
var audioChannels = mediaInfo.AudioChannels;
var audioChannelPositionsTextContainer = mediaInfo.AudioChannelPositionsTextContainer;
var audioChannelPositionsTextStream = mediaInfo.AudioChannelPositionsTextStream;
var audioChannelsContainer = mediaInfo.AudioChannelsContainer;
var audioChannelsStream = mediaInfo.AudioChannelsStream;
if (audioChannelPositionsText.IsNullOrWhiteSpace())
// Skip if the positions texts give us nothing
if ((audioChannelPositionsTextContainer.IsNullOrWhiteSpace() || audioChannelPositionsTextContainer == "Object Based") &&
(audioChannelPositionsTextStream.IsNullOrWhiteSpace() || audioChannelPositionsTextStream == "Object Based"))
{
return null;
}
try
{
return audioChannelPositionsText.ContainsIgnoreCase("LFE") ? audioChannels - 1 + 0.1m : audioChannels;
if (audioChannelsStream > 0)
{
return audioChannelPositionsTextStream.ContainsIgnoreCase("LFE") ? audioChannelsStream - 1 + 0.1m : audioChannelsStream;
}
return audioChannelPositionsTextContainer.ContainsIgnoreCase("LFE") ? audioChannelsContainer - 1 + 0.1m : audioChannelsContainer;
}
catch (Exception e)
{
Logger.Warn(e, "Unable to format audio channels using 'AudioChannelPositionsText', with a value of: '{0}'", audioChannelPositionsText);
Logger.Warn(e, "Unable to format audio channels using 'AudioChannelPositionsText' or 'AudioChannelPositionsTextStream', with value of: '{0}' and '{1}", audioChannelPositionsTextContainer, audioChannelPositionsTextStream);
}
return null;
@ -498,7 +511,22 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
private static decimal? FormatAudioChannelsFromAudioChannels(MediaInfoModel mediaInfo)
{
var audioChannels = mediaInfo.AudioChannels;
var audioChannels = mediaInfo.AudioChannelsContainer;
var audioChannelsStream = mediaInfo.AudioChannelsStream;
var audioFormat = (mediaInfo.AudioFormat ?? string.Empty).Trim().Split(new[] { " / " }, StringSplitOptions.RemoveEmptyEntries);
var splitAdditionalFeatures = (mediaInfo.AudioAdditionalFeatures ?? string.Empty).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
// Workaround https://github.com/MediaArea/MediaInfo/issues/299 for DTS-X Audio
if (audioFormat.ContainsIgnoreCase("DTS") && splitAdditionalFeatures.ContainsIgnoreCase("XLL") && splitAdditionalFeatures.ContainsIgnoreCase("X"))
{
return audioChannels - 1 + 0.1m;
}
if (mediaInfo.SchemaRevision > 5)
{
return audioChannelsStream > 0 ? audioChannelsStream : audioChannels;
}
if (mediaInfo.SchemaRevision >= 3)
{

View File

@ -30,9 +30,11 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
public int AudioBitrate { get; set; }
public TimeSpan RunTime { get; set; }
public int AudioStreamCount { get; set; }
public int AudioChannels { get; set; }
public int AudioChannelsContainer { get; set; }
public int AudioChannelsStream { get; set; }
public string AudioChannelPositions { get; set; }
public string AudioChannelPositionsText { get; set; }
public string AudioChannelPositionsTextContainer { get; set; }
public string AudioChannelPositionsTextStream { get; set; }
public string AudioProfile { get; set; }
public decimal VideoFps { get; set; }
public string AudioLanguages { get; set; }

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
private readonly Logger _logger;
public const int MINIMUM_MEDIA_INFO_SCHEMA_REVISION = 3;
public const int CURRENT_MEDIA_INFO_SCHEMA_REVISION = 5;
public const int CURRENT_MEDIA_INFO_SCHEMA_REVISION = 6;
public VideoFileInfoReader(IDiskProvider diskProvider, Logger logger)
{
@ -110,6 +110,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
int generalRuntime;
int streamCount;
int audioChannels;
int audioChannelsOrig;
int videoBitDepth;
decimal videoFrameRate;
int videoMultiViewCount;
@ -138,11 +139,15 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
int.TryParse(mediaInfo.Get(StreamKind.Audio, 0, "StreamCount"), out streamCount);
string audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)").Split(new string[] { " /" }, StringSplitOptions.None)[0].Trim();
var audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)").Split(new string[] { " /" }, StringSplitOptions.None)[0].Trim();
int.TryParse(audioChannelsStr, out audioChannels);
var audioChannelPositions = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions/String2");
var audioChannelsStrOrig = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)_Original").Split(new string[] { " /" }, StringSplitOptions.None)[0].Trim();
int.TryParse(audioChannelsStrOrig, out audioChannelsOrig);
var audioChannelPositionsText = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions");
var audioChannelPositionsTextOrig = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions_Original");
var audioChannelPositions = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions/String2");
string audioLanguages = mediaInfo.Get(StreamKind.General, 0, "Audio_Language_List");
@ -171,9 +176,11 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
AudioBitrate = audioBitRate,
RunTime = GetBestRuntime(audioRuntime, videoRuntime, generalRuntime),
AudioStreamCount = streamCount,
AudioChannels = audioChannels,
AudioChannelsContainer = audioChannels,
AudioChannelsStream = audioChannelsOrig,
AudioChannelPositions = audioChannelPositions,
AudioChannelPositionsText = audioChannelPositionsText,
AudioChannelPositionsTextContainer = audioChannelPositionsText,
AudioChannelPositionsTextStream = audioChannelPositionsTextOrig,
VideoFps = videoFrameRate,
AudioLanguages = audioLanguages,
Subtitles = subtitles,

View File

@ -105,7 +105,7 @@ namespace NzbDrone.Core.Organizer
VideoColourPrimaries = "BT.2020",
VideoTransferCharacteristics = "HLG",
AudioFormat = "DTS",
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioChannelPositions = "3/2/0.1",
AudioLanguages = "English",
Subtitles = "English/German"
@ -118,7 +118,7 @@ namespace NzbDrone.Core.Organizer
VideoColourPrimaries = "BT.2020",
VideoTransferCharacteristics = "HLG",
AudioFormat = "DTS",
AudioChannels = 6,
AudioChannelsContainer = 6,
AudioChannelPositions = "3/2/0.1",
AudioLanguages = "Japanese",
Subtitles = "Japanese/English"