From acd2defbf7161077c430518cb41782f5771f3282 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 22 May 2016 18:37:50 -0400 Subject: handle flat tv folders --- .../Library/Resolvers/TV/EpisodeResolver.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/TV') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index e620498210..14e5e446b3 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -1,6 +1,9 @@ -using MediaBrowser.Controller.Entities.TV; +using System; +using System.IO; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using System.Linq; +using MediaBrowser.Model.Entities; namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { @@ -37,7 +40,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV } // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something - if (season != null || args.HasParent()) + // Also handle flat tv folders + if (season != null || args.HasParent() || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { var episode = ResolveVideo(args, false); -- cgit v1.2.3 From 2772d595596b3e682dbce890e53bdc3ef027df46 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Jul 2016 01:40:18 -0400 Subject: denormalize seasonid --- MediaBrowser.Api/StartupWizardService.cs | 2 +- MediaBrowser.Controller/Entities/TV/Episode.cs | 23 +-- MediaBrowser.Model/Dto/BaseItemDto.cs | 10 + .../TV/MissingEpisodeProvider.cs | 3 +- .../Dto/DtoService.cs | 220 +++++++++------------ .../Library/LibraryManager.cs | 8 +- .../Library/Resolvers/TV/EpisodeResolver.cs | 8 + .../LiveTv/LiveTvManager.cs | 2 - .../Persistence/SqliteItemRepository.cs | 15 +- .../UserViews/CollectionFolderImageProvider.cs | 5 - .../UserViews/DynamicImageProvider.cs | 5 - 11 files changed, 135 insertions(+), 166 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/TV') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 7cdc3b6a2e..8f4a62ced4 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -117,7 +117,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; //config.EnableFolderView = true; - config.SchemaVersion = 99; + config.SchemaVersion = 100; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index d7526a535f..4ff1813fff 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -13,7 +13,6 @@ namespace MediaBrowser.Controller.Entities.TV /// public class Episode : Video, IHasTrailers, IHasLookupInfo, IHasSeries { - public Episode() { RemoteTrailers = new List(); @@ -181,6 +180,12 @@ namespace MediaBrowser.Controller.Entities.TV { var series = Series; return series == null ? SeriesName : series.Name; + } + + public Guid? FindSeasonId() + { + var season = Season; + return season == null ? (Guid?)null : season.Id; } /// @@ -243,21 +248,7 @@ namespace MediaBrowser.Controller.Entities.TV } [IgnoreDataMember] - public Guid? SeasonId - { - get - { - // First see if the parent is a Season - var season = Season; - - if (season != null) - { - return season.Id; - } - - return null; - } - } + public Guid? SeasonId { get; set; } public override IEnumerable GetAncestorIds() { diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 146fcc74e8..ac7d97288c 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -954,6 +954,16 @@ namespace MediaBrowser.Model.Dto get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Thumb); } } + /// + /// Gets a value indicating whether this instance has thumb. + /// + /// true if this instance has thumb; otherwise, false. + [IgnoreDataMember] + public bool HasBackdrop + { + get { return (BackdropImageTags != null && BackdropImageTags.Count > 0) || (ParentBackdropImageTags != null && ParentBackdropImageTags.Count > 0); } + } + /// /// Gets a value indicating whether this instance has primary image. /// diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index 4e2d9a8d2d..e8a0057fee 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -429,7 +429,8 @@ namespace MediaBrowser.Providers.TV IndexNumber = episodeNumber, ParentIndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)), - IsVirtualItem = true + IsVirtualItem = true, + SeasonId = season == null ? (Guid?)null : season.Id }; episode.SetParent(season); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 67ae24f3e3..257448941a 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -663,19 +663,12 @@ namespace MediaBrowser.Server.Implementations.Dto dto.GameSystem = item.GameSystemName; } - private List GetBackdropImageTags(BaseItem item, int limit) + private List GetImageTags(BaseItem item, List images) { - return GetCacheTags(item, ImageType.Backdrop, limit).ToList(); - } - - private List GetScreenshotImageTags(BaseItem item, int limit) - { - var hasScreenshots = item as IHasScreenshots; - if (hasScreenshots == null) - { - return new List(); - } - return GetCacheTags(item, ImageType.Screenshot, limit).ToList(); + return images + .Select(p => GetImageCacheTag(item, p)) + .Where(i => i != null) + .ToList(); } private IEnumerable GetCacheTags(BaseItem item, ImageType type, int limit) @@ -850,53 +843,6 @@ namespace MediaBrowser.Server.Implementations.Dto } } - /// - /// If an item does not any backdrops, this can be used to find the first parent that does have one - /// - /// The item. - /// The owner. - /// BaseItem. - private BaseItem GetParentBackdropItem(BaseItem item, BaseItem owner) - { - var parent = item.GetParent() ?? owner; - - while (parent != null) - { - if (parent.GetImages(ImageType.Backdrop).Any()) - { - return parent; - } - - parent = parent.GetParent(); - } - - return null; - } - - /// - /// If an item does not have a logo, this can be used to find the first parent that does have one - /// - /// The item. - /// The type. - /// The owner. - /// BaseItem. - private BaseItem GetParentImageItem(BaseItem item, ImageType type, BaseItem owner) - { - var parent = item.GetParent() ?? owner; - - while (parent != null) - { - if (parent.HasImage(type)) - { - return parent; - } - - parent = parent.GetParent(); - } - - return null; - } - /// /// Gets the chapter info dto. /// @@ -1027,7 +973,7 @@ namespace MediaBrowser.Server.Implementations.Dto var backdropLimit = options.GetImageLimit(ImageType.Backdrop); if (backdropLimit > 0) { - dto.BackdropImageTags = GetBackdropImageTags(item, backdropLimit); + dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList()); } if (fields.Contains(ItemFields.ScreenshotImageTags)) @@ -1035,7 +981,7 @@ namespace MediaBrowser.Server.Implementations.Dto var screenshotLimit = options.GetImageLimit(ImageType.Screenshot); if (screenshotLimit > 0) { - dto.ScreenshotImageTags = GetScreenshotImageTags(item, screenshotLimit); + dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Screenshot).Take(screenshotLimit).ToList()); } } @@ -1064,6 +1010,7 @@ namespace MediaBrowser.Server.Implementations.Dto dto.Id = GetDtoId(item); dto.IndexNumber = item.IndexNumber; + dto.ParentIndexNumber = item.ParentIndexNumber; dto.IsFolder = item.IsFolder; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; @@ -1126,18 +1073,6 @@ namespace MediaBrowser.Server.Implementations.Dto dto.ShortOverview = item.ShortOverview; } - // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance - if (backdropLimit > 0 && dto.BackdropImageTags.Count == 0) - { - var parentWithBackdrop = GetParentBackdropItem(item, owner); - - if (parentWithBackdrop != null) - { - dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop); - dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop, backdropLimit); - } - } - if (fields.Contains(ItemFields.ParentId)) { var displayParentId = item.DisplayParentId; @@ -1147,46 +1082,7 @@ namespace MediaBrowser.Server.Implementations.Dto } } - dto.ParentIndexNumber = item.ParentIndexNumber; - - // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance - if (!dto.HasLogo && options.GetImageLimit(ImageType.Logo) > 0) - { - var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner); - - if (parentWithLogo != null) - { - dto.ParentLogoItemId = GetDtoId(parentWithLogo); - - dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo); - } - } - - // If there is no art, indicate what parent has one in case the Ui wants to allow inheritance - if (!dto.HasArtImage && options.GetImageLimit(ImageType.Art) > 0) - { - var parentWithImage = GetParentImageItem(item, ImageType.Art, owner); - - if (parentWithImage != null) - { - dto.ParentArtItemId = GetDtoId(parentWithImage); - - dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art); - } - } - - // If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance - if (!dto.HasThumb && options.GetImageLimit(ImageType.Thumb) > 0) - { - var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner); - - if (parentWithImage != null) - { - dto.ParentThumbItemId = GetDtoId(parentWithImage); - - dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb); - } - } + AddInheritedImages(dto, item, options, owner); if (fields.Contains(ItemFields.Path)) { @@ -1420,33 +1316,36 @@ namespace MediaBrowser.Server.Implementations.Dto dto.SeasonName = episode.SeasonName; - var episodeSeries = episode.Series; + Series episodeSeries = null; - if (episodeSeries != null) + if (fields.Contains(ItemFields.SeriesGenres)) { - if (fields.Contains(ItemFields.SeriesGenres)) + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) { dto.SeriesGenres = episodeSeries.Genres.ToList(); } + } + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) + { dto.SeriesId = GetDtoId(episodeSeries); + } - if (fields.Contains(ItemFields.AirTime)) - { - dto.AirTime = episodeSeries.AirTime; - } - - if (options.GetImageLimit(ImageType.Thumb) > 0) - { - dto.SeriesThumbImageTag = GetImageCacheTag(episodeSeries, ImageType.Thumb); - } - - if (options.GetImageLimit(ImageType.Primary) > 0) + if (options.GetImageLimit(ImageType.Primary) > 0) + { + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary); } + } - if (fields.Contains(ItemFields.SeriesStudio)) + if (fields.Contains(ItemFields.SeriesStudio)) + { + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) { dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault(); } @@ -1475,7 +1374,6 @@ namespace MediaBrowser.Server.Implementations.Dto if (series != null) { dto.SeriesId = GetDtoId(series); - dto.AirTime = series.AirTime; if (fields.Contains(ItemFields.SeriesStudio)) { @@ -1533,6 +1431,70 @@ namespace MediaBrowser.Server.Implementations.Dto } } + private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner) + { + var logoLimit = options.GetImageLimit(ImageType.Logo); + var artLimit = options.GetImageLimit(ImageType.Art); + var thumbLimit = options.GetImageLimit(ImageType.Thumb); + var backdropLimit = options.GetImageLimit(ImageType.Backdrop); + + if (logoLimit == 0 && artLimit == 0 && thumbLimit == 0 && backdropLimit == 0) + { + return; + } + + BaseItem parent = null; + var isFirst = true; + + while (((!dto.HasLogo && logoLimit > 0) || (!dto.HasArtImage && artLimit > 0) || (!dto.HasThumb && thumbLimit > 0) || parent is Series) && + (parent = parent ?? (isFirst ? item.GetParent() ?? owner : parent)) != null) + { + if (logoLimit > 0 && !dto.HasLogo && dto.ParentLogoItemId == null) + { + var image = parent.GetImageInfo(ImageType.Logo, 0); + + if (image != null) + { + dto.ParentLogoItemId = GetDtoId(parent); + dto.ParentLogoImageTag = GetImageCacheTag(parent, image); + } + } + if (artLimit > 0 && !dto.HasArtImage && dto.ParentArtItemId == null) + { + var image = parent.GetImageInfo(ImageType.Art, 0); + + if (image != null) + { + dto.ParentArtItemId = GetDtoId(parent); + dto.ParentArtImageTag = GetImageCacheTag(parent, image); + } + } + if (thumbLimit > 0 && !dto.HasThumb && (dto.ParentThumbItemId == null || parent is Series)) + { + var image = parent.GetImageInfo(ImageType.Thumb, 0); + + if (image != null) + { + dto.ParentThumbItemId = GetDtoId(parent); + dto.ParentThumbImageTag = GetImageCacheTag(parent, image); + } + } + if (backdropLimit > 0 && !dto.HasBackdrop) + { + var images = parent.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList(); + + if (images.Count > 0) + { + dto.ParentBackdropItemId = GetDtoId(parent); + dto.ParentBackdropImageTags = GetImageTags(parent, images); + } + } + + isFirst = false; + parent = parent.GetParent(); + } + } + private string GetMappedPath(IHasMetadata item) { var path = item.Path; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 9d66455e77..7458e7541d 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -368,10 +368,10 @@ namespace MediaBrowser.Server.Implementations.Library { return; } - //if (!(item is Folder)) - //{ - // return; - //} + if (!(item is Folder)) + { + return; + } LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; }); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index 14e5e446b3..e279a978e0 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -45,6 +45,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { var episode = ResolveVideo(args, false); + if (episode != null) + { + if (season != null) + { + episode.SeasonId = season.Id; + } + } + return episode; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index f32a4b59e3..64af35a9aa 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1214,8 +1214,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv var item = await GetChannel(channelInfo.Item2, channelInfo.Item1, parentFolderId, cancellationToken).ConfigureAwait(false); list.Add(item); - - _libraryManager.RegisterItem(item); } catch (OperationCanceledException) { diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 0416474395..e239c3b83e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 99; + public const int LatestSchemaVersion = 100; /// /// Initializes a new instance of the class. @@ -272,6 +272,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -405,7 +406,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "CriticRatingSummary", "IsVirtualItem", "SeriesName", - "SeasonName" + "SeasonName", + "SeasonId" }; private readonly string[] _mediaStreamSaveColumns = @@ -526,7 +528,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsVirtualItem", "SeriesName", "UserDataKey", - "SeasonName" + "SeasonName", + "SeasonId" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -961,10 +964,12 @@ namespace MediaBrowser.Server.Implementations.Persistence if (episode != null) { _saveItemCommand.GetParameter(index++).Value = episode.FindSeasonName(); + _saveItemCommand.GetParameter(index++).Value = episode.FindSeasonId(); } else { _saveItemCommand.GetParameter(index++).Value = null; + _saveItemCommand.GetParameter(index++).Value = null; } _saveItemCommand.Transaction = transaction; @@ -1405,6 +1410,10 @@ namespace MediaBrowser.Server.Implementations.Persistence { episode.SeasonName = reader.GetString(60); } + if (!reader.IsDBNull(61)) + { + episode.SeasonId = reader.GetGuid(61); + } } return item; diff --git a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs index a66884f89d..29716d33e4 100644 --- a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs @@ -54,11 +54,6 @@ namespace MediaBrowser.Server.Implementations.UserViews { return series; } - var episodeSeason = episode.Season; - if (episodeSeason != null) - { - return episodeSeason; - } return episode; } diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 161f771a91..ea4da19b20 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -86,11 +86,6 @@ namespace MediaBrowser.Server.Implementations.UserViews { return series; } - var episodeSeason = episode.Season; - if (episodeSeason != null) - { - return episodeSeason; - } return episode; } -- cgit v1.2.3 From 1fcbd3c6da5bd061473a3f34a6410c9bbce0fc13 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Jul 2016 02:01:31 -0400 Subject: denormalize seriesid --- MediaBrowser.Api/StartupWizardService.cs | 2 +- MediaBrowser.Controller/Entities/Book.cs | 9 +++++- MediaBrowser.Controller/Entities/IHasSeries.cs | 5 +++- MediaBrowser.Controller/Entities/TV/Episode.cs | 9 +++++- MediaBrowser.Controller/Entities/TV/Season.cs | 8 +++++ MediaBrowser.Model/Querying/ItemFields.cs | 2 ++ .../TV/MissingEpisodeProvider.cs | 3 +- .../Dto/DtoService.cs | 35 ++++++++++++++-------- .../Library/Resolvers/TV/EpisodeResolver.cs | 29 +++++++++++------- .../Persistence/SqliteItemRepository.cs | 26 ++++++++++++++-- 10 files changed, 97 insertions(+), 31 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/TV') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 8f4a62ced4..a59cc6909b 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -117,7 +117,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; //config.EnableFolderView = true; - config.SchemaVersion = 100; + config.SchemaVersion = 101; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 76f54edea9..34368d61f1 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Providers; +using System; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using System.Linq; using System.Runtime.Serialization; @@ -19,12 +20,18 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string SeriesName { get; set; } + public Guid? SeriesId { get; set; } public string FindSeriesName() { return SeriesName; } + public Guid? FindSeriesId() + { + return SeriesId; + } + public override bool CanDownload() { var locationType = LocationType; diff --git a/MediaBrowser.Controller/Entities/IHasSeries.cs b/MediaBrowser.Controller/Entities/IHasSeries.cs index 1a262ed283..d4dbb8ef67 100644 --- a/MediaBrowser.Controller/Entities/IHasSeries.cs +++ b/MediaBrowser.Controller/Entities/IHasSeries.cs @@ -1,4 +1,6 @@  +using System; + namespace MediaBrowser.Controller.Entities { public interface IHasSeries @@ -8,7 +10,8 @@ namespace MediaBrowser.Controller.Entities /// /// The name of the series. string SeriesName { get; set; } - string FindSeriesName(); + Guid? SeriesId { get; set; } + Guid? FindSeriesId(); } } diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 4ff1813fff..b13c291d11 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -248,7 +248,14 @@ namespace MediaBrowser.Controller.Entities.TV } [IgnoreDataMember] - public Guid? SeasonId { get; set; } + public Guid? SeasonId { get; set; } + public Guid? SeriesId { get; set; } + + public Guid? FindSeriesId() + { + var series = Series; + return series == null ? (Guid?)null : series.Id; + } public override IEnumerable GetAncestorIds() { diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index a689ca5508..218d0fef83 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -237,12 +237,20 @@ namespace MediaBrowser.Controller.Entities.TV [IgnoreDataMember] public string SeriesName { get; set; } + public Guid? SeriesId { get; set; } + public string FindSeriesName() { var series = Series; return series == null ? SeriesName : series.Name; } + public Guid? FindSeriesId() + { + var series = Series; + return series == null ? (Guid?)null : series.Id; + } + /// /// Gets the lookup information. /// diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index cea638a395..21f87247ab 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -197,6 +197,8 @@ /// SeriesGenres, + SeriesPrimaryImage, + /// /// The series studio /// diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index e8a0057fee..22e1267952 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -430,7 +430,8 @@ namespace MediaBrowser.Providers.TV ParentIndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)), IsVirtualItem = true, - SeasonId = season == null ? (Guid?)null : season.Id + SeasonId = season == null ? (Guid?)null : season.Id, + SeriesId = series.Id }; episode.SetParent(season); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 257448941a..925afa4286 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1316,6 +1316,12 @@ namespace MediaBrowser.Server.Implementations.Dto dto.SeasonName = episode.SeasonName; + var seriesId = episode.SeriesId; + if (seriesId.HasValue) + { + dto.SeriesId = seriesId.Value.ToString("N"); + } + Series episodeSeries = null; if (fields.Contains(ItemFields.SeriesGenres)) @@ -1327,13 +1333,7 @@ namespace MediaBrowser.Server.Implementations.Dto } } - episodeSeries = episodeSeries ?? episode.Series; - if (episodeSeries != null) - { - dto.SeriesId = GetDtoId(episodeSeries); - } - - if (options.GetImageLimit(ImageType.Primary) > 0) + if (fields.Contains(ItemFields.SeriesPrimaryImage)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) @@ -1369,18 +1369,27 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.SeriesName = season.SeriesName; - series = season.Series; - - if (series != null) + var seriesId = season.SeriesId; + if (seriesId.HasValue) { - dto.SeriesId = GetDtoId(series); + dto.SeriesId = seriesId.Value.ToString("N"); + } + + series = null; - if (fields.Contains(ItemFields.SeriesStudio)) + if (fields.Contains(ItemFields.SeriesStudio)) + { + series = series ?? season.Series; + if (series != null) { dto.SeriesStudio = series.Studios.FirstOrDefault(); } + } - if (options.GetImageLimit(ImageType.Primary) > 0) + if (fields.Contains(ItemFields.SeriesPrimaryImage)) + { + series = series ?? season.Series; + if (series != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index e279a978e0..6d0f4ffe29 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -30,23 +30,32 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } - var season = parent as Season; - - // Just in case the user decided to nest episodes. - // Not officially supported but in some cases we can handle it. - if (season == null) - { - season = parent.GetParents().OfType().FirstOrDefault(); - } - // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something // Also handle flat tv folders - if (season != null || args.HasParent() || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { var episode = ResolveVideo(args, false); if (episode != null) { + var season = parent as Season; + // Just in case the user decided to nest episodes. + // Not officially supported but in some cases we can handle it. + if (season == null) + { + season = parent.GetParents().OfType().FirstOrDefault(); + } + + var series = parent as Series; + if (series == null) + { + series = parent.GetParents().OfType().FirstOrDefault(); + } + + if (series != null) + { + episode.SeriesId = series.Id; + } if (season != null) { episode.SeasonId = season.Id; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e239c3b83e..4a70ddc2ef 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 100; + public const int LatestSchemaVersion = 101; /// /// Initializes a new instance of the class. @@ -273,6 +273,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); + _connection.AddColumn(Logger, "TypedBaseItems", "SeriesId", "GUID"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -407,7 +408,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsVirtualItem", "SeriesName", "SeasonName", - "SeasonId" + "SeasonId", + "SeriesId" }; private readonly string[] _mediaStreamSaveColumns = @@ -529,7 +531,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "SeriesName", "UserDataKey", "SeasonName", - "SeasonId" + "SeasonId", + "SeriesId" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -972,6 +975,15 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = null; } + if (hasSeries != null) + { + _saveItemCommand.GetParameter(index++).Value = hasSeries.FindSeriesId(); + } + else + { + _saveItemCommand.GetParameter(index++).Value = null; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1416,6 +1428,14 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + if (hasSeries != null) + { + if (!reader.IsDBNull(62)) + { + hasSeries.SeriesId = reader.GetGuid(62); + } + } + return item; } -- cgit v1.2.3 From 959c6a397cf9bb7c5494e8bb04d9b8f7dff40383 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 9 Jul 2016 13:39:04 -0400 Subject: add new streambuilder options --- MediaBrowser.Model/Dlna/AudioOptions.cs | 6 + MediaBrowser.Model/Dlna/CodecProfile.cs | 3 + MediaBrowser.Model/Dlna/StreamBuilder.cs | 158 +++++++++++++++++---- MediaBrowser.Providers/TV/DummySeasonProvider.cs | 3 +- .../Library/LibraryManager.cs | 43 +++--- .../Library/Resolvers/TV/EpisodeResolver.cs | 20 +-- .../Library/Resolvers/TV/SeasonResolver.cs | 6 +- 7 files changed, 186 insertions(+), 53 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/TV') diff --git a/MediaBrowser.Model/Dlna/AudioOptions.cs b/MediaBrowser.Model/Dlna/AudioOptions.cs index 6ad4fa2659..162b88c981 100644 --- a/MediaBrowser.Model/Dlna/AudioOptions.cs +++ b/MediaBrowser.Model/Dlna/AudioOptions.cs @@ -11,8 +11,14 @@ namespace MediaBrowser.Model.Dlna public AudioOptions() { Context = EncodingContext.Streaming; + + EnableDirectPlay = true; + EnableDirectStream = true; } + public bool EnableDirectPlay { get; set; } + public bool EnableDirectStream { get; set; } + public string ItemId { get; set; } public List MediaSources { get; set; } public DeviceProfile Profile { get; set; } diff --git a/MediaBrowser.Model/Dlna/CodecProfile.cs b/MediaBrowser.Model/Dlna/CodecProfile.cs index 7200f648cd..385e98f619 100644 --- a/MediaBrowser.Model/Dlna/CodecProfile.cs +++ b/MediaBrowser.Model/Dlna/CodecProfile.cs @@ -11,6 +11,8 @@ namespace MediaBrowser.Model.Dlna public ProfileCondition[] Conditions { get; set; } + public ProfileCondition[] ApplyConditions { get; set; } + [XmlAttribute("codec")] public string Codec { get; set; } @@ -20,6 +22,7 @@ namespace MediaBrowser.Model.Dlna public CodecProfile() { Conditions = new ProfileCondition[] {}; + ApplyConditions = new ProfileCondition[] { }; } public List GetCodecs() diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 41efa51b98..e07e56d397 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -131,6 +131,11 @@ namespace MediaBrowser.Model.Dlna List directPlayMethods = GetAudioDirectPlayMethods(item, audioStream, options); + ConditionProcessor conditionProcessor = new ConditionProcessor(); + + int? inputAudioChannels = audioStream == null ? null : audioStream.Channels; + int? inputAudioBitrate = audioStream == null ? null : audioStream.BitDepth; + if (directPlayMethods.Count > 0) { string audioCodec = audioStream == null ? null : audioStream.Codec; @@ -138,27 +143,36 @@ namespace MediaBrowser.Model.Dlna // Make sure audio codec profiles are satisfied if (!string.IsNullOrEmpty(audioCodec)) { - ConditionProcessor conditionProcessor = new ConditionProcessor(); - List conditions = new List(); foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Audio && i.ContainsCodec(audioCodec, item.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsAudioConditionSatisfied(applyCondition, inputAudioChannels, inputAudioBitrate)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } - int? audioChannels = audioStream.Channels; - int? audioBitrate = audioStream.BitRate; - bool all = true; foreach (ProfileCondition c in conditions) { - if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)) + if (!conditionProcessor.IsAudioConditionSatisfied(c, inputAudioChannels, inputAudioBitrate)) { LogConditionFailure(options.Profile, "AudioCodecProfile", c, item); all = false; @@ -241,9 +255,23 @@ namespace MediaBrowser.Model.Dlna List audioTranscodingConditions = new List(); foreach (CodecProfile i in audioCodecProfiles) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - audioTranscodingConditions.Add(c); + if (!conditionProcessor.IsAudioConditionSatisfied(applyCondition, inputAudioChannels, inputAudioBitrate)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + audioTranscodingConditions.Add(c); + } } } @@ -294,7 +322,7 @@ namespace MediaBrowser.Model.Dlna if (directPlayProfile != null) { // While options takes the network and other factors into account. Only applies to direct stream - if (item.SupportsDirectStream && IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate())) + if (item.SupportsDirectStream && IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate()) && options.EnableDirectStream) { playMethods.Add(PlayMethod.DirectStream); } @@ -302,7 +330,7 @@ namespace MediaBrowser.Model.Dlna // The profile describes what the device supports // If device requirements are satisfied then allow both direct stream and direct play if (item.SupportsDirectPlay && - IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options))) + IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options)) && options.EnableDirectPlay) { playMethods.Add(PlayMethod.DirectPlay); } @@ -385,8 +413,8 @@ namespace MediaBrowser.Model.Dlna MediaStream videoStream = item.VideoStream; // TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough - bool isEligibleForDirectPlay = IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay); - bool isEligibleForDirectStream = IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream); + bool isEligibleForDirectPlay = options.EnableDirectPlay && IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay); + bool isEligibleForDirectStream = options.EnableDirectStream && IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream); _logger.Info("Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}", options.Profile.Name ?? "Unknown Profile", @@ -463,17 +491,37 @@ namespace MediaBrowser.Model.Dlna } playlistItem.SubProtocol = transcodingProfile.Protocol; playlistItem.AudioStreamIndex = audioStreamIndex; + ConditionProcessor conditionProcessor = new ConditionProcessor(); List videoTranscodingConditions = new List(); foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(transcodingProfile.VideoCodec, transcodingProfile.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - videoTranscodingConditions.Add(c); + bool? isSecondaryAudio = audioStream == null ? null : item.IsSecondaryAudio(audioStream); + int? inputAudioBitrate = audioStream == null ? null : audioStream.BitRate; + int? audioChannels = audioStream == null ? null : audioStream.Channels; + string audioProfile = audioStream == null ? null : audioStream.Profile; + + if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, inputAudioBitrate, audioProfile, isSecondaryAudio)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + videoTranscodingConditions.Add(c); + } + break; } - break; } } ApplyTranscodingConditions(playlistItem, videoTranscodingConditions); @@ -483,11 +531,42 @@ namespace MediaBrowser.Model.Dlna { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(playlistItem.TargetAudioCodec, transcodingProfile.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - audioTranscodingConditions.Add(c); + int? width = videoStream == null ? null : videoStream.Width; + int? height = videoStream == null ? null : videoStream.Height; + int? bitDepth = videoStream == null ? null : videoStream.BitDepth; + int? videoBitrate = videoStream == null ? null : videoStream.BitRate; + double? videoLevel = videoStream == null ? null : videoStream.Level; + string videoProfile = videoStream == null ? null : videoStream.Profile; + float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate; + bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic; + string videoCodecTag = videoStream == null ? null : videoStream.CodecTag; + + TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : item.Timestamp; + int? packetLength = videoStream == null ? null : videoStream.PacketLength; + int? refFrames = videoStream == null ? null : videoStream.RefFrames; + + int? numAudioStreams = item.GetStreamCount(MediaStreamType.Audio); + int? numVideoStreams = item.GetStreamCount(MediaStreamType.Video); + + if (!conditionProcessor.IsVideoConditionSatisfied(applyCondition, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + { + LogConditionFailure(options.Profile, "VideoCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + audioTranscodingConditions.Add(c); + } + break; } - break; } } ApplyTranscodingConditions(playlistItem, audioTranscodingConditions); @@ -666,9 +745,23 @@ namespace MediaBrowser.Model.Dlna { if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec, container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsVideoConditionSatisfied(applyCondition, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + { + LogConditionFailure(profile, "VideoCodecProfile", applyCondition, mediaSource); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } @@ -697,20 +790,35 @@ namespace MediaBrowser.Model.Dlna } conditions = new List(); + bool? isSecondaryAudio = audioStream == null ? null : mediaSource.IsSecondaryAudio(audioStream); + foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec, container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) + { + LogConditionFailure(profile, "VideoAudioCodecProfile", applyCondition, mediaSource); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } foreach (ProfileCondition i in conditions) { - bool? isSecondaryAudio = audioStream == null ? null : mediaSource.IsSecondaryAudio(audioStream); if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) { LogConditionFailure(profile, "VideoAudioCodecProfile", i, mediaSource); diff --git a/MediaBrowser.Providers/TV/DummySeasonProvider.cs b/MediaBrowser.Providers/TV/DummySeasonProvider.cs index 909760feef..baea0a06d2 100644 --- a/MediaBrowser.Providers/TV/DummySeasonProvider.cs +++ b/MediaBrowser.Providers/TV/DummySeasonProvider.cs @@ -111,7 +111,8 @@ namespace MediaBrowser.Providers.TV Name = seasonName, IndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName), typeof(Season)), - IsVirtualItem = isVirtualItem + IsVirtualItem = isVirtualItem, + SeriesId = series.Id }; season.SetParent(series); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 7458e7541d..a6c5d54292 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -33,6 +33,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Channels; using MediaBrowser.Model.Channels; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Extensions; @@ -353,10 +354,6 @@ namespace MediaBrowser.Server.Implementations.Library private void RegisterItem(Guid id, BaseItem item) { - if (item.SourceType != SourceType.Library) - { - return; - } if (item is IItemByName) { if (!(item is MusicArtist)) @@ -364,14 +361,26 @@ namespace MediaBrowser.Server.Implementations.Library return; } } - if (item is Photo) + + if (item.IsFolder) { - return; + if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel)) + { + if (item.SourceType != SourceType.Library) + { + return; + } + } } - if (!(item is Folder)) + else { return; + if (item is Photo) + { + return; + } } + LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; }); } @@ -782,19 +791,19 @@ namespace MediaBrowser.Server.Implementations.Library public BaseItem FindByPath(string path, bool? isFolder) { + // If this returns multiple items it could be tricky figuring out which one is correct. + // In most cases, the newest one will be and the others obsolete but not yet cleaned up + var query = new InternalItemsQuery { Path = path, - IsFolder = isFolder + IsFolder = isFolder, + SortBy = new[] { ItemSortBy.DateCreated }, + SortOrder = SortOrder.Descending, + Limit = 1 }; - // If this returns multiple items it could be tricky figuring out which one is correct. - // In most cases, the newest one will be and the others obsolete but not yet cleaned up - - return GetItemIds(query) - .Select(GetItemById) - .Where(i => i != null) - .OrderByDescending(i => i.DateCreated) + return GetItemList(query) .FirstOrDefault(); } @@ -1258,6 +1267,8 @@ namespace MediaBrowser.Server.Implementations.Library item = RetrieveItem(id); + //_logger.Debug("GetitemById {0}", id); + if (item != null) { RegisterItem(item); @@ -1508,7 +1519,7 @@ namespace MediaBrowser.Server.Implementations.Library UserId = user.Id.ToString("N") }, CancellationToken.None).Result; - + return channelResult.Items; } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index 6d0f4ffe29..7b8832c594 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -30,22 +30,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } + var season = parent as Season; + // Just in case the user decided to nest episodes. + // Not officially supported but in some cases we can handle it. + if (season == null) + { + season = parent.GetParents().OfType().FirstOrDefault(); + } + // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something // Also handle flat tv folders - if (string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + if (season != null || + string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || + args.HasParent()) { var episode = ResolveVideo(args, false); if (episode != null) { - var season = parent as Season; - // Just in case the user decided to nest episodes. - // Not officially supported but in some cases we can handle it. - if (season == null) - { - season = parent.GetParents().OfType().FirstOrDefault(); - } - var series = parent as Series; if (series == null) { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs index 7d13b11ad1..eeac1345e8 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs @@ -38,10 +38,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV if (args.Parent is Series && args.IsDirectory) { var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions(); - + var series = ((Series)args.Parent); + var season = new Season { - IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber + IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber, + SeriesId = series.Id }; if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0) -- cgit v1.2.3