diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 5b5b0a9024..3c32232ac8 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -123,7 +123,7 @@ namespace MediaBrowser.Api } [Route("/Shows/{Id}/Episodes", "GET", Summary = "Gets episodes for a tv season")] - public class GetEpisodes : IReturn, IHasItemFields + public class GetEpisodes : IReturn, IHasItemFields, IHasDtoOptions { /// /// Gets or sets the user id. @@ -173,10 +173,19 @@ namespace MediaBrowser.Api /// The limit. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int? Limit { get; set; } + + [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] + public bool? EnableImages { get; set; } + + [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? ImageTypeLimit { get; set; } + + [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string EnableImageTypes { get; set; } } [Route("/Shows/{Id}/Seasons", "GET", Summary = "Gets seasons for a tv series")] - public class GetSeasons : IReturn, IHasItemFields + public class GetSeasons : IReturn, IHasItemFields, IHasDtoOptions { /// /// Gets or sets the user id. @@ -206,6 +215,15 @@ namespace MediaBrowser.Api [ApiMember(Name = "AdjacentTo", Description = "Optional. Return items that are siblings of a supplied item.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string AdjacentTo { get; set; } + + [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] + public bool? EnableImages { get; set; } + + [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? ImageTypeLimit { get; set; } + + [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string EnableImageTypes { get; set; } } /// diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 76ef054de0..d2feb41169 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -51,6 +51,8 @@ namespace MediaBrowser.Controller.MediaEncoding /// Task{Stream}. Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken); + Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, int? imageStreamIndex, CancellationToken cancellationToken); + /// /// Extracts the video images on interval. /// diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 97567db0e4..01fb31d0c5 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -484,12 +484,16 @@ namespace MediaBrowser.MediaEncoding.Encoder return ExtractImage(new[] { path }, imageStreamIndex, MediaProtocol.File, true, null, null, cancellationToken); } - public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, - TimeSpan? offset, CancellationToken cancellationToken) + public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { return ExtractImage(inputFiles, null, protocol, false, threedFormat, offset, cancellationToken); } + public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, int? imageStreamIndex, CancellationToken cancellationToken) + { + return ExtractImage(inputFiles, imageStreamIndex, protocol, false, null, null, cancellationToken); + } + private async Task ExtractImage(string[] inputFiles, int? imageStreamIndex, MediaProtocol protocol, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 743351406e..6ec9e64359 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -138,10 +138,14 @@ namespace MediaBrowser.MediaEncoding.Probing var parts = iTunEXTC.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); // Example // mpaa|G|100|For crude humor - if (parts.Length == 4) + if (parts.Length > 1) { info.OfficialRating = parts[1]; - info.OfficialRatingDescription = parts[3]; + + if (parts.Length > 3) + { + info.OfficialRatingDescription = parts[3]; + } } } diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 6bb2a9f827..09d762aaef 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -520,7 +520,7 @@ namespace MediaBrowser.Model.Dlna { if (StringHelper.EqualsIgnoreCase(targetAudioCodec, "ac3")) { - defaultBitrate = 384000; + defaultBitrate = 448000; } else { @@ -840,13 +840,25 @@ namespace MediaBrowser.Model.Dlna private bool IsAudioEligibleForDirectPlay(MediaSourceInfo item, int? maxBitrate) { - if (!maxBitrate.HasValue || (item.Bitrate.HasValue && item.Bitrate.Value <= maxBitrate.Value)) + if (!maxBitrate.HasValue) { - return true; + _logger.Info("Cannot direct play due to unknown supported bitrate"); + return false; } - _logger.Info("Bitrate exceeds DirectPlay limit"); - return false; + if (!item.Bitrate.HasValue) + { + _logger.Info("Cannot direct play due to unknown content bitrate"); + return false; + } + + if (item.Bitrate.Value > maxBitrate.Value) + { + _logger.Info("Bitrate exceeds DirectPlay limit"); + return false; + } + + return true; } private void ValidateInput(VideoOptions options) diff --git a/MediaBrowser.Providers/Manager/ProviderUtils.cs b/MediaBrowser.Providers/Manager/ProviderUtils.cs index 20b2ac6cd2..278d8ed710 100644 --- a/MediaBrowser.Providers/Manager/ProviderUtils.cs +++ b/MediaBrowser.Providers/Manager/ProviderUtils.cs @@ -10,9 +10,9 @@ namespace MediaBrowser.Providers.Manager public static class ProviderUtils { public static void MergeBaseItemData(MetadataResult sourceResult, - MetadataResult targetResult, - List lockedFields, - bool replaceData, + MetadataResult targetResult, + List lockedFields, + bool replaceData, bool mergeMetadataSettings) where T : BaseItem { @@ -89,7 +89,7 @@ namespace MediaBrowser.Providers.Manager { target.CustomRating = source.CustomRating; } - + if (!lockedFields.Contains(MetadataFields.Overview)) { if (replaceData || string.IsNullOrEmpty(target.Overview)) @@ -107,7 +107,7 @@ namespace MediaBrowser.Providers.Manager { if (replaceData || targetResult.People == null || targetResult.People.Count == 0) { - targetResult.People = sourceResult.People ?? new List(); + targetResult.People = sourceResult.People; } } @@ -238,7 +238,7 @@ namespace MediaBrowser.Providers.Manager targetHasDisplayOrder.DisplayOrder = sourceHasDisplayOrder.DisplayOrder; } } - + private static void MergeShortOverview(BaseItem source, BaseItem target, List lockedFields, bool replaceData) { var sourceHasShortOverview = source as IHasShortOverview; diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index aa495afbcf..4b795a474a 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -78,7 +78,8 @@ namespace MediaBrowser.Providers.MediaInfo _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("front", StringComparison.OrdinalIgnoreCase) != -1) ?? - imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1); + imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1) ?? + imageStreams.FirstOrDefault(); var imageStreamIndex = imageStream == null ? (int?)null : imageStream.Index; diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index a5751da0aa..ff6eef167a 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -10,6 +10,8 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; @@ -93,20 +95,59 @@ namespace MediaBrowser.Providers.MediaInfo try { - // If we know the duration, grab it from 10% into the video. Otherwise just 10 seconds in. - // Always use 10 seconds for dvd because our duration could be out of whack - var imageOffset = item.VideoType != VideoType.Dvd && item.RunTimeTicks.HasValue && - item.RunTimeTicks.Value > 0 - ? TimeSpan.FromTicks(Convert.ToInt64(item.RunTimeTicks.Value * .1)) - : TimeSpan.FromSeconds(10); - var protocol = item.LocationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File; var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, item.Path, protocol, isoMount, item.PlayableStreamFileNames); - var stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); + var mediaStreams = + item.GetMediaSources(false) + .Take(1) + .SelectMany(i => i.MediaStreams) + .ToList(); + + var imageStreams = + mediaStreams + .Where(i => i.Type == MediaStreamType.EmbeddedImage) + .ToList(); + + var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("front", StringComparison.OrdinalIgnoreCase) != -1) ?? + imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1) ?? + imageStreams.FirstOrDefault(); + + Stream stream; + + if (imageStream != null) + { + // Instead of using the raw stream index, we need to use nth video/embedded image stream + var videoIndex = -1; + foreach (var mediaStream in mediaStreams) + { + if (mediaStream.Type == MediaStreamType.Video || + mediaStream.Type == MediaStreamType.EmbeddedImage) + { + videoIndex++; + } + if (mediaStream == imageStream) + { + break; + } + } + + stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, videoIndex, cancellationToken).ConfigureAwait(false); + } + else + { + // If we know the duration, grab it from 10% into the video. Otherwise just 10 seconds in. + // Always use 10 seconds for dvd because our duration could be out of whack + var imageOffset = item.VideoType != VideoType.Dvd && item.RunTimeTicks.HasValue && + item.RunTimeTicks.Value > 0 + ? TimeSpan.FromTicks(Convert.ToInt64(item.RunTimeTicks.Value * .1)) + : TimeSpan.FromSeconds(10); + + stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); + } return new DynamicImageResponse { diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs index c7a5e3b184..71019e0ade 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Entities.TV; namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications { @@ -393,6 +394,18 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications public static string GetItemName(BaseItem item) { var name = item.Name; + var episode = item as Episode; + if (episode != null) + { + if (episode.IndexNumber.HasValue) + { + name = string.Format("Ep{0} - {1}", episode.IndexNumber.Value.ToString(CultureInfo.InvariantCulture), name); + } + if (episode.ParentIndexNumber.HasValue) + { + name = string.Format("S{0}, {1}", episode.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture), name); + } + } var hasSeries = item as IHasSeries; diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index cb74d4dd77..75b5498c56 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -85,8 +85,6 @@ namespace MediaBrowser.XbmcMetadata.Parsers /// The cancellation token. private void Fetch(MetadataResult item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken) { - item.ResetPeople(); - if (!SupportsUrlAfterClosingXmlTag) { using (var streamReader = BaseNfoSaver.GetStreamReader(metadataFile)) @@ -94,6 +92,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers // Use XmlReader for best performance using (var reader = XmlReader.Create(streamReader, settings)) { + item.ResetPeople(); + reader.MoveToContent(); // Loop through each element @@ -113,6 +113,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers using (var streamReader = BaseNfoSaver.GetStreamReader(metadataFile)) { + item.ResetPeople(); + // Need to handle a url after the xml data // http://kodi.wiki/view/NFO_files/movies