diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 088acbedda..a4a1d5b4d1 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -483,8 +483,7 @@ namespace MediaBrowser.Common.Kernel CompositionContainer = MefUtils.GetSafeCompositionContainer(Assemblies.Select(i => new AssemblyCatalog(i))); - CompositionContainer.ComposeExportedValue("kernel", this); - CompositionContainer.ComposeExportedValue("logger", Logging.LogManager.GetLogger("App")); + ComposeExportedValues(CompositionContainer); CompositionContainer.ComposeParts(this); @@ -493,6 +492,15 @@ namespace MediaBrowser.Common.Kernel CompositionContainer.Catalog.Dispose(); } + /// + /// Composes the exported values. + /// + /// The container. + protected virtual void ComposeExportedValues(CompositionContainer container) + { + container.ComposeExportedValue("logger", Logging.LogManager.GetLogger("App")); + } + /// /// Gets the composable part assemblies. /// diff --git a/MediaBrowser.Common/Logging/Logger.cs b/MediaBrowser.Common/Logging/Logger.cs index 33d6b7f737..a6cb6d8858 100644 --- a/MediaBrowser.Common/Logging/Logger.cs +++ b/MediaBrowser.Common/Logging/Logger.cs @@ -34,16 +34,6 @@ namespace MediaBrowser.Common.Logging LogEntry(message, LogSeverity.Debug, null, paramList); } - /// - /// Logs the error. - /// - /// The message. - /// The param list. - public static void LogError(string message, params object[] paramList) - { - LogEntry(message, LogSeverity.Error, null, paramList); - } - /// /// Logs the exception. /// @@ -54,17 +44,6 @@ namespace MediaBrowser.Common.Logging { LogEntry(message, LogSeverity.Error, ex, paramList); } - - /// - /// Fatals the exception. - /// - /// The message. - /// The ex. - /// The param list. - public static void FatalException(string message, Exception ex, params object[] paramList) - { - LogEntry(message, LogSeverity.Fatal, ex, paramList); - } /// /// Logs the warning. diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index cef79fe560..8d2a68cb82 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -202,12 +202,14 @@ namespace MediaBrowser.Controller.Entities /// Dictionary{System.StringIComparer{BaseItem}}. protected virtual Dictionary> GetSortByOptions() { + var logger = LogManager.GetLogger("BaseItemComparer"); + return new Dictionary> { - {LocalizedStrings.Instance.GetString("NameDispPref"), new BaseItemComparer(SortOrder.Name)}, - {LocalizedStrings.Instance.GetString("DateDispPref"), new BaseItemComparer(SortOrder.Date)}, - {LocalizedStrings.Instance.GetString("RatingDispPref"), new BaseItemComparer(SortOrder.Rating)}, - {LocalizedStrings.Instance.GetString("RuntimeDispPref"), new BaseItemComparer(SortOrder.Runtime)}, - {LocalizedStrings.Instance.GetString("YearDispPref"), new BaseItemComparer(SortOrder.Year)} + {LocalizedStrings.Instance.GetString("NameDispPref"), new BaseItemComparer(SortOrder.Name, logger)}, + {LocalizedStrings.Instance.GetString("DateDispPref"), new BaseItemComparer(SortOrder.Date, logger)}, + {LocalizedStrings.Instance.GetString("RatingDispPref"), new BaseItemComparer(SortOrder.Rating, logger)}, + {LocalizedStrings.Instance.GetString("RuntimeDispPref"), new BaseItemComparer(SortOrder.Runtime, logger)}, + {LocalizedStrings.Instance.GetString("YearDispPref"), new BaseItemComparer(SortOrder.Year, logger)} }; } @@ -221,7 +223,7 @@ namespace MediaBrowser.Controller.Entities { IComparer sorting; SortByOptions.TryGetValue(name ?? "", out sorting); - return sorting ?? new BaseItemComparer(SortOrder.Name); + return sorting ?? new BaseItemComparer(SortOrder.Name, LogManager.GetLogger("BaseItemComparer")); } /// diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index f8f48d8de9..b4c553c66e 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -16,10 +16,12 @@ using MediaBrowser.Controller.Updates; using MediaBrowser.Controller.Weather; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.IO; +using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.System; using System; using System.Collections.Generic; using System.ComponentModel.Composition; +using System.ComponentModel.Composition.Hosting; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -304,14 +306,48 @@ namespace MediaBrowser.Controller /// The zip client. private IZipClient ZipClient { get; set; } + /// + /// Gets or sets the bluray examiner. + /// + /// The bluray examiner. + private IBlurayExaminer BlurayExaminer { get; set; } + /// /// Creates a kernel based on a Data path, which is akin to our current programdata path /// - public Kernel(IIsoManager isoManager, IZipClient zipClient) + public Kernel(IIsoManager isoManager, IZipClient zipClient, IBlurayExaminer blurayExaminer) : base(isoManager) { + if (isoManager == null) + { + throw new ArgumentNullException("isoManager"); + } + + if (zipClient == null) + { + throw new ArgumentNullException("zipClient"); + } + + if (blurayExaminer == null) + { + throw new ArgumentNullException("blurayExaminer"); + } + Instance = this; ZipClient = zipClient; + BlurayExaminer = blurayExaminer; + } + + /// + /// Composes the exported values. + /// + /// The container. + protected override void ComposeExportedValues(CompositionContainer container) + { + base.ComposeExportedValues(container); + + container.ComposeExportedValue("kernel", this); + container.ComposeExportedValue("blurayExaminer", BlurayExaminer); } /// diff --git a/MediaBrowser.Controller/Library/DtoBuilder.cs b/MediaBrowser.Controller/Library/DtoBuilder.cs index b16671e9e2..3fa438175a 100644 --- a/MediaBrowser.Controller/Library/DtoBuilder.cs +++ b/MediaBrowser.Controller/Library/DtoBuilder.cs @@ -6,6 +6,7 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.Drawing; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.IO; @@ -24,6 +25,8 @@ namespace MediaBrowser.Controller.Library /// const string IndexFolderDelimeter = "-index-"; + private static ILogger Logger = LogManager.GetLogger("DtoBuilder"); + /// /// Gets the dto base item. /// @@ -55,7 +58,7 @@ namespace MediaBrowser.Controller.Library catch (Exception ex) { // Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions - Logger.LogException("Error generating PrimaryImageAspectRatio for {0}", ex, item.Name); + Logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, item.Name); } } @@ -116,7 +119,7 @@ namespace MediaBrowser.Controller.Library catch (Exception ex) { // Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions - Logger.LogException("Error generating PrimaryImageAspectRatio for {0}", ex, item.Name); + Logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, item.Name); } } @@ -211,7 +214,7 @@ namespace MediaBrowser.Controller.Library } catch (FileNotFoundException) { - Logger.LogError("Image file does not exist: {0}", path); + Logger.Error("Image file does not exist: {0}", path); return; } @@ -572,7 +575,7 @@ namespace MediaBrowser.Controller.Library } catch (IOException ex) { - Logger.LogException("Error getting person {0}", ex, c.Name); + Logger.ErrorException("Error getting person {0}", ex, c.Name); return null; } }) diff --git a/MediaBrowser.Controller/Localization/Ratings.cs b/MediaBrowser.Controller/Localization/Ratings.cs index 946e25f536..2f7188a9bd 100644 --- a/MediaBrowser.Controller/Localization/Ratings.cs +++ b/MediaBrowser.Controller/Localization/Ratings.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using MediaBrowser.Common.Logging; namespace MediaBrowser.Controller.Localization { @@ -39,7 +40,7 @@ namespace MediaBrowser.Controller.Localization public static Dictionary Initialize(bool blockUnrated) { //build our ratings dictionary from the combined local one and us one - ratingsDef = new RatingsDefinition(Path.Combine(Kernel.Instance.ApplicationPaths.LocalizationPath, "Ratings-" + Kernel.Instance.Configuration.MetadataCountryCode+".txt")); + ratingsDef = new RatingsDefinition(Path.Combine(Kernel.Instance.ApplicationPaths.LocalizationPath, "Ratings-" + Kernel.Instance.Configuration.MetadataCountryCode + ".txt"), LogManager.GetLogger("RatingsDefinition")); //global value of None var dict = new Dictionary {{"None", -1}}; foreach (var pair in ratingsDef.RatingsDict) diff --git a/MediaBrowser.Controller/Localization/RatingsDefinition.cs b/MediaBrowser.Controller/Localization/RatingsDefinition.cs index 65bd3bcbb4..e0753da2e0 100644 --- a/MediaBrowser.Controller/Localization/RatingsDefinition.cs +++ b/MediaBrowser.Controller/Localization/RatingsDefinition.cs @@ -1,7 +1,7 @@ -using System; +using MediaBrowser.Model.Logging; +using System; using System.Collections.Generic; using System.IO; -using MediaBrowser.Common.Logging; namespace MediaBrowser.Controller.Localization { @@ -10,13 +10,22 @@ namespace MediaBrowser.Controller.Localization /// public class RatingsDefinition { + /// + /// Gets or sets the logger. + /// + /// The logger. + private ILogger Logger { get; set; } + /// /// Initializes a new instance of the class. /// /// The file. - public RatingsDefinition(string file) + /// The logger. + public RatingsDefinition(string file, ILogger logger) { - Logger.LogInfo("Loading Certification Ratings from file " + file); + Logger = logger; + + Logger.Info("Loading Certification Ratings from file " + file); this.file = file; if (!Load()) { @@ -99,7 +108,7 @@ namespace MediaBrowser.Controller.Localization } else { - Logger.LogError("Invalid line in ratings file " + file + "(" + line + ")"); + Logger.Error("Invalid line in ratings file " + file + "(" + line + ")"); } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index da2bc23e81..58e1b3fb0a 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -119,7 +119,6 @@ - @@ -136,7 +135,6 @@ - @@ -203,10 +201,6 @@ - - {07b509c0-0c28-4f3f-8963-5263281f7e3d} - BDInfo - {9142eefa-7570-41e1-bfcc-468bb571af2f} MediaBrowser.Common diff --git a/MediaBrowser.Controller/Providers/MediaInfo/BDInfoProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/BDInfoProvider.cs deleted file mode 100644 index 6214cb0dae..0000000000 --- a/MediaBrowser.Controller/Providers/MediaInfo/BDInfoProvider.cs +++ /dev/null @@ -1,265 +0,0 @@ -using BDInfo; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.MediaInfo; -using MediaBrowser.Model.Entities; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; - -namespace MediaBrowser.Controller.Providers.MediaInfo -{ - /// - /// Extracts dvd information using VgtMpeg - /// - internal static class BDInfoProvider - { - internal static void FetchBdInfo(BaseItem item, string inputPath, FileSystemRepository bdInfoCache, CancellationToken cancellationToken) - { - var video = (Video)item; - - // Get the path to the cache file - var cacheName = item.Id + "_" + item.DateModified.Ticks; - - var cacheFile = bdInfoCache.GetResourcePath(cacheName, ".pb"); - - BDInfoResult result; - - try - { - result = Kernel.Instance.ProtobufSerializer.DeserializeFromFile(cacheFile); - } - catch (FileNotFoundException) - { - result = GetBDInfo(inputPath); - - Kernel.Instance.ProtobufSerializer.SerializeToFile(result, cacheFile); - } - - cancellationToken.ThrowIfCancellationRequested(); - - int? currentHeight = null; - int? currentWidth = null; - int? currentBitRate = null; - - var videoStream = video.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video); - - // Grab the values that ffprobe recorded - if (videoStream != null) - { - currentBitRate = videoStream.BitRate; - currentWidth = videoStream.Width; - currentHeight = videoStream.Height; - } - - // Fill video properties from the BDInfo result - Fetch(video, inputPath, result); - - videoStream = video.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video); - - // Use the ffprobe values if these are empty - if (videoStream != null) - { - videoStream.BitRate = IsEmpty(videoStream.BitRate) ? currentBitRate : videoStream.BitRate; - videoStream.Width = IsEmpty(videoStream.Width) ? currentWidth : videoStream.Width; - videoStream.Height = IsEmpty(videoStream.Height) ? currentHeight : videoStream.Height; - } - } - - /// - /// Determines whether the specified num is empty. - /// - /// The num. - /// true if the specified num is empty; otherwise, false. - private static bool IsEmpty(int? num) - { - return !num.HasValue || num.Value == 0; - } - - /// - /// Fills video properties from the VideoStream of the largest playlist - /// - /// The video. - /// The input path. - /// The stream. - private static void Fetch(Video video, string inputPath, BDInfoResult stream) - { - // Check all input for null/empty/zero - - video.MediaStreams = stream.MediaStreams; - - if (stream.RunTimeTicks.HasValue && stream.RunTimeTicks.Value > 0) - { - video.RunTimeTicks = stream.RunTimeTicks; - } - - video.PlayableStreamFileNames = stream.Files.ToList(); - - if (stream.Chapters != null) - { - video.Chapters = stream.Chapters.Select(c => new ChapterInfo - { - StartPositionTicks = TimeSpan.FromSeconds(c).Ticks - - }).ToList(); - } - } - - /// - /// Gets information about the longest playlist on a bdrom - /// - /// The path. - /// VideoStream. - private static BDInfoResult GetBDInfo(string path) - { - var bdrom = new BDROM(path); - - bdrom.Scan(); - - // Get the longest playlist - var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid); - - var outputStream = new BDInfoResult - { - MediaStreams = new List() - }; - - if (playlist == null) - { - return outputStream; - } - - outputStream.Chapters = playlist.Chapters; - - outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks; - - var mediaStreams = new List {}; - - foreach (var stream in playlist.SortedStreams) - { - var videoStream = stream as TSVideoStream; - - if (videoStream != null) - { - AddVideoStream(mediaStreams, videoStream); - continue; - } - - var audioStream = stream as TSAudioStream; - - if (audioStream != null) - { - AddAudioStream(mediaStreams, audioStream); - continue; - } - - var textStream = stream as TSTextStream; - - if (textStream != null) - { - AddSubtitleStream(mediaStreams, textStream); - continue; - } - - var graphicsStream = stream as TSGraphicsStream; - - if (graphicsStream != null) - { - AddSubtitleStream(mediaStreams, graphicsStream); - } - } - - outputStream.MediaStreams = mediaStreams; - - if (playlist.StreamClips != null && playlist.StreamClips.Any()) - { - // Get the files in the playlist - outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToList(); - } - - return outputStream; - } - - /// - /// Adds the video stream. - /// - /// The streams. - /// The video stream. - private static void AddVideoStream(List streams, TSVideoStream videoStream) - { - var mediaStream = new MediaStream - { - BitRate = Convert.ToInt32(videoStream.BitRate), - Width = videoStream.Width, - Height = videoStream.Height, - Codec = videoStream.CodecShortName, - ScanType = videoStream.IsInterlaced ? "interlaced" : "progressive", - Type = MediaStreamType.Video, - Index = streams.Count - }; - - if (videoStream.FrameRateDenominator > 0) - { - float frameRateEnumerator = videoStream.FrameRateEnumerator; - float frameRateDenominator = videoStream.FrameRateDenominator; - - mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator; - } - - streams.Add(mediaStream); - } - - /// - /// Adds the audio stream. - /// - /// The streams. - /// The audio stream. - private static void AddAudioStream(List streams, TSAudioStream audioStream) - { - streams.Add(new MediaStream - { - BitRate = Convert.ToInt32(audioStream.BitRate), - Codec = audioStream.CodecShortName, - Language = audioStream.LanguageCode, - Channels = audioStream.ChannelCount, - SampleRate = audioStream.SampleRate, - Type = MediaStreamType.Audio, - Index = streams.Count - }); - } - - /// - /// Adds the subtitle stream. - /// - /// The streams. - /// The text stream. - private static void AddSubtitleStream(List streams, TSTextStream textStream) - { - streams.Add(new MediaStream - { - Language = textStream.LanguageCode, - Codec = textStream.CodecShortName, - Type = MediaStreamType.Subtitle, - Index = streams.Count - }); - } - - /// - /// Adds the subtitle stream. - /// - /// The streams. - /// The text stream. - private static void AddSubtitleStream(List streams, TSGraphicsStream textStream) - { - streams.Add(new MediaStream - { - Language = textStream.LanguageCode, - Codec = textStream.CodecShortName, - Type = MediaStreamType.Subtitle, - Index = streams.Count - }); - } - } -} diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs index 5092429e84..2df495b23c 100644 --- a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs +++ b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeVideoInfoProvider.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; using System.ComponentModel.Composition; @@ -25,12 +26,28 @@ namespace MediaBrowser.Controller.Providers.MediaInfo /// The bd info cache. private FileSystemRepository BdInfoCache { get; set; } + /// + /// Gets or sets the bluray examiner. + /// + /// The bluray examiner. + private IBlurayExaminer BlurayExaminer { get; set; } + /// /// Initializes a new instance of the class. /// - public FFProbeVideoInfoProvider() + /// The bluray examiner. + /// blurayExaminer + [ImportingConstructor] + public FFProbeVideoInfoProvider([Import("blurayExaminer")] IBlurayExaminer blurayExaminer) : base() { + if (blurayExaminer == null) + { + throw new ArgumentNullException("blurayExaminer"); + } + + BlurayExaminer = blurayExaminer; + BdInfoCache = new FileSystemRepository(Path.Combine(Kernel.Instance.ApplicationPaths.CachePath, "bdinfo")); } @@ -183,7 +200,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo if (video.VideoType == VideoType.BluRay || (video.IsoType.HasValue && video.IsoType.Value == IsoType.BluRay)) { var inputPath = isoMount != null ? isoMount.MountedPath : video.Path; - BDInfoProvider.FetchBdInfo(video, inputPath, BdInfoCache, cancellationToken); + FetchBdInfo(video, inputPath, BdInfoCache, cancellationToken); } AddExternalSubtitles(video); @@ -239,7 +256,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo /// /// The dummy chapter duration /// - private static readonly long DummyChapterDuration = TimeSpan.FromMinutes(10).Ticks; + private readonly long DummyChapterDuration = TimeSpan.FromMinutes(10).Ticks; /// /// Adds the dummy chapters. @@ -274,6 +291,114 @@ namespace MediaBrowser.Controller.Providers.MediaInfo video.Chapters = chapters; } + /// + /// Fetches the bd info. + /// + /// The item. + /// The input path. + /// The bd info cache. + /// The cancellation token. + private void FetchBdInfo(BaseItem item, string inputPath, FileSystemRepository bdInfoCache, CancellationToken cancellationToken) + { + var video = (Video)item; + + // Get the path to the cache file + var cacheName = item.Id + "_" + item.DateModified.Ticks; + + var cacheFile = bdInfoCache.GetResourcePath(cacheName, ".pb"); + + BlurayDiscInfo result; + + try + { + result = Kernel.Instance.ProtobufSerializer.DeserializeFromFile(cacheFile); + } + catch (FileNotFoundException) + { + result = GetBDInfo(inputPath); + + Kernel.Instance.ProtobufSerializer.SerializeToFile(result, cacheFile); + } + + cancellationToken.ThrowIfCancellationRequested(); + + int? currentHeight = null; + int? currentWidth = null; + int? currentBitRate = null; + + var videoStream = video.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video); + + // Grab the values that ffprobe recorded + if (videoStream != null) + { + currentBitRate = videoStream.BitRate; + currentWidth = videoStream.Width; + currentHeight = videoStream.Height; + } + + // Fill video properties from the BDInfo result + Fetch(video, inputPath, result); + + videoStream = video.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video); + + // Use the ffprobe values if these are empty + if (videoStream != null) + { + videoStream.BitRate = IsEmpty(videoStream.BitRate) ? currentBitRate : videoStream.BitRate; + videoStream.Width = IsEmpty(videoStream.Width) ? currentWidth : videoStream.Width; + videoStream.Height = IsEmpty(videoStream.Height) ? currentHeight : videoStream.Height; + } + } + + /// + /// Determines whether the specified num is empty. + /// + /// The num. + /// true if the specified num is empty; otherwise, false. + private bool IsEmpty(int? num) + { + return !num.HasValue || num.Value == 0; + } + + /// + /// Fills video properties from the VideoStream of the largest playlist + /// + /// The video. + /// The input path. + /// The stream. + private void Fetch(Video video, string inputPath, BlurayDiscInfo stream) + { + // Check all input for null/empty/zero + + video.MediaStreams = stream.MediaStreams; + + if (stream.RunTimeTicks.HasValue && stream.RunTimeTicks.Value > 0) + { + video.RunTimeTicks = stream.RunTimeTicks; + } + + video.PlayableStreamFileNames = stream.Files.ToList(); + + if (stream.Chapters != null) + { + video.Chapters = stream.Chapters.Select(c => new ChapterInfo + { + StartPositionTicks = TimeSpan.FromSeconds(c).Ticks + + }).ToList(); + } + } + + /// + /// Gets information about the longest playlist on a bdrom + /// + /// The path. + /// VideoStream. + private BlurayDiscInfo GetBDInfo(string path) + { + return BlurayExaminer.GetDiscInfo(path); + } + /// /// Releases unmanaged and - optionally - managed resources. /// diff --git a/MediaBrowser.Controller/Sorting/BaseItemComparer.cs b/MediaBrowser.Controller/Sorting/BaseItemComparer.cs index 6e49f396f7..94c16775d0 100644 --- a/MediaBrowser.Controller/Sorting/BaseItemComparer.cs +++ b/MediaBrowser.Controller/Sorting/BaseItemComparer.cs @@ -1,5 +1,5 @@ -using MediaBrowser.Common.Logging; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; @@ -21,12 +21,20 @@ namespace MediaBrowser.Controller.Sorting { /// private readonly StringComparison _compareCulture = StringComparison.CurrentCultureIgnoreCase; + /// + /// Gets or sets the logger. + /// + /// The logger. + private ILogger Logger { get; set; } + /// /// Initializes a new instance of the class. /// /// The order. - public BaseItemComparer(SortOrder order) { + /// The logger. + public BaseItemComparer(SortOrder order, ILogger logger) { _order = order; + Logger = logger; } /// @@ -34,18 +42,24 @@ namespace MediaBrowser.Controller.Sorting { /// /// The order. /// The compare. - public BaseItemComparer(SortOrder order, StringComparison compare) { + /// The logger. + public BaseItemComparer(SortOrder order, StringComparison compare, ILogger logger) + { _order = order; _compareCulture = compare; + Logger = logger; } /// /// Initializes a new instance of the class. /// /// The property. - public BaseItemComparer(string property) { + /// The logger. + public BaseItemComparer(string property, ILogger logger) + { _order = SortOrder.Custom; _propertyName = property; + Logger = logger; } /// @@ -53,10 +67,13 @@ namespace MediaBrowser.Controller.Sorting { /// /// The property. /// The compare. - public BaseItemComparer(string property, StringComparison compare) { + /// The logger. + public BaseItemComparer(string property, StringComparison compare, ILogger logger) + { _order = SortOrder.Custom; _propertyName = property; _compareCulture = compare; + Logger = logger; } #region IComparer Members @@ -102,7 +119,7 @@ namespace MediaBrowser.Controller.Sorting { case SortOrder.Custom: - Logger.LogDebugInfo("Sorting on custom field " + _propertyName); + Logger.Debug("Sorting on custom field " + _propertyName); var yProp = y.GetType().GetProperty(_propertyName); var xProp = x.GetType().GetProperty(_propertyName); if (yProp == null || xProp == null) break; @@ -143,7 +160,7 @@ namespace MediaBrowser.Controller.Sorting { /// The s2. /// The compare culture. /// System.Int32. - public static int AlphaNumericCompare(string s1, string s2, StringComparison compareCulture) { + private int AlphaNumericCompare(string s1, string s2, StringComparison compareCulture) { // http://dotnetperls.com/Content/Alphanumeric-Sorting.aspx int len1 = s1.Length; @@ -213,7 +230,7 @@ namespace MediaBrowser.Controller.Sorting { if (!isValid) { - Logger.LogError("Error comparing numeric strings: " + str1 + "/" + str2); + Logger.Error("Error comparing numeric strings: " + str1 + "/" + str2); result = String.Compare(str1, str2, compareCulture); } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index dd11a131ac..a9c3fcfece 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -45,6 +45,7 @@ + @@ -67,6 +68,7 @@ + diff --git a/MediaBrowser.Controller/MediaInfo/BDInfoResult.cs b/MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs similarity index 93% rename from MediaBrowser.Controller/MediaInfo/BDInfoResult.cs rename to MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs index 08d1ce8a0b..1a05cfe091 100644 --- a/MediaBrowser.Controller/MediaInfo/BDInfoResult.cs +++ b/MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs @@ -2,13 +2,13 @@ using ProtoBuf; using System.Collections.Generic; -namespace MediaBrowser.Controller.MediaInfo +namespace MediaBrowser.Model.MediaInfo { /// /// Represents the result of BDInfo output /// [ProtoContract] - public class BDInfoResult + public class BlurayDiscInfo { /// /// Gets or sets the media streams. diff --git a/MediaBrowser.Model/MediaInfo/IBlurayExaminer.cs b/MediaBrowser.Model/MediaInfo/IBlurayExaminer.cs new file mode 100644 index 0000000000..78d5b197f4 --- /dev/null +++ b/MediaBrowser.Model/MediaInfo/IBlurayExaminer.cs @@ -0,0 +1,16 @@ + +namespace MediaBrowser.Model.MediaInfo +{ + /// + /// Interface IBlurayExaminer + /// + public interface IBlurayExaminer + { + /// + /// Gets the disc info. + /// + /// The path. + /// BlurayDiscInfo. + BlurayDiscInfo GetDiscInfo(string path); + } +} diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs index b06c8f04e2..f52a1cbf08 100644 --- a/MediaBrowser.ServerApplication/App.xaml.cs +++ b/MediaBrowser.ServerApplication/App.xaml.cs @@ -170,7 +170,7 @@ namespace MediaBrowser.ServerApplication /// IKernel. protected override IKernel InstantiateKernel() { - return new Kernel(new PismoIsoManager(LogManager.GetLogger("PismoIsoManager")), new DotNetZipClient()); + return new Kernel(new PismoIsoManager(LogManager.GetLogger("PismoIsoManager")), new DotNetZipClient(), new BdInfoExaminer()); } /// diff --git a/MediaBrowser.ServerApplication/Implementations/BdInfoExaminer.cs b/MediaBrowser.ServerApplication/Implementations/BdInfoExaminer.cs new file mode 100644 index 0000000000..dbde630bed --- /dev/null +++ b/MediaBrowser.ServerApplication/Implementations/BdInfoExaminer.cs @@ -0,0 +1,170 @@ +using BDInfo; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.MediaInfo; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.ServerApplication.Implementations +{ + /// + /// Class BdInfoExaminer + /// + public class BdInfoExaminer : IBlurayExaminer + { + /// + /// Gets the disc info. + /// + /// The path. + /// BlurayDiscInfo. + public BlurayDiscInfo GetDiscInfo(string path) + { + var bdrom = new BDROM(path); + + bdrom.Scan(); + + // Get the longest playlist + var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid); + + var outputStream = new BlurayDiscInfo + { + MediaStreams = new List() + }; + + if (playlist == null) + { + return outputStream; + } + + outputStream.Chapters = playlist.Chapters; + + outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks; + + var mediaStreams = new List { }; + + foreach (var stream in playlist.SortedStreams) + { + var videoStream = stream as TSVideoStream; + + if (videoStream != null) + { + AddVideoStream(mediaStreams, videoStream); + continue; + } + + var audioStream = stream as TSAudioStream; + + if (audioStream != null) + { + AddAudioStream(mediaStreams, audioStream); + continue; + } + + var textStream = stream as TSTextStream; + + if (textStream != null) + { + AddSubtitleStream(mediaStreams, textStream); + continue; + } + + var graphicsStream = stream as TSGraphicsStream; + + if (graphicsStream != null) + { + AddSubtitleStream(mediaStreams, graphicsStream); + } + } + + outputStream.MediaStreams = mediaStreams; + + if (playlist.StreamClips != null && playlist.StreamClips.Any()) + { + // Get the files in the playlist + outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToList(); + } + + return outputStream; + } + + /// + /// Adds the video stream. + /// + /// The streams. + /// The video stream. + private void AddVideoStream(List streams, TSVideoStream videoStream) + { + var mediaStream = new MediaStream + { + BitRate = Convert.ToInt32(videoStream.BitRate), + Width = videoStream.Width, + Height = videoStream.Height, + Codec = videoStream.CodecShortName, + ScanType = videoStream.IsInterlaced ? "interlaced" : "progressive", + Type = MediaStreamType.Video, + Index = streams.Count + }; + + if (videoStream.FrameRateDenominator > 0) + { + float frameRateEnumerator = videoStream.FrameRateEnumerator; + float frameRateDenominator = videoStream.FrameRateDenominator; + + mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator; + } + + streams.Add(mediaStream); + } + + /// + /// Adds the audio stream. + /// + /// The streams. + /// The audio stream. + private void AddAudioStream(List streams, TSAudioStream audioStream) + { + streams.Add(new MediaStream + { + BitRate = Convert.ToInt32(audioStream.BitRate), + Codec = audioStream.CodecShortName, + Language = audioStream.LanguageCode, + Channels = audioStream.ChannelCount, + SampleRate = audioStream.SampleRate, + Type = MediaStreamType.Audio, + Index = streams.Count + }); + } + + /// + /// Adds the subtitle stream. + /// + /// The streams. + /// The text stream. + private void AddSubtitleStream(List streams, TSTextStream textStream) + { + streams.Add(new MediaStream + { + Language = textStream.LanguageCode, + Codec = textStream.CodecShortName, + Type = MediaStreamType.Subtitle, + Index = streams.Count + }); + } + + /// + /// Adds the subtitle stream. + /// + /// The streams. + /// The text stream. + private void AddSubtitleStream(List streams, TSGraphicsStream textStream) + { + streams.Add(new MediaStream + { + Language = textStream.LanguageCode, + Codec = textStream.CodecShortName, + Type = MediaStreamType.Subtitle, + Index = streams.Count + }); + } + } +} diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index cfd37904e3..41e90a38fb 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -179,6 +179,7 @@ MultiItemUpdateNotification.xaml + LibraryExplorer.xaml @@ -221,6 +222,10 @@ + + {07b509c0-0c28-4f3f-8963-5263281f7e3d} + BDInfo + {9142eefa-7570-41e1-bfcc-468bb571af2f} MediaBrowser.Common diff --git a/MediaBrowser.UI.sln b/MediaBrowser.UI.sln index 0bb86a09f5..06d1c5f8bb 100644 --- a/MediaBrowser.UI.sln +++ b/MediaBrowser.UI.sln @@ -19,8 +19,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Plugins.Tmt5", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.UI.Uninstall", "MediaBrowser.UI.Uninstall\MediaBrowser.UI.Uninstall.csproj", "{E4BE0659-4084-407B-B8A8-67802331CC9E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BDInfo", "BDInfo\BDInfo.csproj", "{07B509C0-0C28-4F3F-8963-5263281F7E3D}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.IsoMounter", "MediaBrowser.IsoMounter\MediaBrowser.IsoMounter.csproj", "{5356AE30-6A6E-4A64-81E3-F76C50595E64}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.UI.Controls", "MediaBrowser.UI.Controls\MediaBrowser.UI.Controls.csproj", "{1ADFE460-FD95-46FA-8871-CCCB4B62E2E8}" @@ -137,16 +135,6 @@ Global {E4BE0659-4084-407B-B8A8-67802331CC9E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {E4BE0659-4084-407B-B8A8-67802331CC9E}.Release|Mixed Platforms.Build.0 = Release|Any CPU {E4BE0659-4084-407B-B8A8-67802331CC9E}.Release|x86.ActiveCfg = Release|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Debug|x86.ActiveCfg = Debug|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Release|Any CPU.Build.0 = Release|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {07B509C0-0C28-4F3F-8963-5263281F7E3D}.Release|x86.ActiveCfg = Release|Any CPU {5356AE30-6A6E-4A64-81E3-F76C50595E64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5356AE30-6A6E-4A64-81E3-F76C50595E64}.Debug|Any CPU.Build.0 = Debug|Any CPU {5356AE30-6A6E-4A64-81E3-F76C50595E64}.Debug|Mixed Platforms.ActiveCfg = Debug|x86