diff --git a/MediaBrowser.Controller/Providers/IHasChangeMonitor.cs b/MediaBrowser.Controller/Providers/IHasChangeMonitor.cs index aa0b0e3c9..d914abf61 100644 --- a/MediaBrowser.Controller/Providers/IHasChangeMonitor.cs +++ b/MediaBrowser.Controller/Providers/IHasChangeMonitor.cs @@ -14,4 +14,16 @@ namespace MediaBrowser.Controller.Providers /// true if the specified item has changed; otherwise, false. bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date); } + + public interface IHasItemChangeMonitor + { + /// + /// Determines whether the specified item has changed. + /// + /// The item. + /// The status. + /// The directory service. + /// true if the specified item has changed; otherwise, false. + bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService); + } } diff --git a/MediaBrowser.Controller/Providers/MetadataStatus.cs b/MediaBrowser.Controller/Providers/MetadataStatus.cs index 1e84e5880..12844c3c4 100644 --- a/MediaBrowser.Controller/Providers/MetadataStatus.cs +++ b/MediaBrowser.Controller/Providers/MetadataStatus.cs @@ -61,6 +61,8 @@ namespace MediaBrowser.Controller.Providers public List MetadataProvidersRefreshed { get; set; } public List ImageProvidersRefreshed { get; set; } + public DateTime? ItemDateModified { get; set; } + public void AddStatus(ProviderRefreshStatus status, string errorMessage) { if (LastStatus != status) diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index ab618dc5a..0fdb8f7cc 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -159,8 +159,6 @@ namespace MediaBrowser.Model.Configuration public bool EnableAutomaticRestart { get; set; } - public TvFileOrganizationOptions TvFileOrganizationOptions { get; set; } - public bool EnableRealtimeMonitor { get; set; } public PathSubstitution[] PathSubstitutions { get; set; } diff --git a/MediaBrowser.Providers/FolderImages/DefaultImageProvider.cs b/MediaBrowser.Providers/FolderImages/DefaultImageProvider.cs index aaedc9684..c2e4939e9 100644 --- a/MediaBrowser.Providers/FolderImages/DefaultImageProvider.cs +++ b/MediaBrowser.Providers/FolderImages/DefaultImageProvider.cs @@ -13,7 +13,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Providers.FolderImages { - public class DefaultImageProvider : IRemoteImageProvider, IHasChangeMonitor + public class DefaultImageProvider : IRemoteImageProvider, IHasItemChangeMonitor { private readonly IHttpClient _httpClient; @@ -132,7 +132,7 @@ namespace MediaBrowser.Providers.FolderImages }); } - public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) + public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService) { return GetSupportedImages(item).Any(i => !item.HasImage(i)); } diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index eee8b59e2..92df1c86e 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using System.IO; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; @@ -38,8 +39,9 @@ namespace MediaBrowser.Providers.Manager /// /// The item. /// The result. + /// The directory service. /// Task. - protected Task SaveProviderResult(TItemType item, MetadataStatus result) + protected Task SaveProviderResult(TItemType item, MetadataStatus result, IDirectoryService directoryService) { result.ItemId = item.Id; result.ItemName = item.Name; @@ -49,6 +51,23 @@ namespace MediaBrowser.Providers.Manager result.SeriesName = series == null ? null : series.SeriesName; + //var locationType = item.LocationType; + + //if (locationType == LocationType.FileSystem || locationType == LocationType.Offline) + //{ + // if (!string.IsNullOrWhiteSpace(item.Path)) + // { + // var file = directoryService.GetFile(item.Path); + + // if ((file.Attributes & FileAttributes.Directory) != FileAttributes.Directory && file.Exists) + // { + // result.ItemDateModified = FileSystem.GetLastWriteTimeUtc(file); + // } + // } + //} + + result.ItemDateModified = item.DateModified; + return ProviderRepo.SaveMetadataStatus(result, CancellationToken.None); } @@ -106,7 +125,7 @@ namespace MediaBrowser.Providers.Manager // Next run metadata providers if (refreshOptions.MetadataRefreshMode != MetadataRefreshMode.None) { - var providers = GetProviders(item, refreshResult.DateLastMetadataRefresh.HasValue, refreshOptions) + var providers = GetProviders(item, refreshResult, refreshOptions) .ToList(); if (providers.Count > 0 || !refreshResult.DateLastMetadataRefresh.HasValue) @@ -135,7 +154,7 @@ namespace MediaBrowser.Providers.Manager // Next run remote image providers, but only if local image providers didn't throw an exception if (!localImagesFailed && refreshOptions.ImageRefreshMode != ImageRefreshMode.ValidationOnly) { - var providers = GetNonLocalImageProviders(item, allImageProviders, refreshResult.DateLastImagesRefresh, refreshOptions).ToList(); + var providers = GetNonLocalImageProviders(item, allImageProviders, refreshResult, refreshOptions).ToList(); if (providers.Count > 0) { @@ -161,7 +180,7 @@ namespace MediaBrowser.Providers.Manager if (providersHadChanges || refreshResult.IsDirty) { - await SaveProviderResult(itemOfType, refreshResult).ConfigureAwait(false); + await SaveProviderResult(itemOfType, refreshResult, refreshOptions.DirectoryService).ConfigureAwait(false); } } @@ -188,25 +207,39 @@ namespace MediaBrowser.Providers.Manager /// Gets the providers. /// /// The item. - /// if set to true [has refreshed metadata]. + /// The status. /// The options. /// IEnumerable{`0}. - protected virtual IEnumerable GetProviders(IHasMetadata item, bool hasRefreshedMetadata, MetadataRefreshOptions options) + protected IEnumerable GetProviders(IHasMetadata item, MetadataStatus status, MetadataRefreshOptions options) { // Get providers to refresh var providers = ((ProviderManager)ProviderManager).GetMetadataProviders(item).ToList(); // Run all if either of these flags are true - var runAllProviders = options.ReplaceAllMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || !hasRefreshedMetadata; + var runAllProviders = options.ReplaceAllMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || !status.DateLastMetadataRefresh.HasValue; if (!runAllProviders) { // Avoid implicitly captured closure var currentItem = item; - var providersWithChanges = providers.OfType() - .Where(i => HasChanged(currentItem, i, currentItem.DateLastSaved, options.DirectoryService)) - .Cast>() + var providersWithChanges = providers + .Where(i => + { + var hasChangeMonitor = i as IHasChangeMonitor; + if (hasChangeMonitor != null) + { + return HasChanged(item, hasChangeMonitor, currentItem.DateLastSaved, options.DirectoryService); + } + + var hasFileChangeMonitor = i as IHasItemChangeMonitor; + if (hasFileChangeMonitor != null) + { + return HasChanged(item, hasFileChangeMonitor, status, options.DirectoryService); + } + + return false; + }) .ToList(); if (providersWithChanges.Count == 0) @@ -242,19 +275,33 @@ namespace MediaBrowser.Providers.Manager return providers; } - protected virtual IEnumerable GetNonLocalImageProviders(IHasMetadata item, IEnumerable allImageProviders, DateTime? dateLastImageRefresh, ImageRefreshOptions options) + protected virtual IEnumerable GetNonLocalImageProviders(IHasMetadata item, IEnumerable allImageProviders, MetadataStatus status, ImageRefreshOptions options) { // Get providers to refresh var providers = allImageProviders.Where(i => !(i is ILocalImageProvider)).ToList(); // Run all if either of these flags are true - var runAllProviders = options.ImageRefreshMode == ImageRefreshMode.FullRefresh || !dateLastImageRefresh.HasValue; + var runAllProviders = options.ImageRefreshMode == ImageRefreshMode.FullRefresh || !status.DateLastImagesRefresh.HasValue; if (!runAllProviders) { - providers = providers.OfType() - .Where(i => HasChanged(item, i, dateLastImageRefresh.Value, options.DirectoryService)) - .Cast() + providers = providers + .Where(i => + { + var hasChangeMonitor = i as IHasChangeMonitor; + if (hasChangeMonitor != null) + { + return HasChanged(item, hasChangeMonitor, status.DateLastImagesRefresh.Value, options.DirectoryService); + } + + var hasFileChangeMonitor = i as IHasItemChangeMonitor; + if (hasFileChangeMonitor != null) + { + return HasChanged(item, hasFileChangeMonitor, status, options.DirectoryService); + } + + return false; + }) .ToList(); } @@ -520,6 +567,19 @@ namespace MediaBrowser.Providers.Manager } } + private bool HasChanged(IHasMetadata item, IHasItemChangeMonitor changeMonitor, MetadataStatus status, IDirectoryService directoryService) + { + try + { + return changeMonitor.HasChanged(item, status, directoryService); + } + catch (Exception ex) + { + Logger.ErrorException("Error in {0}.HasChanged", ex, changeMonitor.GetType().Name); + return false; + } + } + private bool HasChanged(IHasMetadata item, IHasChangeMonitor changeMonitor, DateTime date, IDirectoryService directoryService) { try diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index 9188a2281..b0c1b10e4 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Providers.MediaInfo /// /// Uses ffmpeg to create video images /// - public class AudioImageProvider : IDynamicImageProvider, IHasChangeMonitor + public class AudioImageProvider : IDynamicImageProvider, IHasItemChangeMonitor { private readonly ConcurrentDictionary _locks = new ConcurrentDictionary(); @@ -135,9 +135,17 @@ namespace MediaBrowser.Providers.MediaInfo return item is Audio; } - public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) + public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService) { - return item.DateModified > date; + if (status.ItemDateModified.HasValue) + { + if (status.ItemDateModified.Value != item.DateModified) + { + return true; + } + } + + return false; } } } diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs index e3324fe82..cf0c4bbc2 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs @@ -34,7 +34,7 @@ namespace MediaBrowser.Providers.MediaInfo ICustomMetadataProvider, ICustomMetadataProvider