mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 09:59:06 -07:00
Merge pull request #12050 from Shadowghost/fix-seasons
Fix season handling
This commit is contained in:
commit
4601097d3e
@ -350,17 +350,10 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
|
||||
public List<BaseItem> GetSeasonEpisodes(Season parentSeason, User user, DtoOptions options, bool shouldIncludeMissingEpisodes)
|
||||
{
|
||||
var queryFromSeries = ConfigurationManager.Configuration.DisplaySpecialsWithinSeasons;
|
||||
|
||||
// add optimization when this setting is not enabled
|
||||
var seriesKey = queryFromSeries ?
|
||||
GetUniqueSeriesKey(this) :
|
||||
GetUniqueSeriesKey(parentSeason);
|
||||
|
||||
var query = new InternalItemsQuery(user)
|
||||
{
|
||||
AncestorWithPresentationUniqueKey = queryFromSeries ? null : seriesKey,
|
||||
SeriesPresentationUniqueKey = queryFromSeries ? seriesKey : null,
|
||||
AncestorWithPresentationUniqueKey = null,
|
||||
SeriesPresentationUniqueKey = GetUniqueSeriesKey(this),
|
||||
IncludeItemTypes = new[] { BaseItemKind.Episode },
|
||||
OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },
|
||||
DtoOptions = options
|
||||
|
@ -61,8 +61,8 @@ namespace MediaBrowser.Providers.TV
|
||||
await base.AfterMetadataRefresh(item, refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
RemoveObsoleteEpisodes(item);
|
||||
RemoveObsoleteSeasons(item);
|
||||
await CreateSeasonsAsync(item, cancellationToken).ConfigureAwait(false);
|
||||
RemoveObsoleteSeasons(item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -91,7 +91,7 @@ namespace MediaBrowser.Providers.TV
|
||||
|
||||
private void RemoveObsoleteSeasons(Series series)
|
||||
{
|
||||
// TODO Legacy. It's not really "physical" seasons as any virtual seasons are always converted to non-virtual in UpdateAndCreateSeasonsAsync.
|
||||
// TODO Legacy. It's not really "physical" seasons as any virtual seasons are always converted to non-virtual in CreateSeasonsAsync.
|
||||
var physicalSeasonNumbers = new HashSet<int>();
|
||||
var virtualSeasons = new List<Season>();
|
||||
foreach (var existingSeason in series.Children.OfType<Season>())
|
||||
@ -203,11 +203,16 @@ namespace MediaBrowser.Providers.TV
|
||||
foreach (var seasonNumber in uniqueSeasonNumbers)
|
||||
{
|
||||
// Null season numbers will have a 'dummy' season created because seasons are always required.
|
||||
if (!seasons.Any(i => i.IndexNumber == seasonNumber))
|
||||
var existingSeason = seasons.FirstOrDefault(i => i.IndexNumber == seasonNumber);
|
||||
if (existingSeason is null)
|
||||
{
|
||||
var seasonName = GetValidSeasonNameForSeries(series, null, seasonNumber);
|
||||
var season = await CreateSeasonAsync(series, seasonName, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||||
series.AddChild(season);
|
||||
await CreateSeasonAsync(series, seasonName, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else if (existingSeason.IsVirtualItem)
|
||||
{
|
||||
existingSeason.IsVirtualItem = false;
|
||||
await existingSeason.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,7 +225,7 @@ namespace MediaBrowser.Providers.TV
|
||||
/// <param name="seasonNumber">The season number.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>The newly created season.</returns>
|
||||
private async Task<Season> CreateSeasonAsync(
|
||||
private async Task CreateSeasonAsync(
|
||||
Series series,
|
||||
string? seasonName,
|
||||
int? seasonNumber,
|
||||
@ -237,14 +242,12 @@ namespace MediaBrowser.Providers.TV
|
||||
typeof(Season)),
|
||||
IsVirtualItem = false,
|
||||
SeriesId = series.Id,
|
||||
SeriesName = series.Name
|
||||
SeriesName = series.Name,
|
||||
SeriesPresentationUniqueKey = series.GetPresentationUniqueKey()
|
||||
};
|
||||
|
||||
series.AddChild(season);
|
||||
|
||||
await season.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return season;
|
||||
}
|
||||
|
||||
private string GetValidSeasonNameForSeries(Series series, string? seasonName, int? seasonNumber)
|
||||
|
Loading…
Reference in New Issue
Block a user