From 6ff89eab78a9d25fc8a8d195af558bf1c7ab4d8f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 22 Jun 2017 15:14:58 -0400 Subject: [PATCH 1/3] fixes #2588 - OpenSubtitlesDownloader doesn't respect X-Ratelimit-Requests-Remaining --- .../Extensions/ResourceNotFoundException.cs | 21 +++++++++++++++++++ .../Subtitles/OpenSubtitleDownloader.cs | 4 ++-- .../MediaInfo/SubtitleDownloader.cs | 6 +++++- .../Subtitles/SubtitleManager.cs | 7 ++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs b/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs index 403236b3d..86a974229 100644 --- a/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs +++ b/MediaBrowser.Common/Extensions/ResourceNotFoundException.cs @@ -25,4 +25,25 @@ namespace MediaBrowser.Common.Extensions } } + + public class RateLimitExceededException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public RateLimitExceededException() + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The message. + public RateLimitExceededException(string message) + : base(message) + { + + } + } } diff --git a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs index e26a6392c..3954897ca 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs @@ -136,7 +136,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles if ((DateTime.UtcNow - _lastRateLimitException).TotalHours < 1) { - throw new Exception("OpenSubtitles rate limit reached"); + throw new RateLimitExceededException("OpenSubtitles rate limit reached"); } var resultDownLoad = await OpenSubtitles.DownloadSubtitlesAsync(downloadsList, cancellationToken).ConfigureAwait(false); @@ -144,7 +144,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles if ((resultDownLoad.Status ?? string.Empty).IndexOf("407", StringComparison.OrdinalIgnoreCase) != -1) { _lastRateLimitException = DateTime.UtcNow; - throw new Exception("OpenSubtitles rate limit reached"); + throw new RateLimitExceededException("OpenSubtitles rate limit reached"); } if (!(resultDownLoad is MethodResponseSubtitleDownload)) diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs index b69e37136..483d8827e 100644 --- a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs +++ b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Providers.MediaInfo { @@ -139,7 +140,7 @@ namespace MediaBrowser.Providers.MediaInfo request.IndexNumberEnd = episode.IndexNumberEnd; request.SeriesName = episode.SeriesName; } - + try { var searchResults = await _subtitleManager.SearchSubtitles(request, cancellationToken).ConfigureAwait(false); @@ -154,6 +155,9 @@ namespace MediaBrowser.Providers.MediaInfo return true; } } + catch (RateLimitExceededException) + { + } catch (Exception ex) { _logger.ErrorException("Error downloading subtitles", ex); diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs index f7cd9dd13..be2ecf04a 100644 --- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs +++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs @@ -133,7 +133,8 @@ namespace MediaBrowser.Providers.Subtitles { //var isText = MediaStream.IsTextFormat(response.Format); - using (var fs = _fileSystem.GetFileStream(savePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true)) + using (var fs = _fileSystem.GetFileStream(savePath, FileOpenMode.Create, FileAccessMode.Write, + FileShareMode.Read, true)) { await stream.CopyToAsync(fs).ConfigureAwait(false); } @@ -154,6 +155,10 @@ namespace MediaBrowser.Providers.Subtitles } } } + catch (RateLimitExceededException) + { + throw; + } catch (Exception ex) { EventHelper.FireEventIfNotNull(SubtitleDownloadFailure, this, new SubtitleDownloadFailureEventArgs From 1e5c3db9eba730fe8b52995e5c699c22983fa62a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Jun 2017 12:04:45 -0400 Subject: [PATCH 2/3] support individual library refreshing --- .../ScheduledTasks/ScheduledTaskWorker.cs | 3 +- .../PlayedIndicatorDrawer.cs | 4 +- Emby.Drawing.Skia/PlayedIndicatorDrawer.cs | 3 +- .../Channels/ChannelManager.cs | 4 +- .../Channels/ChannelPostScanTask.cs | 2 +- .../Channels/RefreshChannelsScheduledTask.cs | 3 +- .../Emby.Server.Implementations.csproj | 1 - .../EntryPoints/LibraryChangedNotifier.cs | 116 +++++++++- .../IO/FileRefresher.cs | 4 +- .../Library/LibraryManager.cs | 40 ++-- .../Library/Validators/PeopleValidator.cs | 4 - .../Library/Validators/YearsPostScanTask.cs | 57 ----- .../LiveTv/EmbyTV/EmbyTV.cs | 4 +- .../LiveTv/Listings/XmlTvListingsProvider.cs | 3 +- .../LiveTv/LiveTvManager.cs | 6 +- .../News/NewsEntryPoint.cs | 3 +- .../Notifications/WebSocketNotifier.cs | 1 - .../ScheduledTasks/PluginUpdateTask.cs | 3 +- .../ScheduledTasks/SystemUpdateTask.cs | 5 +- .../Updates/InstallationManager.cs | 2 +- MediaBrowser.Api/ItemRefreshService.cs | 7 +- MediaBrowser.Api/Library/LibraryService.cs | 7 +- .../Library/LibraryStructureService.cs | 10 +- MediaBrowser.Api/PackageService.cs | 5 +- .../Progress/ActionableProgress.cs | 46 ++-- MediaBrowser.Controller/Channels/Channel.cs | 3 +- MediaBrowser.Controller/Dto/DtoOptions.cs | 3 +- .../Entities/Audio/MusicAlbum.cs | 2 - .../Entities/Audio/MusicArtist.cs | 2 - MediaBrowser.Controller/Entities/BaseItem.cs | 38 +++- .../Entities/CollectionFolder.cs | 30 +++ MediaBrowser.Controller/Entities/Folder.cs | 198 +++++++++++------- MediaBrowser.Controller/Entities/TV/Series.cs | 2 - .../Library/ILibraryManager.cs | 4 +- .../MediaBrowser.Controller.csproj | 1 - .../Providers/IProviderManager.cs | 19 +- .../Providers/ProviderRefreshStatus.cs | 22 -- .../Encoder/FontConfigLoader.cs | 3 +- .../Entities/VirtualFolderInfo.cs | 3 + MediaBrowser.Model/Querying/ItemFields.cs | 3 +- .../ImagesByName/ImageUtils.cs | 3 +- .../Manager/ProviderManager.cs | 99 ++++++++- .../TV/DummySeasonProvider.cs | 2 +- .../TV/MissingEpisodeProvider.cs | 4 +- 44 files changed, 523 insertions(+), 261 deletions(-) delete mode 100644 Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs delete mode 100644 MediaBrowser.Controller/Providers/ProviderRefreshStatus.cs diff --git a/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index ac1c55b6b..c373ffddb 100644 --- a/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.Events; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; @@ -402,7 +403,7 @@ namespace Emby.Common.Implementations.ScheduledTasks throw new InvalidOperationException("Cannot execute a Task that is already running"); } - var progress = new Progress(); + var progress = new SimpleProgress(); CurrentCancellationTokenSource = new CancellationTokenSource(); diff --git a/Emby.Drawing.ImageMagick/PlayedIndicatorDrawer.cs b/Emby.Drawing.ImageMagick/PlayedIndicatorDrawer.cs index 2ec58ff28..4dccca0c3 100644 --- a/Emby.Drawing.ImageMagick/PlayedIndicatorDrawer.cs +++ b/Emby.Drawing.ImageMagick/PlayedIndicatorDrawer.cs @@ -5,7 +5,7 @@ using MediaBrowser.Model.Drawing; using System; using System.IO; using System.Threading.Tasks; - +using MediaBrowser.Common.Progress; using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; @@ -104,7 +104,7 @@ namespace Emby.Drawing.ImageMagick var tempPath = await httpClient.GetTempFile(new HttpRequestOptions { Url = url, - Progress = new Progress() + Progress = new SimpleProgress() }).ConfigureAwait(false); diff --git a/Emby.Drawing.Skia/PlayedIndicatorDrawer.cs b/Emby.Drawing.Skia/PlayedIndicatorDrawer.cs index ad3b5226c..48f2da62b 100644 --- a/Emby.Drawing.Skia/PlayedIndicatorDrawer.cs +++ b/Emby.Drawing.Skia/PlayedIndicatorDrawer.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using System.Reflection; +using MediaBrowser.Common.Progress; namespace Emby.Drawing.Skia { @@ -99,7 +100,7 @@ namespace Emby.Drawing.Skia var tempPath = await httpClient.GetTempFile(new HttpRequestOptions { Url = url, - Progress = new Progress() + Progress = new SimpleProgress() }).ConfigureAwait(false); diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.cs index 73878160c..85f6c6667 100644 --- a/Emby.Server.Implementations/Channels/ChannelManager.cs +++ b/Emby.Server.Implementations/Channels/ChannelManager.cs @@ -23,7 +23,7 @@ using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; - +using MediaBrowser.Common.Progress; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; @@ -980,7 +980,7 @@ namespace Emby.Server.Implementations.Channels ? null : _userManager.GetUserById(query.UserId); - var internalResult = await GetChannelItemsInternal(query, new Progress(), cancellationToken).ConfigureAwait(false); + var internalResult = await GetChannelItemsInternal(query, new SimpleProgress(), cancellationToken).ConfigureAwait(false); var dtoOptions = new DtoOptions() { diff --git a/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs b/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs index aef06bd1d..ae31fcf3f 100644 --- a/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs +++ b/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs @@ -207,7 +207,7 @@ namespace Emby.Server.Implementations.Channels StartIndex = totalRetrieved, FolderId = folderId - }, new Progress(), cancellationToken); + }, new SimpleProgress(), cancellationToken); folderItems.AddRange(result.Items.Where(i => i.IsFolder).Select(i => i.Id.ToString("N"))); diff --git a/Emby.Server.Implementations/Channels/RefreshChannelsScheduledTask.cs b/Emby.Server.Implementations/Channels/RefreshChannelsScheduledTask.cs index d5ec86445..4a3301252 100644 --- a/Emby.Server.Implementations/Channels/RefreshChannelsScheduledTask.cs +++ b/Emby.Server.Implementations/Channels/RefreshChannelsScheduledTask.cs @@ -4,6 +4,7 @@ using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.Tasks; namespace Emby.Server.Implementations.Channels @@ -42,7 +43,7 @@ namespace Emby.Server.Implementations.Channels { var manager = (ChannelManager)_channelManager; - await manager.RefreshChannels(new Progress(), cancellationToken).ConfigureAwait(false); + await manager.RefreshChannels(new SimpleProgress(), cancellationToken).ConfigureAwait(false); await new ChannelPostScanTask(_channelManager, _userManager, _logger, _libraryManager).Run(progress, cancellationToken) .ConfigureAwait(false); diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 58d44d261..231ffe791 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -148,7 +148,6 @@ - diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 91142f928..23ae4cee9 100644 --- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -6,9 +6,14 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading; +using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Events; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Threading; @@ -49,13 +54,16 @@ namespace Emby.Server.Implementations.EntryPoints /// private const int LibraryUpdateDuration = 5000; - public LibraryChangedNotifier(ILibraryManager libraryManager, ISessionManager sessionManager, IUserManager userManager, ILogger logger, ITimerFactory timerFactory) + private readonly IProviderManager _providerManager; + + public LibraryChangedNotifier(ILibraryManager libraryManager, ISessionManager sessionManager, IUserManager userManager, ILogger logger, ITimerFactory timerFactory, IProviderManager providerManager) { _libraryManager = libraryManager; _sessionManager = sessionManager; _userManager = userManager; _logger = logger; _timerFactory = timerFactory; + _providerManager = providerManager; } public void Run() @@ -64,6 +72,108 @@ namespace Emby.Server.Implementations.EntryPoints _libraryManager.ItemUpdated += libraryManager_ItemUpdated; _libraryManager.ItemRemoved += libraryManager_ItemRemoved; + _providerManager.RefreshCompleted += _providerManager_RefreshCompleted; + _providerManager.RefreshStarted += _providerManager_RefreshStarted; + _providerManager.RefreshProgress += _providerManager_RefreshProgress; + } + + private Dictionary _lastProgressMessageTimes = new Dictionary(); + + private void _providerManager_RefreshProgress(object sender, GenericEventArgs> e) + { + var item = e.Argument.Item1; + + if (!EnableRefreshMessage(item)) + { + return; + } + + var progress = e.Argument.Item2; + + DateTime lastMessageSendTime; + if (_lastProgressMessageTimes.TryGetValue(item.Id, out lastMessageSendTime)) + { + if (progress > 0 && progress < 100 && (DateTime.UtcNow - lastMessageSendTime).TotalMilliseconds < 1000) + { + return; + } + } + + _lastProgressMessageTimes[item.Id] = DateTime.UtcNow; + + var dict = new Dictionary(); + dict["ItemId"] = item.Id.ToString("N"); + dict["Progress"] = progress.ToString(CultureInfo.InvariantCulture); + + try + { + _sessionManager.SendMessageToAdminSessions("RefreshProgress", dict, CancellationToken.None); + + _logger.Info("Sending refresh progress {0} {1}", item.Id.ToString("N"), progress); + } + catch + { + } + + var collectionFolders = _libraryManager.GetCollectionFolders(item).ToList(); + + foreach (var collectionFolder in collectionFolders) + { + var collectionFolderDict = new Dictionary(); + collectionFolderDict["ItemId"] = collectionFolder.Id.ToString("N"); + collectionFolderDict["Progress"] = (collectionFolder.GetRefreshProgress() ?? 0).ToString(CultureInfo.InvariantCulture); + + try + { + _sessionManager.SendMessageToAdminSessions("RefreshProgress", collectionFolderDict, CancellationToken.None); + } + catch + { + + } + } + } + + private void _providerManager_RefreshStarted(object sender, GenericEventArgs e) + { + _providerManager_RefreshProgress(sender, new GenericEventArgs>(new Tuple(e.Argument, 0))); + } + + private void _providerManager_RefreshCompleted(object sender, GenericEventArgs e) + { + _providerManager_RefreshProgress(sender, new GenericEventArgs>(new Tuple(e.Argument, 100))); + } + + private bool EnableRefreshMessage(BaseItem item) + { + var folder = item as Folder; + + if (folder == null) + { + return false; + } + + if (folder.IsRoot) + { + return false; + } + + if (folder is AggregateFolder || folder is UserRootFolder) + { + return false; + } + + if (folder is UserView || folder is Channel) + { + return false; + } + + if (!folder.IsTopParent) + { + return false; + } + + return true; } /// @@ -218,8 +328,8 @@ namespace Emby.Server.Implementations.EntryPoints try { - info = GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo, - foldersRemovedFrom, id); + info = GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo, + foldersRemovedFrom, id); } catch (Exception ex) { diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs index 9606b60b8..d4914e734 100644 --- a/Emby.Server.Implementations/IO/FileRefresher.cs +++ b/Emby.Server.Implementations/IO/FileRefresher.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.IO; using MediaBrowser.Common.Events; - +using MediaBrowser.Common.Progress; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; @@ -170,7 +170,7 @@ namespace Emby.Server.Implementations.IO // If the root folder changed, run the library task so the user can see it if (itemsToRefresh.Any(i => i is AggregateFolder)) { - LibraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + LibraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); return; } diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 15efd3d39..1a909549e 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -462,7 +462,7 @@ namespace Emby.Server.Implementations.Library if (parent != null) { - await parent.ValidateChildren(new Progress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false).ConfigureAwait(false); + await parent.ValidateChildren(new SimpleProgress(), CancellationToken.None, new MetadataRefreshOptions(_fileSystem), false).ConfigureAwait(false); } } else if (parent != null) @@ -1113,13 +1113,13 @@ namespace Emby.Server.Implementations.Library progress.Report(.5); // Start by just validating the children of the root, but go no further - await RootFolder.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false); + await RootFolder.ValidateChildren(new SimpleProgress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false); progress.Report(1); await GetUserRootFolder().RefreshMetadata(cancellationToken).ConfigureAwait(false); - await GetUserRootFolder().ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false).ConfigureAwait(false); + await GetUserRootFolder().ValidateChildren(new SimpleProgress(), cancellationToken, new MetadataRefreshOptions(_fileSystem), recursive: false).ConfigureAwait(false); progress.Report(2); // Quickly scan CollectionFolders for changes @@ -1204,25 +1204,24 @@ namespace Emby.Server.Implementations.Library /// Gets the default view. /// /// IEnumerable{VirtualFolderInfo}. - public IEnumerable GetVirtualFolders() + public List GetVirtualFolders() { - return GetView(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath); + return GetVirtualFolders(false); } - /// - /// Gets the view. - /// - /// The path. - /// IEnumerable{VirtualFolderInfo}. - private IEnumerable GetView(string path) + public List GetVirtualFolders(bool includeRefreshState) { var topLibraryFolders = GetUserRootFolder().Children.ToList(); - return _fileSystem.GetDirectoryPaths(path) - .Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders)); + var refreshQueue = includeRefreshState ? _providerManagerFactory().GetRefreshQueue() : null; + + return _fileSystem.GetDirectoryPaths(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath) + .Select(dir => GetVirtualFolderInfo(dir, topLibraryFolders, refreshQueue)) + .OrderBy(i => i.Name) + .ToList(); } - private VirtualFolderInfo GetVirtualFolderInfo(string dir, List allCollectionFolders) + private VirtualFolderInfo GetVirtualFolderInfo(string dir, List allCollectionFolders, Dictionary refreshQueue) { var info = new VirtualFolderInfo { @@ -1248,6 +1247,13 @@ namespace Emby.Server.Implementations.Library { info.ItemId = libraryFolder.Id.ToString("N"); info.LibraryOptions = GetLibraryOptions(libraryFolder); + + if (refreshQueue != null) + { + info.RefreshProgress = libraryFolder.GetRefreshProgress(); + + info.RefreshStatus = info.RefreshProgress.HasValue ? "Active" : refreshQueue.ContainsKey(libraryFolder.Id) ? "Queued" : "Idle"; + } } return info; @@ -2947,7 +2953,7 @@ namespace Emby.Server.Implementations.Library // No need to start if scanning the library because it will handle it if (refreshLibrary) { - ValidateMediaLibrary(new Progress(), CancellationToken.None); + ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { @@ -3075,7 +3081,7 @@ namespace Emby.Server.Implementations.Library private void SyncLibraryOptionsToLocations(string virtualFolderPath, LibraryOptions options) { var topLibraryFolders = GetUserRootFolder().Children.ToList(); - var info = GetVirtualFolderInfo(virtualFolderPath, topLibraryFolders); + var info = GetVirtualFolderInfo(virtualFolderPath, topLibraryFolders, null); if (info.Locations.Count > 0 && info.Locations.Count != options.PathInfos.Length) { @@ -3125,7 +3131,7 @@ namespace Emby.Server.Implementations.Library // No need to start if scanning the library because it will handle it if (refreshLibrary) { - ValidateMediaLibrary(new Progress(), CancellationToken.None); + ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { diff --git a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs index ef3b86abf..c2eb30ee4 100644 --- a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -55,10 +55,6 @@ namespace Emby.Server.Implementations.Library.Validators /// Task. public async Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) { - var innerProgress = new ActionableProgress(); - - innerProgress.RegisterAction(pct => progress.Report(pct * .15)); - var people = _libraryManager.GetPeople(new InternalPeopleQuery()); var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); diff --git a/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs b/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs deleted file mode 100644 index 4afb4c04a..000000000 --- a/Emby.Server.Implementations/Library/Validators/YearsPostScanTask.cs +++ /dev/null @@ -1,57 +0,0 @@ -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Logging; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Emby.Server.Implementations.Library.Validators -{ - public class YearsPostScanTask : ILibraryPostScanTask - { - private readonly ILibraryManager _libraryManager; - private readonly ILogger _logger; - - public YearsPostScanTask(ILibraryManager libraryManager, ILogger logger) - { - _libraryManager = libraryManager; - _logger = logger; - } - - public async Task Run(IProgress progress, CancellationToken cancellationToken) - { - var yearNumber = 1900; - var maxYear = DateTime.UtcNow.Year + 3; - var count = maxYear - yearNumber + 1; - var numComplete = 0; - - while (yearNumber < maxYear) - { - cancellationToken.ThrowIfCancellationRequested(); - - try - { - var year = _libraryManager.GetYear(yearNumber); - - await year.RefreshMetadata(cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - // Don't clutter the log - throw; - } - catch (Exception ex) - { - _logger.ErrorException("Error refreshing year {0}", ex, yearNumber); - } - - numComplete++; - double percent = numComplete; - percent /= count; - percent *= 100; - - progress.Report(percent); - yearNumber++; - } - } - } -} diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index a4c5b338e..b55e4412b 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -28,7 +28,7 @@ using System.Xml; using MediaBrowser.Model.IO; using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; - +using MediaBrowser.Common.Progress; using MediaBrowser.Controller; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; @@ -240,7 +240,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV if (requiresRefresh) { - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } } diff --git a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index b50f5ac92..9bf9f140d 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -15,6 +15,7 @@ using Emby.XmlTv.Classes; using Emby.XmlTv.Entities; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; +using MediaBrowser.Common.Progress; using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; @@ -75,7 +76,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings { CancellationToken = cancellationToken, Url = path, - Progress = new Progress(), + Progress = new SimpleProgress(), DecompressionMethod = CompressionMethod.Gzip, // It's going to come back gzipped regardless of this value diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index 69def362b..24afc03da 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1273,8 +1273,8 @@ namespace Emby.Server.Implementations.LiveTv if (coreService != null) { - await coreService.RefreshSeriesTimers(cancellationToken, new Progress()).ConfigureAwait(false); - await coreService.RefreshTimers(cancellationToken, new Progress()).ConfigureAwait(false); + await coreService.RefreshSeriesTimers(cancellationToken, new SimpleProgress()).ConfigureAwait(false); + await coreService.RefreshTimers(cancellationToken, new SimpleProgress()).ConfigureAwait(false); } // Load these now which will prefetch metadata @@ -1549,7 +1549,7 @@ namespace Emby.Server.Implementations.LiveTv var idList = await Task.WhenAll(recordingTasks).ConfigureAwait(false); - await CleanDatabaseInternal(idList.ToList(), new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new Progress(), cancellationToken).ConfigureAwait(false); + await CleanDatabaseInternal(idList.ToList(), new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new SimpleProgress(), cancellationToken).ConfigureAwait(false); _lastRecordingRefreshTime = DateTime.UtcNow; } diff --git a/Emby.Server.Implementations/News/NewsEntryPoint.cs b/Emby.Server.Implementations/News/NewsEntryPoint.cs index 53c862d47..3c9a3bbf1 100644 --- a/Emby.Server.Implementations/News/NewsEntryPoint.cs +++ b/Emby.Server.Implementations/News/NewsEntryPoint.cs @@ -15,6 +15,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Xml; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.IO; using MediaBrowser.Model.Threading; @@ -82,7 +83,7 @@ namespace Emby.Server.Implementations.News var requestOptions = new HttpRequestOptions { Url = "http://emby.media/community/index.php?/blog/rss/1-media-browser-developers-blog", - Progress = new Progress(), + Progress = new SimpleProgress(), UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.42 Safari/537.36", BufferContent = false }; diff --git a/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs b/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs index 8b3367217..0239ee336 100644 --- a/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs +++ b/Emby.Server.Implementations/Notifications/WebSocketNotifier.cs @@ -23,7 +23,6 @@ namespace Emby.Server.Implementations.Notifications public void Run() { _notificationsRepo.NotificationAdded += _notificationsRepo_NotificationAdded; - _notificationsRepo.NotificationsMarkedRead += _notificationsRepo_NotificationsMarkedRead; } diff --git a/Emby.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs index e619b6864..9f887ba03 100644 --- a/Emby.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.Tasks; namespace Emby.Server.Implementations.ScheduledTasks @@ -77,7 +78,7 @@ namespace Emby.Server.Implementations.ScheduledTasks try { - await _installationManager.InstallPackage(i, true, new Progress(), cancellationToken).ConfigureAwait(false); + await _installationManager.InstallPackage(i, true, new SimpleProgress(), cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { diff --git a/Emby.Server.Implementations/ScheduledTasks/SystemUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/SystemUpdateTask.cs index 28fd8b68c..a41e21a4b 100644 --- a/Emby.Server.Implementations/ScheduledTasks/SystemUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/SystemUpdateTask.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.Tasks; namespace Emby.Server.Implementations.ScheduledTasks @@ -70,7 +71,7 @@ namespace Emby.Server.Implementations.ScheduledTasks EventHandler innerProgressHandler = (sender, e) => progress.Report(e * .1); // Create a progress object for the update check - var innerProgress = new Progress(); + var innerProgress = new SimpleProgress(); innerProgress.ProgressChanged += innerProgressHandler; var updateInfo = await _appHost.CheckForApplicationUpdate(cancellationToken, innerProgress).ConfigureAwait(false); @@ -97,7 +98,7 @@ namespace Emby.Server.Implementations.ScheduledTasks innerProgressHandler = (sender, e) => progress.Report(e * .9 + .1); - innerProgress = new Progress(); + innerProgress = new SimpleProgress(); innerProgress.ProgressChanged += innerProgressHandler; await _appHost.UpdateApplication(updateInfo.Package, cancellationToken, innerProgress).ConfigureAwait(false); diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index eed17fb66..717416da1 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -246,7 +246,7 @@ namespace Emby.Server.Implementations.Updates { Url = "https://www.mb3admin.com/admin/service/MB3Packages.json", CancellationToken = cancellationToken, - Progress = new Progress() + Progress = new SimpleProgress() }).ConfigureAwait(false); diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 534089848..d26fb768a 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -65,7 +65,7 @@ namespace MediaBrowser.Api _providerManager.QueueRefresh(item.Id, options, RefreshPriority.High); } - private MetadataRefreshOptions GetRefreshOptions(BaseRefreshRequest request) + private MetadataRefreshOptions GetRefreshOptions(RefreshItem request) { return new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)) { @@ -73,8 +73,9 @@ namespace MediaBrowser.Api ImageRefreshMode = request.ImageRefreshMode, ReplaceAllImages = request.ReplaceAllImages, ReplaceAllMetadata = request.ReplaceAllMetadata, - ForceSave = true, - IsAutomated = false + ForceSave = request.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || request.ImageRefreshMode == ImageRefreshMode.FullRefresh || request.ReplaceAllImages || request.ReplaceAllMetadata, + IsAutomated = false, + ValidateChildren = request.Recursive }; } } diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index d9fc7143f..80d8c072e 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -28,6 +28,7 @@ using MediaBrowser.Controller.IO; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Services; using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Progress; namespace MediaBrowser.Api.Library { @@ -445,7 +446,7 @@ namespace MediaBrowser.Api.Library } else { - Task.Run(() => _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None)); + Task.Run(() => _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None)); } } @@ -483,7 +484,7 @@ namespace MediaBrowser.Api.Library } else { - Task.Run(() => _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None)); + Task.Run(() => _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None)); } } @@ -696,7 +697,7 @@ namespace MediaBrowser.Api.Library { try { - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } catch (Exception ex) { diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index 8e396ff57..ae488f066 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -8,7 +8,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; - +using MediaBrowser.Common.Progress; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; @@ -208,7 +208,7 @@ namespace MediaBrowser.Api.Library /// System.Object. public object Get(GetVirtualFolders request) { - var result = _libraryManager.GetVirtualFolders().OrderBy(i => i.Name).ToList(); + var result = _libraryManager.GetVirtualFolders(true); return ToOptimizedSerializedResultUsingCache(result); } @@ -290,7 +290,7 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (request.RefreshLibrary) { - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { @@ -347,7 +347,7 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (request.RefreshLibrary) { - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { @@ -400,7 +400,7 @@ namespace MediaBrowser.Api.Library // No need to start if scanning the library because it will handle it if (request.RefreshLibrary) { - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None); + _libraryManager.ValidateMediaLibrary(new SimpleProgress(), CancellationToken.None); } else { diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index 125cec681..64424795f 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.Services; namespace MediaBrowser.Api @@ -156,7 +157,7 @@ namespace MediaBrowser.Api else if (string.Equals(request.PackageType, "System", StringComparison.OrdinalIgnoreCase) || string.Equals(request.PackageType, "All", StringComparison.OrdinalIgnoreCase)) { - var updateCheckResult = _appHost.CheckForApplicationUpdate(CancellationToken.None, new Progress()).Result; + var updateCheckResult = _appHost.CheckForApplicationUpdate(CancellationToken.None, new SimpleProgress()).Result; if (updateCheckResult.IsUpdateAvailable) { @@ -233,7 +234,7 @@ namespace MediaBrowser.Api throw new ResourceNotFoundException(string.Format("Package not found: {0}", request.Name)); } - Task.Run(() => _installationManager.InstallPackage(package, true, new Progress(), CancellationToken.None)); + Task.Run(() => _installationManager.InstallPackage(package, true, new SimpleProgress(), CancellationToken.None)); } /// diff --git a/MediaBrowser.Common/Progress/ActionableProgress.cs b/MediaBrowser.Common/Progress/ActionableProgress.cs index 39f46ce05..503f3f407 100644 --- a/MediaBrowser.Common/Progress/ActionableProgress.cs +++ b/MediaBrowser.Common/Progress/ActionableProgress.cs @@ -7,12 +7,13 @@ namespace MediaBrowser.Common.Progress /// Class ActionableProgress /// /// - public class ActionableProgress : Progress, IDisposable + public class ActionableProgress : IProgress, IDisposable { /// /// The _actions /// private readonly List> _actions = new List>(); + public event EventHandler ProgressChanged; /// /// Registers the action. @@ -21,22 +22,6 @@ namespace MediaBrowser.Common.Progress public void RegisterAction(Action action) { _actions.Add(action); - - ProgressChanged -= ActionableProgress_ProgressChanged; - ProgressChanged += ActionableProgress_ProgressChanged; - } - - /// - /// Actionables the progress_ progress changed. - /// - /// The sender. - /// The e. - void ActionableProgress_ProgressChanged(object sender, T e) - { - foreach (var action in _actions) - { - action(e); - } } /// @@ -55,9 +40,34 @@ namespace MediaBrowser.Common.Progress { if (disposing) { - ProgressChanged -= ActionableProgress_ProgressChanged; _actions.Clear(); } } + + public void Report(T value) + { + if (ProgressChanged != null) + { + ProgressChanged(this, value); + } + + foreach (var action in _actions) + { + action(value); + } + } + } + + public class SimpleProgress : IProgress + { + public event EventHandler ProgressChanged; + + public void Report(T value) + { + if (ProgressChanged != null) + { + ProgressChanged(this, value); + } + } } } diff --git a/MediaBrowser.Controller/Channels/Channel.cs b/MediaBrowser.Controller/Channels/Channel.cs index 862c8e5ac..8e2faa20e 100644 --- a/MediaBrowser.Controller/Channels/Channel.cs +++ b/MediaBrowser.Controller/Channels/Channel.cs @@ -6,6 +6,7 @@ using System.Linq; using MediaBrowser.Model.Serialization; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; namespace MediaBrowser.Controller.Channels { @@ -51,7 +52,7 @@ namespace MediaBrowser.Controller.Channels SortBy = query.SortBy, SortOrder = query.SortOrder - }, new Progress(), CancellationToken.None).Result; + }, new SimpleProgress(), CancellationToken.None).Result; } catch { diff --git a/MediaBrowser.Controller/Dto/DtoOptions.cs b/MediaBrowser.Controller/Dto/DtoOptions.cs index b9d9d7dda..098ba558f 100644 --- a/MediaBrowser.Controller/Dto/DtoOptions.cs +++ b/MediaBrowser.Controller/Dto/DtoOptions.cs @@ -10,7 +10,8 @@ namespace MediaBrowser.Controller.Dto { private static readonly List DefaultExcludedFields = new List { - ItemFields.SeasonUserData + ItemFields.SeasonUserData, + ItemFields.RefreshState }; public List Fields { get; set; } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index e9eca19cf..516ab5053 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -235,8 +235,6 @@ namespace MediaBrowser.Controller.Entities.Audio { await RefreshArtists(refreshOptions, cancellationToken).ConfigureAwait(false); } - - progress.Report(100); } private async Task RefreshArtists(MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken) diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index 4b232de49..ebd83205e 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -250,8 +250,6 @@ namespace MediaBrowser.Controller.Entities.Audio percent /= totalItems; progress.Report(percent * 100); } - - progress.Report(100); } public ArtistInfo GetLookupInfo() diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 4efea94d8..b4a3d89ea 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1058,6 +1058,16 @@ namespace MediaBrowser.Controller.Entities return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)), cancellationToken); } + protected virtual void TriggerOnRefreshStart() + { + + } + + protected virtual void TriggerOnRefreshComplete() + { + + } + /// /// Overrides the base implementation to refresh metadata for local trailers /// @@ -1066,6 +1076,8 @@ namespace MediaBrowser.Controller.Entities /// true if a provider reports we changed public async Task RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken) { + TriggerOnRefreshStart(); + var locationType = LocationType; var requiresSave = false; @@ -1091,14 +1103,21 @@ namespace MediaBrowser.Controller.Entities } } - var refreshOptions = requiresSave - ? new MetadataRefreshOptions(options) - { - ForceSave = true - } - : options; + try + { + var refreshOptions = requiresSave + ? new MetadataRefreshOptions(options) + { + ForceSave = true + } + : options; - return await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false); + return await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false); + } + finally + { + TriggerOnRefreshComplete(); + } } [IgnoreDataMember] @@ -2421,5 +2440,10 @@ namespace MediaBrowser.Controller.Entities { return new List(); } + + public virtual double? GetRefreshProgress() + { + return null; + } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 8bc23a581..0bd8606b9 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; @@ -199,6 +200,30 @@ namespace MediaBrowser.Controller.Entities return changed; } + public override double? GetRefreshProgress() + { + var folders = GetPhysicalFolders(true).ToList(); + double totalProgresses = 0; + var foldersWithProgress = 0; + + foreach (var folder in folders) + { + var progress = ProviderManager.GetRefreshProgress(folder.Id); + if (progress.HasValue) + { + totalProgresses += progress.Value; + foldersWithProgress++; + } + } + + if (foldersWithProgress == 0) + { + return null; + } + + return (totalProgresses / foldersWithProgress); + } + protected override bool RefreshLinkedChildren(IEnumerable fileSystemChildren) { return RefreshLinkedChildrenInternal(true); @@ -321,6 +346,11 @@ namespace MediaBrowser.Controller.Entities return GetPhysicalFolders(true).SelectMany(c => c.Children); } + public IEnumerable GetPhysicalFolders() + { + return GetPhysicalFolders(true); + } + private IEnumerable GetPhysicalFolders(bool enableCache) { if (enableCache) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 727b7dbeb..34b33fde0 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -271,6 +271,11 @@ namespace MediaBrowser.Controller.Entities return GetCachedChildren(); } + public override double? GetRefreshProgress() + { + return ProviderManager.GetRefreshProgress(Id); + } + public Task ValidateChildren(IProgress progress, CancellationToken cancellationToken) { return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem))); @@ -318,6 +323,14 @@ namespace MediaBrowser.Controller.Entities return current.IsValidFromResolver(newItem); } + protected override void TriggerOnRefreshStart() + { + } + + protected override void TriggerOnRefreshComplete() + { + } + /// /// Validates the children internal. /// @@ -328,7 +341,27 @@ namespace MediaBrowser.Controller.Entities /// The refresh options. /// The directory service. /// Task. - protected async virtual Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) + protected virtual async Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) + { + if (recursive) + { + ProviderManager.OnRefreshStart(this); + } + + try + { + await ValidateChildrenInternal2(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService).ConfigureAwait(false); + } + finally + { + if (recursive) + { + ProviderManager.OnRefreshComplete(this); + } + } + } + + private async Task ValidateChildrenInternal2(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) { var locationType = LocationType; @@ -360,6 +393,11 @@ namespace MediaBrowser.Controller.Entities progress.Report(5); + if (recursive) + { + ProviderManager.OnRefreshProgress(this, 5); + } + //build a dictionary of the current children we have now by Id so we can compare quickly and easily var currentChildren = GetActualChildrenDictionary(); @@ -424,76 +462,99 @@ namespace MediaBrowser.Controller.Entities await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false); } } + else + { + if (recursive || refreshChildMetadata) + { + // used below + validChildren = Children.ToList(); + } + } progress.Report(10); + if (recursive) + { + ProviderManager.OnRefreshProgress(this, 10); + } + cancellationToken.ThrowIfCancellationRequested(); if (recursive) { - await ValidateSubFolders(Children.ToList().OfType().ToList(), directoryService, progress, cancellationToken).ConfigureAwait(false); - } + using (var innerProgress = new ActionableProgress()) + { + var folder = this; + innerProgress.RegisterAction(p => + { + double newPct = .70 * p + 10; + progress.Report(newPct); + ProviderManager.OnRefreshProgress(folder, newPct); + }); - progress.Report(20); + await ValidateSubFolders(validChildren.OfType().ToList(), directoryService, innerProgress, cancellationToken).ConfigureAwait(false); + } + } if (refreshChildMetadata) { + progress.Report(80); + + if (recursive) + { + ProviderManager.OnRefreshProgress(this, 80); + } + var container = this as IMetadataContainer; - var innerProgress = new ActionableProgress(); - - innerProgress.RegisterAction(p => progress.Report(.80 * p + 20)); - - if (container != null) + using (var innerProgress = new ActionableProgress()) { - await container.RefreshAllMetadata(refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false); - } - else - { - await RefreshMetadataRecursive(refreshOptions, recursive, innerProgress, cancellationToken); + var folder = this; + innerProgress.RegisterAction(p => + { + double newPct = .20 * p + 80; + progress.Report(newPct); + if (recursive) + { + ProviderManager.OnRefreshProgress(folder, newPct); + } + }); + + if (container != null) + { + await container.RefreshAllMetadata(refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false); + } + else + { + await RefreshMetadataRecursive(validChildren, refreshOptions, recursive, innerProgress, cancellationToken); + } } } - - progress.Report(100); } - private async Task RefreshMetadataRecursive(MetadataRefreshOptions refreshOptions, bool recursive, IProgress progress, CancellationToken cancellationToken) + private async Task RefreshMetadataRecursive(List children, MetadataRefreshOptions refreshOptions, bool recursive, IProgress progress, CancellationToken cancellationToken) { - var children = Children.ToList(); - - var percentages = new Dictionary(children.Count); var numComplete = 0; var count = children.Count; + double currentPercent = 0; foreach (var child in children) { cancellationToken.ThrowIfCancellationRequested(); - if (child.IsFolder) + using (var innerProgress = new ActionableProgress()) { - var innerProgress = new ActionableProgress(); - // Avoid implicitly captured closure - var currentChild = child; + var currentInnerPercent = currentPercent; + innerProgress.RegisterAction(p => { - lock (percentages) - { - percentages[currentChild.Id] = p / 100; - - var innerPercent = percentages.Values.Sum(); - innerPercent /= count; - innerPercent *= 100; - progress.Report(innerPercent); - } + double innerPercent = currentInnerPercent; + innerPercent += p / (count); + progress.Report(innerPercent); }); - await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken) - .ConfigureAwait(false); - } - else - { - await RefreshChildMetadata(child, refreshOptions, false, new Progress(), cancellationToken) + await RefreshChildMetadata(child, refreshOptions, recursive && child.IsFolder, innerProgress, cancellationToken) .ConfigureAwait(false); } @@ -501,11 +562,10 @@ namespace MediaBrowser.Controller.Entities double percent = numComplete; percent /= count; percent *= 100; + currentPercent = percent; progress.Report(percent); } - - progress.Report(100); } private async Task RefreshChildMetadata(BaseItem child, MetadataRefreshOptions refreshOptions, bool recursive, IProgress progress, CancellationToken cancellationToken) @@ -526,11 +586,10 @@ namespace MediaBrowser.Controller.Entities if (folder != null) { - await folder.RefreshMetadataRecursive(refreshOptions, true, progress, cancellationToken); + await folder.RefreshMetadataRecursive(folder.Children.ToList(), refreshOptions, true, progress, cancellationToken); } } } - progress.Report(100); } /// @@ -543,47 +602,40 @@ namespace MediaBrowser.Controller.Entities /// Task. private async Task ValidateSubFolders(IList children, IDirectoryService directoryService, IProgress progress, CancellationToken cancellationToken) { - var list = children; - var childCount = list.Count; + var numComplete = 0; + var count = children.Count; + double currentPercent = 0; - var percentages = new Dictionary(list.Count); - - foreach (var item in list) + foreach (var child in children) { cancellationToken.ThrowIfCancellationRequested(); - var child = item; - - var innerProgress = new ActionableProgress(); - - innerProgress.RegisterAction(p => + using (var innerProgress = new ActionableProgress()) { - lock (percentages) + // Avoid implicitly captured closure + var currentInnerPercent = currentPercent; + + innerProgress.RegisterAction(p => { - percentages[child.Id] = p / 100; + double innerPercent = currentInnerPercent; + innerPercent += p / (count); + progress.Report(innerPercent); + }); - var percent = percentages.Values.Sum(); - percent /= childCount; + await child.ValidateChildrenInternal(innerProgress, cancellationToken, true, false, null, directoryService) + .ConfigureAwait(false); + } - progress.Report(10 * percent + 10); - } - }); + numComplete++; + double percent = numComplete; + percent /= count; + percent *= 100; + currentPercent = percent; - await child.ValidateChildrenInternal(innerProgress, cancellationToken, true, false, null, directoryService) - .ConfigureAwait(false); + progress.Report(percent); } } - /// - /// Determines whether the specified path is offline. - /// - /// The path. - /// true if the specified path is offline; otherwise, false. - public static bool IsPathOffline(string path) - { - return IsPathOffline(path, LibraryManager.GetVirtualFolders().SelectMany(i => i.Locations).ToList()); - } - public static bool IsPathOffline(string path, List allLibraryPaths) { if (FileSystem.FileExists(path)) @@ -926,7 +978,7 @@ namespace MediaBrowser.Controller.Entities SortBy = query.SortBy, SortOrder = query.SortOrder - }, new Progress(), CancellationToken.None).Result; + }, new SimpleProgress(), CancellationToken.None).Result; } catch { diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index 0b9662450..1e4b3fdad 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -414,8 +414,6 @@ namespace MediaBrowser.Controller.Entities.TV refreshOptions = new MetadataRefreshOptions(refreshOptions); refreshOptions.IsPostRecursiveRefresh = true; await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false); - - progress.Report(100); } public IEnumerable GetSeasonEpisodes(Season parentSeason, User user, DtoOptions options) diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 5a702b4f0..b726c267c 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -132,7 +132,9 @@ namespace MediaBrowser.Controller.Library /// Gets the default view. /// /// IEnumerable{VirtualFolderInfo}. - IEnumerable GetVirtualFolders(); + List GetVirtualFolders(); + + List GetVirtualFolders(bool includeRefreshState); /// /// Gets the item by id. diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 348cfd343..22f94695d 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -320,7 +320,6 @@ - diff --git a/MediaBrowser.Controller/Providers/IProviderManager.cs b/MediaBrowser.Controller/Providers/IProviderManager.cs index c0bc90214..0ba573da8 100644 --- a/MediaBrowser.Controller/Providers/IProviderManager.cs +++ b/MediaBrowser.Controller/Providers/IProviderManager.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Events; namespace MediaBrowser.Controller.Providers { @@ -30,7 +31,7 @@ namespace MediaBrowser.Controller.Providers /// The cancellation token. /// Task. Task RefreshFullItem(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken); - + /// /// Refreshes the metadata. /// @@ -68,7 +69,7 @@ namespace MediaBrowser.Controller.Providers /// /// Task. Task SaveImage(IHasImages item, string source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken); - + /// /// Adds the metadata providers. /// @@ -128,7 +129,7 @@ namespace MediaBrowser.Controller.Providers /// The savers. /// Task. Task SaveMetadata(IHasMetadata item, ItemUpdateType updateType, IEnumerable savers); - + /// /// Gets the metadata options. /// @@ -158,6 +159,18 @@ namespace MediaBrowser.Controller.Providers /// The cancellation token. /// Task{HttpResponseInfo}. Task GetSearchImage(string providerName, string url, CancellationToken cancellationToken); + + Dictionary GetRefreshQueue(); + + void OnRefreshStart(BaseItem item); + void OnRefreshProgress(BaseItem item, double progress); + void OnRefreshComplete(BaseItem item); + + double? GetRefreshProgress(Guid id); + + event EventHandler> RefreshStarted; + event EventHandler> RefreshCompleted; + event EventHandler>> RefreshProgress; } public enum RefreshPriority diff --git a/MediaBrowser.Controller/Providers/ProviderRefreshStatus.cs b/MediaBrowser.Controller/Providers/ProviderRefreshStatus.cs deleted file mode 100644 index 6523dc417..000000000 --- a/MediaBrowser.Controller/Providers/ProviderRefreshStatus.cs +++ /dev/null @@ -1,22 +0,0 @@ - -namespace MediaBrowser.Controller.Providers -{ - /// - /// Enum ProviderRefreshStatus - /// - public enum ProviderRefreshStatus - { - /// - /// The success - /// - Success = 0, - /// - /// The completed with errors - /// - CompletedWithErrors = 1, - /// - /// The failure - /// - Failure = 2 - } -} diff --git a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs b/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs index 1b5b4b4e4..e21292cbd 100644 --- a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs +++ b/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs @@ -7,6 +7,7 @@ using MediaBrowser.Model.IO; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; +using MediaBrowser.Common.Progress; using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; @@ -62,7 +63,7 @@ namespace MediaBrowser.MediaEncoding.Encoder // Kick this off, but no need to wait on it var task = Task.Run(async () => { - await DownloadFontFile(fontsDirectory, fontFilename, new Progress()).ConfigureAwait(false); + await DownloadFontFile(fontsDirectory, fontFilename, new SimpleProgress()).ConfigureAwait(false); await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false); }); diff --git a/MediaBrowser.Model/Entities/VirtualFolderInfo.cs b/MediaBrowser.Model/Entities/VirtualFolderInfo.cs index d8ec04ff6..374d8d028 100644 --- a/MediaBrowser.Model/Entities/VirtualFolderInfo.cs +++ b/MediaBrowser.Model/Entities/VirtualFolderInfo.cs @@ -47,5 +47,8 @@ namespace MediaBrowser.Model.Entities /// /// The primary image item identifier. public string PrimaryImageItemId { get; set; } + + public double? RefreshProgress { get; set; } + public string RefreshStatus { get; set; } } } diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index 5873293f7..c6f34d58a 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -228,6 +228,7 @@ ExternalSeriesId, SeriesPresentationUniqueKey, DateLastRefreshed, - DateLastSaved + DateLastSaved, + RefreshState } } diff --git a/MediaBrowser.Providers/ImagesByName/ImageUtils.cs b/MediaBrowser.Providers/ImagesByName/ImageUtils.cs index 566378dd0..499fd2e0b 100644 --- a/MediaBrowser.Providers/ImagesByName/ImageUtils.cs +++ b/MediaBrowser.Providers/ImagesByName/ImageUtils.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.IO; namespace MediaBrowser.Providers.ImagesByName @@ -30,7 +31,7 @@ namespace MediaBrowser.Providers.ImagesByName var temp = await httpClient.GetTempFile(new HttpRequestOptions { CancellationToken = cancellationToken, - Progress = new Progress(), + Progress = new SimpleProgress(), Url = url }).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 3cdda2cbb..ce995fe64 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -18,8 +18,10 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Progress; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Dto; +using MediaBrowser.Model.Events; using MediaBrowser.Model.Serialization; using Priority_Queue; @@ -67,6 +69,10 @@ namespace MediaBrowser.Providers.Manager private readonly IMemoryStreamFactory _memoryStreamProvider; private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource(); + public event EventHandler> RefreshStarted; + public event EventHandler> RefreshCompleted; + public event EventHandler>> RefreshProgress; + /// /// Initializes a new instance of the class. /// @@ -849,6 +855,89 @@ namespace MediaBrowser.Providers.Manager }); } + private Dictionary _activeRefreshes = new Dictionary(); + + public Dictionary GetRefreshQueue() + { + lock (_refreshQueueLock) + { + var dict = new Dictionary(); + + foreach (var item in _refreshQueue) + { + dict[item.Item1] = item.Item1; + } + return dict; + } + } + + public void OnRefreshStart(BaseItem item) + { + //_logger.Info("OnRefreshStart {0}", item.Id.ToString("N")); + var id = item.Id; + + lock (_activeRefreshes) + { + _activeRefreshes[id] = 0; + } + + if (RefreshStarted != null) + { + RefreshStarted(this, new GenericEventArgs(item)); + } + } + + public void OnRefreshComplete(BaseItem item) + { + //_logger.Info("OnRefreshComplete {0}", item.Id.ToString("N")); + lock (_activeRefreshes) + { + _activeRefreshes.Remove(item.Id); + } + + if (RefreshCompleted != null) + { + RefreshCompleted(this, new GenericEventArgs(item)); + } + } + + public double? GetRefreshProgress(Guid id) + { + lock (_activeRefreshes) + { + double value; + if (_activeRefreshes.TryGetValue(id, out value)) + { + return value; + } + + return null; + } + } + + public void OnRefreshProgress(BaseItem item, double progress) + { + //_logger.Info("OnRefreshProgress {0} {1}", item.Id.ToString("N"), progress); + var id = item.Id; + + lock (_activeRefreshes) + { + if (_activeRefreshes.ContainsKey(id)) + { + _activeRefreshes[id] = progress; + + if (RefreshProgress != null) + { + RefreshProgress(this, new GenericEventArgs>(new Tuple(item, progress))); + } + } + else + { + throw new Exception(string.Format("Refresh for item {0} {1} is not in progress", item.GetType().Name, item.Id.ToString("N"))); + } + } + } + private readonly SimplePriorityQueue> _refreshQueue = new SimplePriorityQueue>(); @@ -906,7 +995,7 @@ namespace MediaBrowser.Providers.Manager var folder = item as Folder; if (folder != null) { - await folder.ValidateChildren(new Progress(), cancellationToken).ConfigureAwait(false); + await folder.ValidateChildren(new SimpleProgress(), cancellationToken).ConfigureAwait(false); } } @@ -951,14 +1040,14 @@ namespace MediaBrowser.Providers.Manager if (folder != null) { - await folder.ValidateChildren(new Progress(), cancellationToken, options).ConfigureAwait(false); + await folder.ValidateChildren(new SimpleProgress(), cancellationToken, options).ConfigureAwait(false); } } } private async Task RefreshCollectionFolderChildren(MetadataRefreshOptions options, CollectionFolder collectionFolder, CancellationToken cancellationToken) { - foreach (var child in collectionFolder.Children.ToList()) + foreach (var child in collectionFolder.GetPhysicalFolders().ToList()) { await child.RefreshMetadata(options, cancellationToken).ConfigureAwait(false); @@ -966,7 +1055,7 @@ namespace MediaBrowser.Providers.Manager { var folder = (Folder)child; - await folder.ValidateChildren(new Progress(), cancellationToken, options, true).ConfigureAwait(false); + await folder.ValidateChildren(new SimpleProgress(), cancellationToken, options, true).ConfigureAwait(false); } } } @@ -991,7 +1080,7 @@ namespace MediaBrowser.Providers.Manager .Where(i => i != null) .ToList(); - var musicArtistRefreshTasks = musicArtists.Select(i => i.ValidateChildren(new Progress(), cancellationToken, options, true)); + var musicArtistRefreshTasks = musicArtists.Select(i => i.ValidateChildren(new SimpleProgress(), cancellationToken, options, true)); await Task.WhenAll(musicArtistRefreshTasks).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/TV/DummySeasonProvider.cs b/MediaBrowser.Providers/TV/DummySeasonProvider.cs index 3b2d674a6..aef29abbe 100644 --- a/MediaBrowser.Providers/TV/DummySeasonProvider.cs +++ b/MediaBrowser.Providers/TV/DummySeasonProvider.cs @@ -46,7 +46,7 @@ namespace MediaBrowser.Providers.TV //await series.RefreshMetadata(new MetadataRefreshOptions(directoryService), cancellationToken).ConfigureAwait(false); - //await series.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(directoryService)) + //await series.ValidateChildren(new SimpleProgress(), cancellationToken, new MetadataRefreshOptions(directoryService)) // .ConfigureAwait(false); } } diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index da5a1f2d1..51ad12364 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -13,7 +13,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml; - +using MediaBrowser.Common.Progress; using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using MediaBrowser.Model.Globalization; @@ -162,7 +162,7 @@ namespace MediaBrowser.Providers.TV await series.RefreshMetadata(new MetadataRefreshOptions(directoryService), cancellationToken).ConfigureAwait(false); - await series.ValidateChildren(new Progress(), cancellationToken, new MetadataRefreshOptions(directoryService), true) + await series.ValidateChildren(new SimpleProgress(), cancellationToken, new MetadataRefreshOptions(directoryService), true) .ConfigureAwait(false); } } From 023952d04df3765ee5574915f0a84903bb97a748 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Jun 2017 12:07:32 -0400 Subject: [PATCH 3/3] 3.2.20.11 --- Emby.Server.Implementations/Dto/DtoService.cs | 24 +++++++++++++++---- SharedVersion.cs | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 7352073bd..52ebd5e30 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -105,9 +105,13 @@ namespace Emby.Server.Implementations.Dto var programTuples = new List>(); var channelTuples = new List>(); + var refreshQueue = options.Fields.Contains(ItemFields.RefreshState) + ? _providerManager.GetRefreshQueue() + : null; + foreach (var item in items) { - var dto = GetBaseItemDtoInternal(item, options, user, owner); + var dto = GetBaseItemDtoInternal(item, options, refreshQueue, user, owner); var tvChannel = item as LiveTvChannel; if (tvChannel != null) @@ -160,7 +164,11 @@ namespace Emby.Server.Implementations.Dto { var syncDictionary = GetSyncedItemProgress(options); - var dto = GetBaseItemDtoInternal(item, options, user, owner); + var refreshQueue = options.Fields.Contains(ItemFields.RefreshState) + ? _providerManager.GetRefreshQueue() + : null; + + var dto = GetBaseItemDtoInternal(item, options, refreshQueue, user, owner); var tvChannel = item as LiveTvChannel; if (tvChannel != null) { @@ -292,7 +300,7 @@ namespace Emby.Server.Implementations.Dto } } - private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null) + private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, Dictionary currentRefreshQueue, User user = null, BaseItem owner = null) { var fields = options.Fields; @@ -392,6 +400,11 @@ namespace Emby.Server.Implementations.Dto dto.Etag = item.GetEtag(user); } + if (currentRefreshQueue != null) + { + //dto.RefreshState = item.GetRefreshState(currentRefreshQueue); + } + if (item is ILiveTvRecording) { _livetvManager().AddInfoToRecordingDto(item, dto, user); @@ -402,7 +415,10 @@ namespace Emby.Server.Implementations.Dto public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List taggedItems, Dictionary syncProgress, User user = null) { - var dto = GetBaseItemDtoInternal(item, options, user); + var refreshQueue = options.Fields.Contains(ItemFields.RefreshState) + ? _providerManager.GetRefreshQueue() + : null; + var dto = GetBaseItemDtoInternal(item, options, refreshQueue, user); if (taggedItems != null && options.Fields.Contains(ItemFields.ItemCounts)) { diff --git a/SharedVersion.cs b/SharedVersion.cs index 7df961c8d..ec801ba7f 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,3 +1,3 @@ using System.Reflection; -[assembly: AssemblyVersion("3.2.20.10")] +[assembly: AssemblyVersion("3.2.20.11")]