Fix error with weirdly formatted audioChannelPositions on MediaInfo.

pull/2/head
Leonardo Galli 8 years ago
parent 0083e95019
commit 0668f12e62

@ -100,5 +100,23 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo
stream.Close();
}
[Test]
[TestCase("/ Front: L R", 2.0)]
public void should_correctly_read_audio_channels(string ChannelPositions, decimal formattedChannels)
{
var info = new MediaInfoModel()
{
VideoCodec = "AVC",
AudioFormat = "DTS",
AudioLanguages = "English",
Subtitles = "English",
AudioChannels = 2,
AudioChannelPositions = ChannelPositions,
SchemaRevision = 3,
};
info.FormattedAudioChannels.Should().Be(formattedChannels);
}
}
}

@ -34,27 +34,33 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
{
get
{
if (AudioChannelPositions.IsNullOrWhiteSpace())
{
if (AudioChannelPositionsText.IsNullOrWhiteSpace())
{
if (SchemaRevision >= 3)
{
return AudioChannels;
}
return 0;
}
return AudioChannelPositionsText.ContainsIgnoreCase("LFE") ? AudioChannels - 1 + 0.1m : AudioChannels;
}
return
AudioChannelPositions.Replace("Object Based /", "").Replace(" / ", "$")
.Split('$')
.First()
.Split('/')
.Sum(s => decimal.Parse(s, CultureInfo.InvariantCulture));
try
{
return
AudioChannelPositions.Replace("Object Based /", "").Replace(" / ", "$")
.Split('$')
.First()
.Split('/')
.Sum(s => decimal.Parse(s, CultureInfo.InvariantCulture));
}
catch
{
if (AudioChannelPositionsText.IsNullOrWhiteSpace())
{
if (SchemaRevision >= 3)
{
return AudioChannels;
}
return 0;
}
return AudioChannelPositionsText.ContainsIgnoreCase("LFE") ? AudioChannels - 1 + 0.1m : AudioChannels;
}
}
}
}

Loading…
Cancel
Save