update season creator

This commit is contained in:
Luke Pulverenti 2017-01-13 22:48:25 -05:00
parent 1cb7a1b49c
commit 7a77aa42c5

View File

@ -66,29 +66,39 @@ namespace MediaBrowser.Providers.TV
.Distinct()
.ToList())
{
var hasSeason = series.Children.OfType<Season>()
.Any(i => i.IndexNumber.HasValue && i.IndexNumber.Value == seasonNumber);
var existingSeason = series.Children.OfType<Season>()
.FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == seasonNumber);
if (!hasSeason)
if (existingSeason == null)
{
await AddSeason(series, seasonNumber, false, cancellationToken).ConfigureAwait(false);
hasChanges = true;
}
else if (existingSeason.IsVirtualItem)
{
existingSeason.IsVirtualItem = false;
await existingSeason.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
}
}
// Unknown season - create a dummy season to put these under
if (episodesInSeriesFolder.Any(i => !i.ParentIndexNumber.HasValue))
{
var hasSeason = series.Children.OfType<Season>()
.Any(i => !i.IndexNumber.HasValue);
var existingSeason = series.Children.OfType<Season>()
.FirstOrDefault(i => !i.IndexNumber.HasValue);
if (!hasSeason)
if (existingSeason == null)
{
await AddSeason(series, null, false, cancellationToken).ConfigureAwait(false);
hasChanges = true;
}
else if (existingSeason.IsVirtualItem)
{
existingSeason.IsVirtualItem = false;
await existingSeason.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
}
}
return hasChanges;