|
|
@ -41,7 +41,7 @@ namespace MediaBrowser.Providers.TV
|
|
|
|
|
|
|
|
|
|
|
|
RemoveObsoleteEpisodes(item);
|
|
|
|
RemoveObsoleteEpisodes(item);
|
|
|
|
RemoveObsoleteSeasons(item);
|
|
|
|
RemoveObsoleteSeasons(item);
|
|
|
|
await FillInMissingSeasonsAsync(item, cancellationToken).ConfigureAwait(false);
|
|
|
|
await UpdateAndCreateSeasonsAsync(item, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
@ -67,6 +67,24 @@ 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 targetSeasonNames = targetItem.SeasonNames;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (replaceData || targetSeasonNames.Count == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
targetItem.SeasonNames = sourceSeasonNames;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (targetSeasonNames.Count != sourceSeasonNames.Count || !sourceSeasonNames.Keys.All(targetSeasonNames.ContainsKey))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var season in sourceSeasonNames)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var seasonNumber = season.Key;
|
|
|
|
|
|
|
|
if (!targetSeasonNames.ContainsKey(seasonNumber))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
targetItem.SeasonNames[seasonNumber] = season.Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(targetItem.AirTime))
|
|
|
|
if (replaceData || string.IsNullOrEmpty(targetItem.AirTime))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -86,7 +104,7 @@ namespace MediaBrowser.Providers.TV
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveObsoleteSeasons(Series series)
|
|
|
|
private void RemoveObsoleteSeasons(Series series)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO Legacy. It's not really "physical" seasons as any virtual seasons are always converted to non-virtual in FillInMissingSeasonsAsync.
|
|
|
|
// TODO Legacy. It's not really "physical" seasons as any virtual seasons are always converted to non-virtual in UpdateAndCreateSeasonsAsync.
|
|
|
|
var physicalSeasonNumbers = new HashSet<int>();
|
|
|
|
var physicalSeasonNumbers = new HashSet<int>();
|
|
|
|
var virtualSeasons = new List<Season>();
|
|
|
|
var virtualSeasons = new List<Season>();
|
|
|
|
foreach (var existingSeason in series.Children.OfType<Season>())
|
|
|
|
foreach (var existingSeason in series.Children.OfType<Season>())
|
|
|
@ -177,36 +195,43 @@ namespace MediaBrowser.Providers.TV
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates seasons for all episodes that aren't in a season folder.
|
|
|
|
/// Creates seasons for all episodes if they don't exist.
|
|
|
|
/// If no season number can be determined, a dummy season will be created.
|
|
|
|
/// If no season number can be determined, a dummy season will be created.
|
|
|
|
|
|
|
|
/// Updates seasons names.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="series">The series.</param>
|
|
|
|
/// <param name="series">The series.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <returns>The async task.</returns>
|
|
|
|
/// <returns>The async task.</returns>
|
|
|
|
private async Task FillInMissingSeasonsAsync(Series series, CancellationToken cancellationToken)
|
|
|
|
private async Task UpdateAndCreateSeasonsAsync(Series series, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var seasonNames = series.SeasonNames;
|
|
|
|
var seriesChildren = series.GetRecursiveChildren(i => i is Episode || i is Season);
|
|
|
|
var seriesChildren = series.GetRecursiveChildren(i => i is Episode || i is Season);
|
|
|
|
var episodesInSeriesFolder = seriesChildren
|
|
|
|
var seasons = seriesChildren.OfType<Season>().ToList();
|
|
|
|
|
|
|
|
var uniqueSeasonNumbers = seriesChildren
|
|
|
|
.OfType<Episode>()
|
|
|
|
.OfType<Episode>()
|
|
|
|
.Where(i => !i.IsInSeasonFolder);
|
|
|
|
.Select(e => e.ParentIndexNumber >= 0 ? e.ParentIndexNumber : null)
|
|
|
|
|
|
|
|
.Distinct();
|
|
|
|
List<Season> seasons = seriesChildren.OfType<Season>().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through the unique season numbers
|
|
|
|
// Loop through the unique season numbers
|
|
|
|
foreach (var episode in episodesInSeriesFolder)
|
|
|
|
foreach (var seasonNumber in uniqueSeasonNumbers)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Null season numbers will have a 'dummy' season created because seasons are always required.
|
|
|
|
// Null season numbers will have a 'dummy' season created because seasons are always required.
|
|
|
|
var seasonNumber = episode.ParentIndexNumber >= 0 ? episode.ParentIndexNumber : null;
|
|
|
|
|
|
|
|
var existingSeason = seasons.FirstOrDefault(i => i.IndexNumber == seasonNumber);
|
|
|
|
var existingSeason = seasons.FirstOrDefault(i => i.IndexNumber == seasonNumber);
|
|
|
|
|
|
|
|
string? seasonName = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (seasonNumber.HasValue && seasonNames.ContainsKey(seasonNumber.Value))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
seasonName = seasonNames[seasonNumber.Value];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (existingSeason is null)
|
|
|
|
if (existingSeason is null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var season = await CreateSeasonAsync(series, seasonNumber, cancellationToken).ConfigureAwait(false);
|
|
|
|
var season = await CreateSeasonAsync(series, seasonName, seasonNumber, cancellationToken).ConfigureAwait(false);
|
|
|
|
seasons.Add(season);
|
|
|
|
series.AddChild(season);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (existingSeason.IsVirtualItem)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
existingSeason.IsVirtualItem = false;
|
|
|
|
existingSeason.Name = GetValidSeasonNameForSeries(series, seasonName, seasonNumber);
|
|
|
|
await existingSeason.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
|
|
|
|
await existingSeason.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -216,21 +241,17 @@ namespace MediaBrowser.Providers.TV
|
|
|
|
/// Creates a new season, adds it to the database by linking it to the [series] and refreshes the metadata.
|
|
|
|
/// Creates a new season, adds it to the database by linking it to the [series] and refreshes the metadata.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="series">The series.</param>
|
|
|
|
/// <param name="series">The series.</param>
|
|
|
|
|
|
|
|
/// <param name="seasonName">The season name.</param>
|
|
|
|
/// <param name="seasonNumber">The season number.</param>
|
|
|
|
/// <param name="seasonNumber">The season number.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <returns>The newly created season.</returns>
|
|
|
|
/// <returns>The newly created season.</returns>
|
|
|
|
private async Task<Season> CreateSeasonAsync(
|
|
|
|
private async Task<Season> CreateSeasonAsync(
|
|
|
|
Series series,
|
|
|
|
Series series,
|
|
|
|
|
|
|
|
string? seasonName,
|
|
|
|
int? seasonNumber,
|
|
|
|
int? seasonNumber,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string seasonName = seasonNumber switch
|
|
|
|
seasonName = GetValidSeasonNameForSeries(series, seasonName, seasonNumber);
|
|
|
|
{
|
|
|
|
|
|
|
|
null => _localizationManager.GetLocalizedString("NameSeasonUnknown"),
|
|
|
|
|
|
|
|
0 => LibraryManager.GetLibraryOptions(series).SeasonZeroDisplayName,
|
|
|
|
|
|
|
|
_ => string.Format(CultureInfo.InvariantCulture, _localizationManager.GetLocalizedString("NameSeasonNumber"), seasonNumber.Value)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.LogInformation("Creating Season {SeasonName} entry for {SeriesName}", seasonName, series.Name);
|
|
|
|
Logger.LogInformation("Creating Season {SeasonName} entry for {SeriesName}", seasonName, series.Name);
|
|
|
|
|
|
|
|
|
|
|
|
var season = new Season
|
|
|
|
var season = new Season
|
|
|
@ -251,5 +272,20 @@ namespace MediaBrowser.Providers.TV
|
|
|
|
|
|
|
|
|
|
|
|
return season;
|
|
|
|
return season;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string GetValidSeasonNameForSeries(Series series, string? seasonName, int? seasonNumber)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(seasonName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
seasonName = seasonNumber switch
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
null => _localizationManager.GetLocalizedString("NameSeasonUnknown"),
|
|
|
|
|
|
|
|
0 => LibraryManager.GetLibraryOptions(series).SeasonZeroDisplayName,
|
|
|
|
|
|
|
|
_ => string.Format(CultureInfo.InvariantCulture, _localizationManager.GetLocalizedString("NameSeasonNumber"), seasonNumber.Value)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return seasonName;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|