Backport pull request #11647 from jellyfin/release-10.9.z
Fix season names
Original-merge: 2da06bc0b1
Merged-by: joshuaboniface <joshua@boniface.me>
Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
parent
77c3ddc7ca
commit
29a293f9e7
|
@ -83,7 +83,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
|
||||||
var seasonNumber = season.IndexNumber.Value;
|
var seasonNumber = season.IndexNumber.Value;
|
||||||
if (string.IsNullOrEmpty(season.Name))
|
if (string.IsNullOrEmpty(season.Name))
|
||||||
{
|
{
|
||||||
var seasonNames = series.SeasonNames;
|
var seasonNames = series.GetSeasonNames();
|
||||||
if (seasonNames.TryGetValue(seasonNumber, out var seasonName))
|
if (seasonNames.TryGetValue(seasonNumber, out var seasonName))
|
||||||
{
|
{
|
||||||
season.Name = seasonName;
|
season.Name = seasonName;
|
||||||
|
|
|
@ -25,19 +25,18 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Series : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>, IMetadataContainer
|
public class Series : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>, IMetadataContainer
|
||||||
{
|
{
|
||||||
|
private readonly Dictionary<int, string> _seasonNames;
|
||||||
|
|
||||||
public Series()
|
public Series()
|
||||||
{
|
{
|
||||||
AirDays = Array.Empty<DayOfWeek>();
|
AirDays = Array.Empty<DayOfWeek>();
|
||||||
SeasonNames = new Dictionary<int, string>();
|
_seasonNames = new Dictionary<int, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DayOfWeek[] AirDays { get; set; }
|
public DayOfWeek[] AirDays { get; set; }
|
||||||
|
|
||||||
public string AirTime { get; set; }
|
public string AirTime { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public Dictionary<int, string> SeasonNames { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public override bool SupportsAddingToPlaylist => true;
|
public override bool SupportsAddingToPlaylist => true;
|
||||||
|
|
||||||
|
@ -213,6 +212,26 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||||
return LibraryManager.GetItemList(query);
|
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)
|
private void SetSeasonQueryOptions(InternalItemsQuery query, User user)
|
||||||
{
|
{
|
||||||
var seriesKey = GetUniqueSeriesKey(this);
|
var seriesKey = GetUniqueSeriesKey(this);
|
||||||
|
|
|
@ -88,18 +88,22 @@ namespace MediaBrowser.Providers.TV
|
||||||
|
|
||||||
var sourceItem = source.Item;
|
var sourceItem = source.Item;
|
||||||
var targetItem = target.Item;
|
var targetItem = target.Item;
|
||||||
var sourceSeasonNames = sourceItem.SeasonNames;
|
var sourceSeasonNames = sourceItem.GetSeasonNames();
|
||||||
var targetSeasonNames = targetItem.SeasonNames;
|
var targetSeasonNames = targetItem.GetSeasonNames();
|
||||||
|
|
||||||
if (replaceData || targetSeasonNames.Count == 0)
|
if (replaceData)
|
||||||
{
|
|
||||||
targetItem.SeasonNames = sourceSeasonNames;
|
|
||||||
}
|
|
||||||
else if (targetSeasonNames.Count != sourceSeasonNames.Count || !sourceSeasonNames.Keys.All(targetSeasonNames.ContainsKey))
|
|
||||||
{
|
{
|
||||||
foreach (var (number, name) in sourceSeasonNames)
|
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>
|
/// <returns>The async task.</returns>
|
||||||
private async Task UpdateAndCreateSeasonsAsync(Series series, CancellationToken cancellationToken)
|
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 seriesChildren = series.GetRecursiveChildren(i => i is Episode || i is Season);
|
||||||
var seasons = seriesChildren.OfType<Season>().ToList();
|
var seasons = seriesChildren.OfType<Season>().ToList();
|
||||||
var uniqueSeasonNumbers = seriesChildren
|
var uniqueSeasonNumbers = seriesChildren
|
||||||
|
@ -245,7 +249,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
var season = await CreateSeasonAsync(series, seasonName, seasonNumber, cancellationToken).ConfigureAwait(false);
|
var season = await CreateSeasonAsync(series, seasonName, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||||||
series.AddChild(season);
|
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;
|
existingSeason.Name = seasonName;
|
||||||
await existingSeason.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
|
await existingSeason.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
|
@ -107,7 +107,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(name) && parsed)
|
if (!string.IsNullOrWhiteSpace(name) && parsed)
|
||||||
{
|
{
|
||||||
item.SeasonNames[seasonNumber] = name;
|
item.SetSeasonName(seasonNumber, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user