Fixed: Import failures when audio channels are in an unexpected format
Fixes #2318
This commit is contained in:
parent
9d7547e941
commit
4399d272dc
|
@ -145,5 +145,33 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo.MediaInfoFormatterTests
|
||||||
|
|
||||||
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2.0m);
|
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(2.0m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_use_AudioChannelPositionText_when_AudioChannelChannelPosition_is_invalid()
|
||||||
|
{
|
||||||
|
var mediaInfoModel = new MediaInfoModel
|
||||||
|
{
|
||||||
|
AudioChannels = 6,
|
||||||
|
AudioChannelPositions = "15 objects",
|
||||||
|
AudioChannelPositionsText = "15 objects / Front: L C R, Side: L R, LFE",
|
||||||
|
SchemaRevision = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_remove_atmos_objects_from_AudioChannelPostions()
|
||||||
|
{
|
||||||
|
var mediaInfoModel = new MediaInfoModel
|
||||||
|
{
|
||||||
|
AudioChannels = 2,
|
||||||
|
AudioChannelPositions = "15 objects / 3/2.1",
|
||||||
|
AudioChannelPositionsText = null,
|
||||||
|
SchemaRevision = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
MediaInfoFormatter.FormatAudioChannels(mediaInfoModel).Should().Be(5.1m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Fluent;
|
using NLog.Fluent;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
@ -16,42 +17,19 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
||||||
|
|
||||||
public static decimal FormatAudioChannels(MediaInfoModel mediaInfo)
|
public static decimal FormatAudioChannels(MediaInfoModel mediaInfo)
|
||||||
{
|
{
|
||||||
var audioChannelPositions = mediaInfo.AudioChannelPositions;
|
var audioChannels = FormatAudioChannelsFromAudioChannelPositions(mediaInfo);
|
||||||
var audioChannelPositionsText = mediaInfo.AudioChannelPositionsText;
|
|
||||||
var audioChannels = mediaInfo.AudioChannels;
|
|
||||||
|
|
||||||
if (audioChannelPositions.IsNullOrWhiteSpace())
|
if (audioChannels == null)
|
||||||
{
|
{
|
||||||
if (audioChannelPositionsText.IsNullOrWhiteSpace())
|
audioChannels = FormatAudioChannelsFromAudioChannelPositionsText(mediaInfo);
|
||||||
{
|
|
||||||
if (mediaInfo.SchemaRevision >= 3)
|
|
||||||
{
|
|
||||||
Logger.Debug("Formatiting audio channels using 'AudioChannels', with a value of: '{0}'", audioChannels);
|
|
||||||
|
|
||||||
return audioChannels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (audioChannels == null)
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Debug("Formatiting audio channels using 'AudioChannelPositionsText', with a value of: '{0}'", audioChannelPositionsText);
|
|
||||||
|
|
||||||
return mediaInfo.AudioChannelPositionsText.ContainsIgnoreCase("LFE") ? audioChannels - 1 + 0.1m : audioChannels;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Debug("Formatiting audio channels using 'AudioChannelPositions', with a value of: '{0}'", audioChannelPositions);
|
|
||||||
|
|
||||||
if (audioChannelPositions.Contains("+"))
|
|
||||||
{
|
{
|
||||||
return audioChannelPositions.Split('+')
|
audioChannels = FormatAudioChannelsFromAudioChannels(mediaInfo);
|
||||||
.Sum(s => decimal.Parse(s.Trim(), CultureInfo.InvariantCulture));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioChannelPositions.Replace("Object Based / ", "")
|
return audioChannels ?? 0;
|
||||||
.Split(new string[] { " / " }, StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
.First()
|
|
||||||
.Split('/')
|
|
||||||
.Sum(s => decimal.Parse(s, CultureInfo.InvariantCulture));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FormatAudioCodec(MediaInfoModel mediaInfo, string sceneName)
|
public static string FormatAudioCodec(MediaInfoModel mediaInfo, string sceneName)
|
||||||
|
@ -360,6 +338,79 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
||||||
return videoCodec;
|
return videoCodec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static decimal? FormatAudioChannelsFromAudioChannelPositions(MediaInfoModel mediaInfo)
|
||||||
|
{
|
||||||
|
var audioChannelPositions = mediaInfo.AudioChannelPositions;
|
||||||
|
|
||||||
|
if (audioChannelPositions.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Logger.Debug("Formatiting audio channels using 'AudioChannelPositions', with a value of: '{0}'", audioChannelPositions);
|
||||||
|
|
||||||
|
if (audioChannelPositions.Contains("+"))
|
||||||
|
{
|
||||||
|
return audioChannelPositions.Split('+')
|
||||||
|
.Sum(s => decimal.Parse(s.Trim(), CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Regex.Replace(audioChannelPositions, @"^\d+\sobjects", "", RegexOptions.Compiled | RegexOptions.IgnoreCase)
|
||||||
|
.Replace("Object Based / ", "")
|
||||||
|
.Split(new string[] { " / " }, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.FirstOrDefault()
|
||||||
|
?.Split('/')
|
||||||
|
.Sum(s => decimal.Parse(s, CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Warn(e, "Unable to format audio channels using 'AudioChannelPositions'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static decimal? FormatAudioChannelsFromAudioChannelPositionsText(MediaInfoModel mediaInfo)
|
||||||
|
{
|
||||||
|
var audioChannelPositionsText = mediaInfo.AudioChannelPositionsText;
|
||||||
|
var audioChannels = mediaInfo.AudioChannels;
|
||||||
|
|
||||||
|
if (audioChannelPositionsText.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Logger.Debug("Formatiting audio channels using 'AudioChannelPositionsText', with a value of: '{0}'", audioChannelPositionsText);
|
||||||
|
|
||||||
|
return mediaInfo.AudioChannelPositionsText.ContainsIgnoreCase("LFE") ? audioChannels - 1 + 0.1m : audioChannels;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Warn(e, "Unable to format audio channels using 'AudioChannelPositionsText'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static decimal? FormatAudioChannelsFromAudioChannels(MediaInfoModel mediaInfo)
|
||||||
|
{
|
||||||
|
var audioChannels = mediaInfo.AudioChannels;
|
||||||
|
|
||||||
|
if (mediaInfo.SchemaRevision >= 3)
|
||||||
|
{
|
||||||
|
Logger.Debug("Formatiting audio channels using 'AudioChannels', with a value of: '{0}'", audioChannels);
|
||||||
|
|
||||||
|
return audioChannels;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetSceneNameMatch(string sceneName, params string[] tokens)
|
private static string GetSceneNameMatch(string sceneName, params string[] tokens)
|
||||||
{
|
{
|
||||||
sceneName = sceneName.IsNotNullOrWhiteSpace() ? Path.GetFileNameWithoutExtension(sceneName) : string.Empty;
|
sceneName = sceneName.IsNotNullOrWhiteSpace() ? Path.GetFileNameWithoutExtension(sceneName) : string.Empty;
|
||||||
|
|
Loading…
Reference in New Issue