diff options
| author | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
|---|---|---|
| committer | stefan <stefan@hegedues.at> | 2018-09-12 19:26:21 +0200 |
| commit | 48facb797ed912e4ea6b04b17d1ff190ac2daac4 (patch) | |
| tree | 8dae77a31670a888d733484cb17dd4077d5444e8 /Emby.Server.Implementations/TV | |
| parent | c32d8656382a0eacb301692e0084377fc433ae9b (diff) | |
Update to 3.5.2 and .net core 2.1
Diffstat (limited to 'Emby.Server.Implementations/TV')
| -rw-r--r-- | Emby.Server.Implementations/TV/SeriesPostScanTask.cs | 241 | ||||
| -rw-r--r-- | Emby.Server.Implementations/TV/TVSeriesManager.cs | 38 |
2 files changed, 20 insertions, 259 deletions
diff --git a/Emby.Server.Implementations/TV/SeriesPostScanTask.cs b/Emby.Server.Implementations/TV/SeriesPostScanTask.cs deleted file mode 100644 index 764df8baf..000000000 --- a/Emby.Server.Implementations/TV/SeriesPostScanTask.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Dto; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.TV; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Globalization; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Tasks; -using MediaBrowser.Model.Threading; -using MediaBrowser.Model.Xml; -using MediaBrowser.Providers.TV; - -namespace Emby.Server.Implementations.TV -{ - class SeriesGroup : List<Series>, IGrouping<string, Series> - { - public string Key { get; set; } - } - - class SeriesPostScanTask : ILibraryPostScanTask, IHasOrder - { - /// <summary> - /// The _library manager - /// </summary> - private readonly ILibraryManager _libraryManager; - private readonly IServerConfigurationManager _config; - private readonly ILogger _logger; - private readonly ILocalizationManager _localization; - private readonly IFileSystem _fileSystem; - private readonly IXmlReaderSettingsFactory _xmlSettings; - - public SeriesPostScanTask(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, ILocalizationManager localization, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlSettings) - { - _libraryManager = libraryManager; - _logger = logger; - _config = config; - _localization = localization; - _fileSystem = fileSystem; - _xmlSettings = xmlSettings; - } - - public Task Run(IProgress<double> progress, CancellationToken cancellationToken) - { - return RunInternal(progress, cancellationToken); - } - - private Task RunInternal(IProgress<double> progress, CancellationToken cancellationToken) - { - var seriesList = _libraryManager.GetItemList(new InternalItemsQuery() - { - IncludeItemTypes = new[] { typeof(Series).Name }, - Recursive = true, - GroupByPresentationUniqueKey = false, - DtoOptions = new DtoOptions(true) - - }).Cast<Series>().ToList(); - - var seriesGroups = FindSeriesGroups(seriesList).Where(g => !string.IsNullOrEmpty(g.Key)).ToList(); - - return new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem, _xmlSettings).Run(seriesGroups, true, cancellationToken); - } - - internal static IEnumerable<IGrouping<string, Series>> FindSeriesGroups(List<Series> seriesList) - { - var links = seriesList.ToDictionary(s => s, s => seriesList.Where(c => c != s && ShareProviderId(s, c)).ToList()); - - var visited = new HashSet<Series>(); - - foreach (var series in seriesList) - { - if (!visited.Contains(series)) - { - var group = new SeriesGroup(); - FindAllLinked(series, visited, links, group); - - group.Key = group.Select(s => s.PresentationUniqueKey).FirstOrDefault(id => !string.IsNullOrEmpty(id)); - - yield return group; - } - } - } - - private static void FindAllLinked(Series series, HashSet<Series> visited, IDictionary<Series, List<Series>> linksMap, List<Series> results) - { - results.Add(series); - visited.Add(series); - - var links = linksMap[series]; - - foreach (var s in links) - { - if (!visited.Contains(s)) - { - FindAllLinked(s, visited, linksMap, results); - } - } - } - - private static bool ShareProviderId(Series a, Series b) - { - return string.Equals(a.PresentationUniqueKey, b.PresentationUniqueKey, StringComparison.Ordinal); - } - - public int Order - { - get - { - // Run after tvdb update task - return 1; - } - } - } - - public class CleanMissingEpisodesEntryPoint : IServerEntryPoint - { - private readonly ILibraryManager _libraryManager; - private readonly IServerConfigurationManager _config; - private readonly ILogger _logger; - private readonly ILocalizationManager _localization; - private readonly IFileSystem _fileSystem; - private readonly object _libraryChangedSyncLock = new object(); - private const int LibraryUpdateDuration = 180000; - private readonly ITaskManager _taskManager; - private readonly IXmlReaderSettingsFactory _xmlSettings; - private readonly ITimerFactory _timerFactory; - - public CleanMissingEpisodesEntryPoint(ILibraryManager libraryManager, IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, IFileSystem fileSystem, ITaskManager taskManager, IXmlReaderSettingsFactory xmlSettings, ITimerFactory timerFactory) - { - _libraryManager = libraryManager; - _config = config; - _logger = logger; - _localization = localization; - _fileSystem = fileSystem; - _taskManager = taskManager; - _xmlSettings = xmlSettings; - _timerFactory = timerFactory; - } - - private ITimer LibraryUpdateTimer { get; set; } - - public void Run() - { - _libraryManager.ItemAdded += _libraryManager_ItemAdded; - } - - private void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e) - { - if (!FilterItem(e.Item)) - { - return; - } - - lock (_libraryChangedSyncLock) - { - if (LibraryUpdateTimer == null) - { - LibraryUpdateTimer = _timerFactory.Create(LibraryUpdateTimerCallback, null, LibraryUpdateDuration, Timeout.Infinite); - } - else - { - LibraryUpdateTimer.Change(LibraryUpdateDuration, Timeout.Infinite); - } - } - } - - private async void LibraryUpdateTimerCallback(object state) - { - try - { - if (MissingEpisodeProvider.IsRunning) - { - return; - } - - if (_libraryManager.IsScanRunning) - { - return; - } - - var seriesList = _libraryManager.GetItemList(new InternalItemsQuery() - { - IncludeItemTypes = new[] { typeof(Series).Name }, - Recursive = true, - GroupByPresentationUniqueKey = false, - DtoOptions = new DtoOptions(true) - - }).Cast<Series>().ToList(); - - var seriesGroups = SeriesPostScanTask.FindSeriesGroups(seriesList).Where(g => !string.IsNullOrEmpty(g.Key)).ToList(); - - await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem, _xmlSettings) - .Run(seriesGroups, false, CancellationToken.None).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.ErrorException("Error in SeriesPostScanTask", ex); - } - } - - private bool FilterItem(BaseItem item) - { - return item is Episode && item.LocationType != LocationType.Virtual; - } - - /// <summary> - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// </summary> - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// <summary> - /// Releases unmanaged and - optionally - managed resources. - /// </summary> - /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - if (LibraryUpdateTimer != null) - { - LibraryUpdateTimer.Dispose(); - LibraryUpdateTimer = null; - } - - _libraryManager.ItemAdded -= _libraryManager_ItemAdded; - } - } - } -} diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs index d92245a67..1f9cb9164 100644 --- a/Emby.Server.Implementations/TV/TVSeriesManager.cs +++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs @@ -37,48 +37,50 @@ namespace Emby.Server.Implementations.TV } string presentationUniqueKey = null; - int? limit = null; - if (!string.IsNullOrWhiteSpace(request.SeriesId)) + if (!string.IsNullOrEmpty(request.SeriesId)) { var series = _libraryManager.GetItemById(request.SeriesId) as Series; if (series != null) { presentationUniqueKey = GetUniqueSeriesKey(series); - limit = 1; } } - if (!string.IsNullOrWhiteSpace(presentationUniqueKey)) + if (!string.IsNullOrEmpty(presentationUniqueKey)) { return GetResult(GetNextUpEpisodes(request, user, new[] { presentationUniqueKey }, dtoOptions), request); } - var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId); + var parentIdGuid = string.IsNullOrEmpty(request.ParentId) ? (Guid?)null : new Guid(request.ParentId); - List<BaseItem> parents; + BaseItem[] parents; if (parentIdGuid.HasValue) { var parent = _libraryManager.GetItemById(parentIdGuid.Value); - parents = new List<BaseItem>(); + if (parent != null) { - parents.Add(parent); + parents = new[] { parent }; + } + else + { + parents = Array.Empty<BaseItem>(); } } else { - parents = user.RootFolder.GetChildren(user, true) + parents = _libraryManager.GetUserRootFolder().GetChildren(user, true) .Where(i => i is Folder) .Where(i => !user.Configuration.LatestItemsExcludes.Contains(i.Id.ToString("N"))) - .ToList(); + .ToArray(); } return GetNextUp(request, parents, dtoOptions); } - public QueryResult<BaseItem> GetNextUp(NextUpQuery request, List<BaseItem> parentsFolders, DtoOptions dtoOptions) + public QueryResult<BaseItem> GetNextUp(NextUpQuery request, BaseItem[] parentsFolders, DtoOptions dtoOptions) { var user = _userManager.GetUserById(request.UserId); @@ -89,7 +91,7 @@ namespace Emby.Server.Implementations.TV string presentationUniqueKey = null; int? limit = null; - if (!string.IsNullOrWhiteSpace(request.SeriesId)) + if (!string.IsNullOrEmpty(request.SeriesId)) { var series = _libraryManager.GetItemById(request.SeriesId) as Series; @@ -100,7 +102,7 @@ namespace Emby.Server.Implementations.TV } } - if (!string.IsNullOrWhiteSpace(presentationUniqueKey)) + if (!string.IsNullOrEmpty(presentationUniqueKey)) { return GetResult(GetNextUpEpisodes(request, user, new[] { presentationUniqueKey }, dtoOptions), request); } @@ -113,7 +115,7 @@ namespace Emby.Server.Implementations.TV var items = _libraryManager.GetItemList(new InternalItemsQuery(user) { IncludeItemTypes = new[] { typeof(Episode).Name }, - OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.DatePlayed, SortOrder.Descending) }, + OrderBy = new[] { new ValueTuple<string, SortOrder>(ItemSortBy.DatePlayed, SortOrder.Descending) }, SeriesPresentationUniqueKey = presentationUniqueKey, Limit = limit, DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions @@ -126,7 +128,7 @@ namespace Emby.Server.Implementations.TV }, GroupBySeriesPresentationUniqueKey = true - }, parentsFolders).Cast<Episode>().Select(GetUniqueSeriesKey); + }, parentsFolders.ToList()).Cast<Episode>().Select(GetUniqueSeriesKey); // Avoid implicitly captured closure var episodes = GetNextUpEpisodes(request, user, items, dtoOptions); @@ -146,7 +148,7 @@ namespace Emby.Server.Implementations.TV // If viewing all next up for all series, remove first episodes // But if that returns empty, keep those first episodes (avoid completely empty view) - var alwaysEnableFirstEpisode = !string.IsNullOrWhiteSpace(request.SeriesId); + var alwaysEnableFirstEpisode = !string.IsNullOrEmpty(request.SeriesId); var anyFound = false; return allNextUp @@ -190,7 +192,7 @@ namespace Emby.Server.Implementations.TV AncestorWithPresentationUniqueKey = null, SeriesPresentationUniqueKey = seriesKey, IncludeItemTypes = new[] { typeof(Episode).Name }, - OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Descending) }, + OrderBy = new[] { new ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Descending) }, IsPlayed = true, Limit = 1, ParentIndexNumberNotEquals = 0, @@ -212,7 +214,7 @@ namespace Emby.Server.Implementations.TV AncestorWithPresentationUniqueKey = null, SeriesPresentationUniqueKey = seriesKey, IncludeItemTypes = new[] { typeof(Episode).Name }, - OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending) }, + OrderBy = new[] { new ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending) }, Limit = 1, IsPlayed = false, IsVirtualItem = false, |
