New: MediaInfo VideoBitDepth and AudioChannels

This commit is contained in:
Mark McDowall 2016-08-11 15:49:20 -07:00
parent 914f799f9d
commit db4b0de5e2
4 changed files with 68 additions and 20 deletions

View File

@ -1,4 +1,8 @@
using System; using System;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.MediaFiles.MediaInfo namespace NzbDrone.Core.MediaFiles.MediaInfo
@ -7,6 +11,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
{ {
public string VideoCodec { get; set; } public string VideoCodec { get; set; }
public int VideoBitrate { get; set; } public int VideoBitrate { get; set; }
public int VideoBitDepth { get; set; }
public int Width { get; set; } public int Width { get; set; }
public int Height { get; set; } public int Height { get; set; }
public string AudioFormat { get; set; } public string AudioFormat { get; set; }
@ -14,10 +19,26 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
public TimeSpan RunTime { get; set; } public TimeSpan RunTime { get; set; }
public int AudioStreamCount { get; set; } public int AudioStreamCount { get; set; }
public int AudioChannels { get; set; } public int AudioChannels { get; set; }
public string AudioChannelPositions { get; set; }
public string AudioProfile { get; set; } public string AudioProfile { get; set; }
public decimal VideoFps { get; set; } public decimal VideoFps { get; set; }
public string AudioLanguages { get; set; } public string AudioLanguages { get; set; }
public string Subtitles { get; set; } public string Subtitles { get; set; }
public string ScanType { get; set; } public string ScanType { get; set; }
public int SchemaRevision { get; set; }
[JsonIgnore]
public decimal FormattedAudioChannels
{
get
{
if (AudioChannelPositions.IsNullOrWhiteSpace())
{
return 0;
}
return AudioChannelPositions.Split('/').Sum(s => decimal.Parse(s, CultureInfo.InvariantCulture));
}
}
} }
} }

View File

@ -18,6 +18,8 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly Logger _logger; private readonly Logger _logger;
private const int CURRENT_MEDIA_INFO_SCHEMA_REVISION = 2;
public UpdateMediaInfoService(IDiskProvider diskProvider, public UpdateMediaInfoService(IDiskProvider diskProvider,
IMediaFileService mediaFileService, IMediaFileService mediaFileService,
IVideoFileInfoReader videoFileInfoReader, IVideoFileInfoReader videoFileInfoReader,
@ -47,6 +49,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
if (mediaFile.MediaInfo != null) if (mediaFile.MediaInfo != null)
{ {
mediaFile.MediaInfo.SchemaRevision = CURRENT_MEDIA_INFO_SCHEMA_REVISION;
_mediaFileService.Update(mediaFile); _mediaFileService.Update(mediaFile);
_logger.Debug("Updated MediaInfo for '{0}'", path); _logger.Debug("Updated MediaInfo for '{0}'", path);
} }
@ -61,11 +64,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
return; return;
} }
var mediaFiles = _mediaFileService.GetFilesBySeries(message.Series.Id) var allMediaFiles = _mediaFileService.GetFilesBySeries(message.Series.Id);
.Where(c => c.MediaInfo == null) var filteredMediaFiles = allMediaFiles.Where(c => c.MediaInfo == null || c.MediaInfo.SchemaRevision < CURRENT_MEDIA_INFO_SCHEMA_REVISION).ToList();
.ToList();
UpdateMediaInfo(message.Series, mediaFiles); UpdateMediaInfo(message.Series, filteredMediaFiles);
} }
} }
} }

View File

