diff options
Diffstat (limited to 'MediaBrowser.Providers/TV/DummySeasonProvider.cs')
| -rw-r--r-- | MediaBrowser.Providers/TV/DummySeasonProvider.cs | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/MediaBrowser.Providers/TV/DummySeasonProvider.cs b/MediaBrowser.Providers/TV/DummySeasonProvider.cs index 771570cbc7..4f528086e0 100644 --- a/MediaBrowser.Providers/TV/DummySeasonProvider.cs +++ b/MediaBrowser.Providers/TV/DummySeasonProvider.cs @@ -8,8 +8,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; - -using MediaBrowser.Controller.IO; +using System.Collections.Generic; using MediaBrowser.Model.IO; using MediaBrowser.Model.Globalization; @@ -34,9 +33,9 @@ namespace MediaBrowser.Providers.TV _fileSystem = fileSystem; } - public async Task Run(Series series, CancellationToken cancellationToken) + public async Task<bool> Run(Series series, CancellationToken cancellationToken) { - await RemoveObsoleteSeasons(series).ConfigureAwait(false); + var seasonsRemoved = RemoveObsoleteSeasons(series); var hasNewSeasons = await AddDummySeasonFolders(series, cancellationToken).ConfigureAwait(false); @@ -49,6 +48,8 @@ namespace MediaBrowser.Providers.TV //await series.ValidateChildren(new SimpleProgress<double>(), cancellationToken, new MetadataRefreshOptions(directoryService)) // .ConfigureAwait(false); } + + return seasonsRemoved || hasNewSeasons; } private async Task<bool> AddDummySeasonFolders(Series series, CancellationToken cancellationToken) @@ -60,32 +61,44 @@ namespace MediaBrowser.Providers.TV var hasChanges = false; + List<Season> seasons = null; + // Loop through the unique season numbers foreach (var seasonNumber in episodesInSeriesFolder.Select(i => i.ParentIndexNumber ?? -1) .Where(i => i >= 0) .Distinct() .ToList()) { - var existingSeason = series.Children.OfType<Season>() + if (seasons == null) + { + seasons = series.Children.OfType<Season>().ToList(); + } + var existingSeason = seasons .FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == seasonNumber); if (existingSeason == null) { await AddSeason(series, seasonNumber, false, cancellationToken).ConfigureAwait(false); - hasChanges = true; + seasons = null; } else if (existingSeason.IsVirtualItem) { existingSeason.IsVirtualItem = false; existingSeason.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken); + seasons = null; } } // Unknown season - create a dummy season to put these under if (episodesInSeriesFolder.Any(i => !i.ParentIndexNumber.HasValue)) { - var existingSeason = series.Children.OfType<Season>() + if (seasons == null) + { + seasons = series.Children.OfType<Season>().ToList(); + } + + var existingSeason = seasons .FirstOrDefault(i => !i.IndexNumber.HasValue); if (existingSeason == null) @@ -93,11 +106,13 @@ namespace MediaBrowser.Providers.TV await AddSeason(series, null, false, cancellationToken).ConfigureAwait(false); hasChanges = true; + seasons = null; } else if (existingSeason.IsVirtualItem) { existingSeason.IsVirtualItem = false; existingSeason.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken); + seasons = null; } } @@ -137,7 +152,7 @@ namespace MediaBrowser.Providers.TV return season; } - private async Task<bool> RemoveObsoleteSeasons(Series series) + private bool RemoveObsoleteSeasons(Series series) { var existingSeasons = series.Children.OfType<Season>().ToList(); @@ -177,13 +192,13 @@ namespace MediaBrowser.Providers.TV foreach (var seasonToRemove in seasonsToRemove) { - _logger.Info("Removing virtual season {0} {1}", seasonToRemove.Series.Name, seasonToRemove.IndexNumber); + _logger.Info("Removing virtual season {0} {1}", series.Name, seasonToRemove.IndexNumber); - await seasonToRemove.Delete(new DeleteOptions + _libraryManager.DeleteItem(seasonToRemove, new DeleteOptions { DeleteFileLocation = true - }).ConfigureAwait(false); + }, false); hasChanges = true; } |
