From 432c52f934ffe6c161ee18d343277f31b75f75a1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 May 2016 17:18:48 -0400 Subject: [PATCH 1/2] update season filters --- MediaBrowser.Api/TvShowsService.cs | 11 ----------- MediaBrowser.Controller/Entities/Folder.cs | 10 ++++------ MediaBrowser.Controller/Entities/TV/Season.cs | 6 ------ MediaBrowser.Controller/Entities/TV/Series.cs | 15 ++++----------- .../Entities/UserViewBuilder.cs | 16 ---------------- 5 files changed, 8 insertions(+), 50 deletions(-) diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index e3dfb7f5a..697e39628 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -415,17 +415,6 @@ namespace MediaBrowser.Api private IEnumerable FilterVirtualSeasons(GetSeasons request, IEnumerable items) { - if (request.IsMissing.HasValue && request.IsVirtualUnaired.HasValue) - { - var isMissing = request.IsMissing.Value; - var isVirtualUnaired = request.IsVirtualUnaired.Value; - - if (!isMissing && !isVirtualUnaired) - { - return items.Where(i => !i.IsMissingOrVirtualUnaired); - } - } - if (request.IsMissing.HasValue) { var val = request.IsMissing.Value; diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index c94c26626..e7b1df55a 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -772,7 +772,7 @@ namespace MediaBrowser.Controller.Entities return true; } } - + var supportsUserDataQueries = ConfigurationManager.Configuration.SchemaVersion >= 76; if (query.SortBy != null && query.SortBy.Length > 0) @@ -1294,7 +1294,7 @@ namespace MediaBrowser.Controller.Entities /// /// Adds the children to list. /// - private void AddChildrenToList(Dictionary result, bool includeLinkedChildren, bool recursive, Func filter) + private void AddChildrenToList(Dictionary result, bool includeLinkedChildren, bool recursive, Func filter) { foreach (var child in Children) { @@ -1525,14 +1525,12 @@ namespace MediaBrowser.Controller.Entities User = user, Recursive = true, IsFolder = false, - IsUnaired = false, EnableTotalRecordCount = false - }; - if (!user.Configuration.DisplayMissingEpisodes) + if (!user.Configuration.DisplayMissingEpisodes || !user.Configuration.DisplayUnairedEpisodes) { - query.IsMissing = false; + query.ExcludeLocationTypes = new[] { LocationType.Virtual }; } var itemsResult = await GetItems(query).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index ab125eecb..10436e0f2 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -152,12 +152,6 @@ namespace MediaBrowser.Controller.Entities.TV get { return LocationType == LocationType.Virtual && IsUnaired; } } - [IgnoreDataMember] - public bool IsMissingOrVirtualUnaired - { - get { return (IsMissingSeason ?? false) || (LocationType == LocationType.Virtual && IsUnaired); } - } - [IgnoreDataMember] public bool IsSpecialSeason { diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index 4a1982edc..a1e7c7e15 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -238,20 +238,13 @@ namespace MediaBrowser.Controller.Entities.TV seasons = LibraryManager.Sort(base.GetChildren(user, true), user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).OfType(); } - if (!includeMissingSeasons && !includeVirtualUnaired) + if (!includeMissingSeasons) { - seasons = seasons.Where(i => !i.IsMissingOrVirtualUnaired); + seasons = seasons.Where(i => !(i.IsMissingSeason ?? false)); } - else + if (!includeVirtualUnaired) { - if (!includeMissingSeasons) - { - seasons = seasons.Where(i => !(i.IsMissingSeason ?? false)); - } - if (!includeVirtualUnaired) - { - seasons = seasons.Where(i => !i.IsVirtualUnaired); - } + seasons = seasons.Where(i => !i.IsVirtualUnaired); } return seasons; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 682eafb37..fbca357cd 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1134,22 +1134,6 @@ namespace MediaBrowser.Controller.Entities bool? isVirtualUnaired, bool? isUnaired) { - if (isMissing.HasValue && isVirtualUnaired.HasValue) - { - if (!isMissing.Value && !isVirtualUnaired.Value) - { - return items.Where(i => - { - var e = i as Season; - if (e != null) - { - return !e.IsMissingOrVirtualUnaired; - } - return true; - }); - } - } - if (isMissing.HasValue) { var val = isMissing.Value; From 329e04780375741d44aba3058a4e35b985903db6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 May 2016 17:32:43 -0400 Subject: [PATCH 2/2] update seasons --- MediaBrowser.Api/TvShowsService.cs | 2 +- MediaBrowser.Controller/Entities/TV/Season.cs | 29 ++++++++++--------- MediaBrowser.Controller/Entities/TV/Series.cs | 2 +- .../Entities/UserViewBuilder.cs | 2 +- .../TV/DummySeasonProvider.cs | 4 +-- .../TV/SeasonMetadataService.cs | 10 +++---- .../Persistence/SqliteItemRepository.cs | 23 +++++++++++++-- 7 files changed, 46 insertions(+), 26 deletions(-) diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 697e39628..c4c603f91 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -418,7 +418,7 @@ namespace MediaBrowser.Api if (request.IsMissing.HasValue) { var val = request.IsMissing.Value; - items = items.Where(i => (i.IsMissingSeason ?? false) == val); + items = items.Where(i => (i.IsMissingSeason) == val); } if (request.IsVirtualUnaired.HasValue) diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index 10436e0f2..53989943b 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -134,7 +134,7 @@ namespace MediaBrowser.Controller.Entities.TV if (!result) { - if (!IsMissingSeason.HasValue) + if (!IsVirtualItem.HasValue) { return true; } @@ -144,12 +144,18 @@ namespace MediaBrowser.Controller.Entities.TV } [IgnoreDataMember] - public bool? IsMissingSeason { get; set; } + public bool? IsVirtualItem { get; set; } + + [IgnoreDataMember] + public bool IsMissingSeason + { + get { return (IsVirtualItem ?? false) && !IsUnaired; } + } [IgnoreDataMember] public bool IsVirtualUnaired { - get { return LocationType == LocationType.Virtual && IsUnaired; } + get { return (IsVirtualItem ?? false) && IsUnaired; } } [IgnoreDataMember] @@ -313,19 +319,14 @@ namespace MediaBrowser.Controller.Entities.TV { var hasChanges = base.BeforeMetadataRefresh(); - var locationType = LocationType; - - if (locationType == LocationType.FileSystem || locationType == LocationType.Offline) + if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path)) { - if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path)) - { - IndexNumber = IndexNumber ?? LibraryManager.GetSeasonNumberFromPath(Path); + IndexNumber = IndexNumber ?? LibraryManager.GetSeasonNumberFromPath(Path); - // If a change was made record it - if (IndexNumber.HasValue) - { - hasChanges = true; - } + // If a change was made record it + if (IndexNumber.HasValue) + { + hasChanges = true; } } diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index a1e7c7e15..17fc0c0d2 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -240,7 +240,7 @@ namespace MediaBrowser.Controller.Entities.TV if (!includeMissingSeasons) { - seasons = seasons.Where(i => !(i.IsMissingSeason ?? false)); + seasons = seasons.Where(i => !(i.IsMissingSeason)); } if (!includeVirtualUnaired) { diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index fbca357cd..d4a8b0730 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1142,7 +1142,7 @@ namespace MediaBrowser.Controller.Entities var e = i as Season; if (e != null) { - return (e.IsMissingSeason ?? false) == val; + return (e.IsMissingSeason) == val; } return true; }); diff --git a/MediaBrowser.Providers/TV/DummySeasonProvider.cs b/MediaBrowser.Providers/TV/DummySeasonProvider.cs index 8fb04b852..909760fee 100644 --- a/MediaBrowser.Providers/TV/DummySeasonProvider.cs +++ b/MediaBrowser.Providers/TV/DummySeasonProvider.cs @@ -97,7 +97,7 @@ namespace MediaBrowser.Providers.TV /// public async Task AddSeason(Series series, int? seasonNumber, - bool isMissingSeason, + bool isVirtualItem, CancellationToken cancellationToken) { var seasonName = seasonNumber == 0 ? @@ -111,7 +111,7 @@ namespace MediaBrowser.Providers.TV Name = seasonName, IndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName), typeof(Season)), - IsMissingSeason = isMissingSeason + IsVirtualItem = isVirtualItem }; season.SetParent(series); diff --git a/MediaBrowser.Providers/TV/SeasonMetadataService.cs b/MediaBrowser.Providers/TV/SeasonMetadataService.cs index fc072052a..ae19a6a44 100644 --- a/MediaBrowser.Providers/TV/SeasonMetadataService.cs +++ b/MediaBrowser.Providers/TV/SeasonMetadataService.cs @@ -36,7 +36,7 @@ namespace MediaBrowser.Providers.TV { var episodes = item.GetEpisodes().ToList(); updateType |= SavePremiereDate(item, episodes); - updateType |= SaveIsMissing(item, episodes); + updateType |= SaveIsVirtualItem(item, episodes); } return updateType; @@ -67,13 +67,13 @@ namespace MediaBrowser.Providers.TV return ItemUpdateType.None; } - private ItemUpdateType SaveIsMissing(Season item, List episodes) + private ItemUpdateType SaveIsVirtualItem(Season item, List episodes) { - var isMissing = item.LocationType == LocationType.Virtual && (episodes.Count == 0 || episodes.All(i => i.IsMissingEpisode)); + var isVirtualItem = item.LocationType == LocationType.Virtual && (episodes.Count == 0 || episodes.All(i => i.LocationType == LocationType.Virtual)); - if (item.IsMissingSeason != isMissing) + if (item.IsVirtualItem != isVirtualItem) { - item.IsMissingSeason = isMissing; + item.IsVirtualItem = isVirtualItem; return ItemUpdateType.MetadataEdit; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 8c7432b21..7f45e6184 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -238,6 +238,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "PrimaryVersionId", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "DateLastMediaAdded", "DATETIME"); _connection.AddColumn(Logger, "TypedBaseItems", "Album", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "IsVirtualItem", "BIT"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); @@ -359,7 +360,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "DateLastMediaAdded", "Album", "CriticRating", - "CriticRatingSummary" + "CriticRatingSummary", + "IsVirtualItem" }; private readonly string[] _mediaStreamSaveColumns = @@ -474,7 +476,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "OriginalTitle", "PrimaryVersionId", "DateLastMediaAdded", - "Album" + "Album", + "IsVirtualItem" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -866,6 +869,16 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.Album; + var season = item as Season; + if (season != null && season.IsVirtualItem.HasValue) + { + _saveItemCommand.GetParameter(index++).Value = season.IsVirtualItem.Value; + } + else + { + _saveItemCommand.GetParameter(index++).Value = null; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1281,6 +1294,12 @@ namespace MediaBrowser.Server.Implementations.Persistence item.CriticRatingSummary = reader.GetString(57); } + var season = item as Season; + if (season != null && !reader.IsDBNull(58)) + { + season.IsVirtualItem = reader.GetBoolean(58); + } + return item; }