@ -88,6 +88,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
int generalRuntime; int generalRuntime;
int streamCount; int streamCount;
int audioChannels; int audioChannels;
int videoBitDepth;
decimal videoFrameRate; decimal videoFrameRate;
string subtitles = mediaInfo.Get(StreamKind.General, 0, "Text_Language_List"); string subtitles = mediaInfo.Get(StreamKind.General, 0, "Text_Language_List");
@ -96,6 +97,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "Height"), out height); int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "Height"), out height);
int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "BitRate"), out videoBitRate); int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "BitRate"), out videoBitRate);
decimal.TryParse(mediaInfo.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out videoFrameRate); decimal.TryParse(mediaInfo.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out videoFrameRate);
int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "BitDepth"), out videoBitDepth);
//Runtime //Runtime
int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "PlayTime"), out videoRuntime); int.TryParse(mediaInfo.Get(StreamKind.Video, 0, "PlayTime"), out videoRuntime);
@ -105,7 +107,9 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
string aBitRate = mediaInfo.Get(StreamKind.Audio, 0, "BitRate"); string aBitRate = mediaInfo.Get(StreamKind.Audio, 0, "BitRate");
int aBindex = aBitRate.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase); int aBindex = aBitRate.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase);
if (aBindex > 0) if (aBindex > 0)
{
aBitRate = aBitRate.Remove(aBindex); aBitRate = aBitRate.Remove(aBindex);
}
int.TryParse(aBitRate, out audioBitRate); int.TryParse(aBitRate, out audioBitRate);
int.TryParse(mediaInfo.Get(StreamKind.Audio, 0, "StreamCount"), out streamCount); int.TryParse(mediaInfo.Get(StreamKind.Audio, 0, "StreamCount"), out streamCount);
@ -113,21 +117,30 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
string audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)"); string audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)");
int aCindex = audioChannelsStr.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase); int aCindex = audioChannelsStr.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase);
if (aCindex > 0) if (aCindex > 0)
{
audioChannelsStr = audioChannelsStr.Remove(aCindex); audioChannelsStr = audioChannelsStr.Remove(aCindex);
}
var audioChannelPositions = mediaInfo.Get(StreamKind.Audio, 0, "ChannelPositions/String2");
string audioLanguages = mediaInfo.Get(StreamKind.General, 0, "Audio_Language_List"); string audioLanguages = mediaInfo.Get(StreamKind.General, 0, "Audio_Language_List");
string audioProfile = mediaInfo.Get(StreamKind.Audio, 0, "Format_Profile"); string audioProfile = mediaInfo.Get(StreamKind.Audio, 0, "Format_Profile");
int aPindex = audioProfile.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase); int aPindex = audioProfile.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase);
if (aPindex > 0) if (aPindex > 0)
{
audioProfile = audioProfile.Remove(aPindex); audioProfile = audioProfile.Remove(aPindex);
}
int.TryParse(audioChannelsStr, out audioChannels); int.TryParse(audioChannelsStr, out audioChannels);
var mediaInfoModel = new MediaInfoModel var mediaInfoModel = new MediaInfoModel
{ {
VideoCodec = mediaInfo.Get(StreamKind.Video, 0, "Codec/String"), VideoCodec = mediaInfo.Get(StreamKind.Video, 0, "Codec/String"),
VideoBitrate = videoBitRate, VideoBitrate = videoBitRate,
VideoBitDepth = videoBitDepth,
Height = height, Height = height,
Width = width, Width = width,
AudioFormat = mediaInfo.Get(StreamKind.Audio, 0, "Format"), AudioFormat = mediaInfo.Get(StreamKind.Audio, 0, "Format"),
@ -135,6 +148,7 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
RunTime = GetBestRuntime(audioRuntime, videoRuntime, generalRuntime), RunTime = GetBestRuntime(audioRuntime, videoRuntime, generalRuntime),
AudioStreamCount = streamCount, AudioStreamCount = streamCount,
AudioChannels = audioChannels, AudioChannels = audioChannels,
AudioChannelPositions = audioChannelPositions,
AudioProfile = audioProfile.Trim(), AudioProfile = audioProfile.Trim(),
VideoFps = videoFrameRate, VideoFps = videoFrameRate,
AudioLanguages = audioLanguages, AudioLanguages = audioLanguages,

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -444,60 +445,60 @@ namespace NzbDrone.Core.Organizer
{ {
if (episodeFile.MediaInfo == null) return; if (episodeFile.MediaInfo == null) return;
string mediaInfoVideo; string videoCodec;
switch (episodeFile.MediaInfo.VideoCodec) switch (episodeFile.MediaInfo.VideoCodec)
{ {
case "AVC": case "AVC":
if (episodeFile.SceneName.IsNotNullOrWhiteSpace() && Path.GetFileNameWithoutExtension(episodeFile.SceneName).Contains("h264")) if (episodeFile.SceneName.IsNotNullOrWhiteSpace() && Path.GetFileNameWithoutExtension(episodeFile.SceneName).Contains("h264"))
{ {
mediaInfoVideo = "h264"; videoCodec = "h264";
} }
else else
{ {
mediaInfoVideo = "x264"; videoCodec = "x264";
} }
break; break;
case "V_MPEGH/ISO/HEVC": case "V_MPEGH/ISO/HEVC":
if (episodeFile.SceneName.IsNotNullOrWhiteSpace() && Path.GetFileNameWithoutExtension(episodeFile.SceneName).Contains("h265")) if (episodeFile.SceneName.IsNotNullOrWhiteSpace() && Path.GetFileNameWithoutExtension(episodeFile.SceneName).Contains("h265"))
{ {
mediaInfoVideo = "h265"; videoCodec = "h265";
} }
else else
{ {
mediaInfoVideo = "x265"; videoCodec = "x265";
} }
break; break;
default: default:
mediaInfoVideo = episodeFile.MediaInfo.VideoCodec; videoCodec = episodeFile.MediaInfo.VideoCodec;
break; break;
} }
string mediaInfoAudio; string audioCodec;
switch (episodeFile.MediaInfo.AudioFormat) switch (episodeFile.MediaInfo.AudioFormat)
{ {
case "AC-3": case "AC-3":
mediaInfoAudio = "AC3"; audioCodec = "AC3";
break; break;
case "MPEG Audio": case "MPEG Audio":
if (episodeFile.MediaInfo.AudioProfile == "Layer 3") if (episodeFile.MediaInfo.AudioProfile == "Layer 3")
{ {
mediaInfoAudio = "MP3"; audioCodec = "MP3";
} }
else else
{ {
mediaInfoAudio = episodeFile.MediaInfo.AudioFormat; audioCodec = episodeFile.MediaInfo.AudioFormat;
} }
break; break;
case "DTS": case "DTS":
mediaInfoAudio = episodeFile.MediaInfo.AudioFormat; audioCodec = episodeFile.MediaInfo.AudioFormat;
break; break;
default: default:
mediaInfoAudio = episodeFile.MediaInfo.AudioFormat; audioCodec = episodeFile.MediaInfo.AudioFormat;
break; break;
} }
@ -518,12 +519,22 @@ namespace NzbDrone.Core.Organizer
mediaInfoSubtitleLanguages = string.Format("[{0}]", mediaInfoSubtitleLanguages); mediaInfoSubtitleLanguages = string.Format("[{0}]", mediaInfoSubtitleLanguages);
} }
tokenHandlers["{MediaInfo Video}"] = m => mediaInfoVideo; var videoBitDepth = episodeFile.MediaInfo.VideoBitDepth > 0 ? episodeFile.MediaInfo.VideoBitDepth.ToString() : string.Empty;
tokenHandlers["{MediaInfo Audio}"] = m => mediaInfoAudio; var audioChannels = episodeFile.MediaInfo.FormattedAudioChannels > 0 ?
episodeFile.MediaInfo.FormattedAudioChannels.ToString(CultureInfo.InvariantCulture) :
string.Empty;
tokenHandlers["{MediaInfo Simple}"] = m => string.Format("{0} {1}", mediaInfoVideo, mediaInfoAudio); tokenHandlers["{MediaInfo Video}"] = m => videoCodec;
tokenHandlers["{MediaInfo VideoCodec}"] = m => videoCodec;
tokenHandlers["{MediaInfo VideoBitDepth}"] = m => videoBitDepth;
tokenHandlers["{MediaInfo Full}"] = m => string.Format("{0} {1}{2} {3}", mediaInfoVideo, mediaInfoAudio, mediaInfoAudioLanguages, mediaInfoSubtitleLanguages); tokenHandlers["{MediaInfo Audio}"] = m => audioCodec;
tokenHandlers["{MediaInfo AudioCodec}"] = m => audioCodec;
tokenHandlers["{MediaInfo AudioChannels}"] = m => audioChannels;
tokenHandlers["{MediaInfo Simple}"] = m => string.Format("{0} {1}", videoCodec, audioCodec);
tokenHandlers["{MediaInfo Full}"] = m => string.Format("{0} {1}{2} {3}", videoCodec, audioCodec, mediaInfoAudioLanguages, mediaInfoSubtitleLanguages);
} }
private string GetLanguagesToken(string mediaInfoLanguages) private string GetLanguagesToken(string mediaInfoLanguages)