From 48228430c06cae668b19bc55a25b1fecb2082a08 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Wed, 15 May 2024 01:23:23 +0200 Subject: [PATCH 1/4] Fix season names --- .../Library/Resolvers/TV/SeasonResolver.cs | 2 +- MediaBrowser.Controller/Entities/TV/Series.cs | 25 ++++++++++++++++--- .../TV/SeriesMetadataService.cs | 17 ++++++------- .../Parsers/SeriesNfoParser.cs | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs b/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs index 858c5b281..ff4a88162 100644 --- a/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs @@ -83,7 +83,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV var seasonNumber = season.IndexNumber.Value; if (string.IsNullOrEmpty(season.Name)) { - var seasonNames = series.SeasonNames; + var seasonNames = series.GetSeasonNames(); if (seasonNames.TryGetValue(seasonNumber, out var seasonName)) { season.Name = seasonName; diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index a49c1609d..dbc323db5 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -25,19 +25,18 @@ namespace MediaBrowser.Controller.Entities.TV /// public class Series : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo, IMetadataContainer { + private readonly Dictionary _seasonNames; + public Series() { AirDays = Array.Empty(); - SeasonNames = new Dictionary(); + _seasonNames = new Dictionary(); } public DayOfWeek[] AirDays { get; set; } public string AirTime { get; set; } - [JsonIgnore] - public Dictionary SeasonNames { get; set; } - [JsonIgnore] public override bool SupportsAddingToPlaylist => true; @@ -213,6 +212,24 @@ namespace MediaBrowser.Controller.Entities.TV return LibraryManager.GetItemList(query); } + public Dictionary GetSeasonNames() + { + if (_seasonNames.Count > 0) + { + return _seasonNames; + } + + return Children.OfType() + .Where(s => s.IndexNumber.HasValue) + .DistinctBy(s => s.IndexNumber) + .ToDictionary(s => s.IndexNumber.Value, s => s.Name); + } + + public void SetSeasonName(int index, string name) + { + _seasonNames[index] = name; + } + private void SetSeasonQueryOptions(InternalItemsQuery query, User user) { var seriesKey = GetUniqueSeriesKey(this); diff --git a/MediaBrowser.Providers/TV/SeriesMetadataService.cs b/MediaBrowser.Providers/TV/SeriesMetadataService.cs index 0acc1c805..2509c3584 100644 --- a/MediaBrowser.Providers/TV/SeriesMetadataService.cs +++ b/MediaBrowser.Providers/TV/SeriesMetadataService.cs @@ -88,18 +88,17 @@ namespace MediaBrowser.Providers.TV var sourceItem = source.Item; var targetItem = target.Item; - var sourceSeasonNames = sourceItem.SeasonNames; - var targetSeasonNames = targetItem.SeasonNames; + var sourceSeasonNames = sourceItem.GetSeasonNames(); + var targetSeasonNames = targetItem.GetSeasonNames(); - if (replaceData || targetSeasonNames.Count == 0) - { - targetItem.SeasonNames = sourceSeasonNames; - } - else if (targetSeasonNames.Count != sourceSeasonNames.Count || !sourceSeasonNames.Keys.All(targetSeasonNames.ContainsKey)) + if (replaceData + || targetSeasonNames.Count == 0 + || targetSeasonNames.Count != sourceSeasonNames.Count + || !sourceSeasonNames.Keys.All(targetSeasonNames.ContainsKey)) { foreach (var (number, name) in sourceSeasonNames) { - targetSeasonNames.TryAdd(number, name); + target.Item.SetSeasonName(number, name); } } @@ -221,7 +220,7 @@ namespace MediaBrowser.Providers.TV /// The async task. private async Task UpdateAndCreateSeasonsAsync(Series series, CancellationToken cancellationToken) { - var seasonNames = series.SeasonNames; + var seasonNames = series.GetSeasonNames(); var seriesChildren = series.GetRecursiveChildren(i => i is Episode || i is Season); var seasons = seriesChildren.OfType().ToList(); var uniqueSeasonNumbers = seriesChildren diff --git a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs index dbcfe7997..94df871e9 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs @@ -107,7 +107,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers if (!string.IsNullOrWhiteSpace(name) && parsed) { - item.SeasonNames[seasonNumber] = name; + item.SetSeasonName(seasonNumber, name); } break; From 1cdf0f5cc4c899ecb9e43d0a22c907f3395c00da Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 16 May 2024 08:22:40 +0200 Subject: [PATCH 2/4] Apply review suggestion --- MediaBrowser.Controller/Entities/TV/Series.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index dbc323db5..a2d5e3867 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -214,15 +214,19 @@ namespace MediaBrowser.Controller.Entities.TV public Dictionary GetSeasonNames() { - if (_seasonNames.Count > 0) + if (_seasonNames.Count == 0) { - return _seasonNames; + var childSeasons = Children.OfType() + .Where(s => s.IndexNumber.HasValue) + .DistinctBy(s => s.IndexNumber); + + foreach (var season in childSeasons) + { + _seasonNames[season.IndexNumber.Value] = season.Name; + } } - return Children.OfType() - .Where(s => s.IndexNumber.HasValue) - .DistinctBy(s => s.IndexNumber) - .ToDictionary(s => s.IndexNumber.Value, s => s.Name); + return _seasonNames; } public void SetSeasonName(int index, string name) From af4b7320806c3e133ad7c84d09119e79a4e9a39c Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 16 May 2024 08:25:35 +0200 Subject: [PATCH 3/4] Fix override of locked name --- MediaBrowser.Providers/TV/SeriesMetadataService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Providers/TV/SeriesMetadataService.cs b/MediaBrowser.Providers/TV/SeriesMetadataService.cs index 2509c3584..add91a61a 100644 --- a/MediaBrowser.Providers/TV/SeriesMetadataService.cs +++ b/MediaBrowser.Providers/TV/SeriesMetadataService.cs @@ -244,7 +244,7 @@ namespace MediaBrowser.Providers.TV var season = await CreateSeasonAsync(series, seasonName, seasonNumber, cancellationToken).ConfigureAwait(false); series.AddChild(season); } - else if (!string.Equals(existingSeason.Name, seasonName, StringComparison.Ordinal)) + else if (!existingSeason.LockedFields.Contains(MetadataField.Name) && !string.Equals(existingSeason.Name, seasonName, StringComparison.Ordinal)) { existingSeason.Name = seasonName; await existingSeason.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); From dc93cc13b512dc98365299e38c55e905d42f86e9 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 16 May 2024 19:36:49 +0200 Subject: [PATCH 4/4] Apply review suggestion --- MediaBrowser.Controller/Entities/TV/Series.cs | 16 +++++++--------- .../TV/SeriesMetadataService.cs | 15 ++++++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index a2d5e3867..d200721b2 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -214,16 +214,14 @@ namespace MediaBrowser.Controller.Entities.TV public Dictionary GetSeasonNames() { - if (_seasonNames.Count == 0) - { - var childSeasons = Children.OfType() - .Where(s => s.IndexNumber.HasValue) - .DistinctBy(s => s.IndexNumber); + var newSeasons = Children.OfType() + .Where(s => s.IndexNumber.HasValue) + .Where(s => !_seasonNames.ContainsKey(s.IndexNumber.Value)) + .DistinctBy(s => s.IndexNumber); - foreach (var season in childSeasons) - { - _seasonNames[season.IndexNumber.Value] = season.Name; - } + foreach (var season in newSeasons) + { + SetSeasonName(season.IndexNumber.Value, season.Name); } return _seasonNames; diff --git a/MediaBrowser.Providers/TV/SeriesMetadataService.cs b/MediaBrowser.Providers/TV/SeriesMetadataService.cs index add91a61a..62eb0d89c 100644 --- a/MediaBrowser.Providers/TV/SeriesMetadataService.cs +++ b/MediaBrowser.Providers/TV/SeriesMetadataService.cs @@ -91,14 +91,19 @@ namespace MediaBrowser.Providers.TV var sourceSeasonNames = sourceItem.GetSeasonNames(); var targetSeasonNames = targetItem.GetSeasonNames(); - if (replaceData - || targetSeasonNames.Count == 0 - || targetSeasonNames.Count != sourceSeasonNames.Count - || !sourceSeasonNames.Keys.All(targetSeasonNames.ContainsKey)) + if (replaceData) { foreach (var (number, name) in sourceSeasonNames) { - target.Item.SetSeasonName(number, name); + targetItem.SetSeasonName(number, name); + } + } + else if (!sourceSeasonNames.Keys.All(targetSeasonNames.ContainsKey)) + { + var newSeasons = sourceSeasonNames.Where(s => !targetSeasonNames.ContainsKey(s.Key)); + foreach (var (number, name) in newSeasons) + { + targetItem.SetSeasonName(number, name); } }