Merge pull request #11647 from Shadowghost/fix-season-names
Fix season names
This commit is contained in:
commit
2da06bc0b1
|
@ -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;
|
||||
|
|
|
@ -25,19 +25,18 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
/// </summary>
|
||||
public class Series : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>, IMetadataContainer
|
||||
{
|
||||
private readonly Dictionary<int, string> _seasonNames;
|
||||
|
||||
public Series()
|
||||
{
|
||||
AirDays = Array.Empty<DayOfWeek>();
|
||||
SeasonNames = new Dictionary<int, string>();
|
||||
_seasonNames = new Dictionary<int, string>();
|
||||
}
|
||||
|
||||
public DayOfWeek[] AirDays { get; set; }
|
||||
|
||||
public string AirTime { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Dictionary<int, string> SeasonNames { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public override bool SupportsAddingToPlaylist => true;
|
||||
|
||||
|
@ -213,6 +212,26 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
return LibraryManager.GetItemList(query);
|
||||
}
|
||||
|
||||
public Dictionary<int, string> GetSeasonNames()
|
||||
{
|
||||
var newSeasons = Children.OfType<Season>()
|
||||
.Where(s => s.IndexNumber.HasValue)
|
||||
.Where(s => !_seasonNames.ContainsKey(s.IndexNumber.Value))
|
||||
.DistinctBy(s => s.IndexNumber);
|
||||
|
||||
foreach (var season in newSeasons)
|
||||
{
|
||||
SetSeasonName(season.IndexNumber.Value, season.Name);
|
||||
}
|
||||
|
||||
return _seasonNames;
|
||||
}
|
||||
|
||||
public void SetSeasonName(int index, string name)
|
||||
{
|
||||
_seasonNames[index] = name;
|
||||
}
|
||||
|
||||
private void SetSeasonQueryOptions(InternalItemsQuery query, User user)
|
||||
{
|
||||
var seriesKey = GetUniqueSeriesKey(this);
|
||||
|
|
|
@ -88,18 +88,22 @@ 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)
|
||||
{
|
||||
foreach (var (number, name) in sourceSeasonNames)
|
||||
{
|
||||
targetSeasonNames.TryAdd(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,7 +225,7 @@ namespace MediaBrowser.Providers.TV
|
|||
/// <returns>The async task.</returns>
|
||||
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<Season>().ToList();
|
||||
var uniqueSeasonNumbers = seriesChildren
|
||||
|
@ -245,7 +249,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);
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
|
||||
if (!string.IsNullOrWhiteSpace(name) && parsed)
|
||||
{
|
||||
item.SeasonNames[seasonNumber] = name;
|
||||
item.SetSeasonName(seasonNumber, name);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user