Fixed: Audio Channel Information missing in MediaInfo for certain mkv files with DTS audio

This commit is contained in:
Taloth Saldono 2020-03-22 12:01:20 +01:00 committed by Qstick
parent e6f5d535e9
commit 12041ac290
1 changed files with 20 additions and 2 deletions

View File

@ -3,6 +3,7 @@ using System.Globalization;
using System.IO;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.MediaFiles.MediaInfo
{
@ -43,6 +44,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
if (filename.ToLower().EndsWith(".ts"))
{
// For .ts files we often have to scan more of the file to get all the info we need
mediaInfo.Option("ParseSpeed", "0.3");
}
else
@ -63,15 +65,31 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
int videoRuntime;
int generalRuntime;
//Runtime
// Runtime
int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "PlayTime"), out videoRuntime);
int.TryParse(mediaInfo.Get(StreamKind.Audio, 0, "PlayTime"), out audioRuntime);
int.TryParse(mediaInfo.Get(StreamKind.General, 0, "PlayTime"), out generalRuntime);
// Audio Channels
var audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)").Split(new string[] { " /" }, StringSplitOptions.None)[0].Trim();
var audioChannelPositions = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions/String2");
int.TryParse(audioChannelsStr, out var audioChannels);
if (audioRuntime == 0 && videoRuntime == 0 && generalRuntime == 0)
{
// No runtime, ask mediainfo to scan the whole file
mediaInfo.Option("ParseSpeed", "1.0");
using (var stream = _diskProvider.OpenReadStream(filename))
{
open = mediaInfo.Open(stream);
}
}
else if (audioChannels > 2 && audioChannelPositions.IsNullOrWhiteSpace())
{
// Some files with DTS don't have ChannelPositions unless more of the file is scanned
mediaInfo.Option("ParseSpeed", "0.3");
using (var stream = _diskProvider.OpenReadStream(filename))
{
open = mediaInfo.Open(stream);
@ -119,6 +137,7 @@ 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();
int.TryParse(audioChannelsStr, out audioChannels);
var audioChannelPositions = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions/String2");
var audioChannelPositionsText = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions");
@ -128,7 +147,6 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
string videoProfile = mediaInfo.Get(StreamKind.Video, 0, "Format_Profile").Split(new string[] { " /" }, StringSplitOptions.None)[0].Trim();
string audioProfile = mediaInfo.Get(StreamKind.Audio, 0, "Format_Profile").Split(new string[] { " /" }, StringSplitOptions.None)[0].Trim();
int.TryParse(audioChannelsStr, out audioChannels);
var mediaInfoModel = new MediaInfoModel
{
ContainerFormat = mediaInfo.Get(StreamKind.General, 0, "Format"),