From 1f7e1f5c4a9051c7fa13a09b4d895cf58ee1b3bf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 14 Oct 2015 01:02:30 -0400 Subject: [PATCH] boxset image fixes --- MediaBrowser.Api/StartupWizardService.cs | 1 + MediaBrowser.Controller/Entities/BaseItem.cs | 3 ++ .../Entities/IHasMetadata.cs | 6 ++++ .../Providers/ImageRefreshMode.cs | 12 +++---- .../Configuration/ServerConfiguration.cs | 2 ++ .../Manager/MetadataService.cs | 36 ++++++++++++++++--- .../Collections/CollectionImageProvider.cs | 11 ++++++ .../Collections/CollectionManager.cs | 15 +++++--- .../Library/LibraryManager.cs | 6 ++-- .../LiveTv/LiveTvManager.cs | 2 +- .../Persistence/SqliteItemRepository.cs | 21 +++++++++-- .../Photos/BaseDynamicImageProvider.cs | 2 +- .../CollectionFolderImageProvider.cs | 2 +- .../UserViews/DynamicImageProvider.cs | 2 +- 14 files changed, 97 insertions(+), 24 deletions(-) diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 962334cdc..399c81ae8 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -73,6 +73,7 @@ namespace MediaBrowser.Api _config.Configuration.DisableXmlSavers = true; _config.Configuration.DisableStartupScan = true; _config.Configuration.EnableUserViews = true; + _config.Configuration.EnableDateLastRefresh = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 59d2a4bc7..22ca607ba 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -342,6 +342,9 @@ namespace MediaBrowser.Controller.Entities public DateTime DateLastSaved { get; set; } + [IgnoreDataMember] + public DateTime DateLastRefreshed { get; set; } + /// /// The logger /// diff --git a/MediaBrowser.Controller/Entities/IHasMetadata.cs b/MediaBrowser.Controller/Entities/IHasMetadata.cs index b8c3e2823..4eb25718e 100644 --- a/MediaBrowser.Controller/Entities/IHasMetadata.cs +++ b/MediaBrowser.Controller/Entities/IHasMetadata.cs @@ -30,6 +30,12 @@ namespace MediaBrowser.Controller.Entities /// The date last saved. DateTime DateLastSaved { get; set; } + /// + /// Gets or sets the date last refreshed. + /// + /// The date last refreshed. + DateTime DateLastRefreshed { get; set; } + /// /// Updates to repository. /// diff --git a/MediaBrowser.Controller/Providers/ImageRefreshMode.cs b/MediaBrowser.Controller/Providers/ImageRefreshMode.cs index df10c91f6..73ef4b8cd 100644 --- a/MediaBrowser.Controller/Providers/ImageRefreshMode.cs +++ b/MediaBrowser.Controller/Providers/ImageRefreshMode.cs @@ -7,15 +7,15 @@ namespace MediaBrowser.Controller.Providers /// None = 0, - /// - /// The default - /// - Default = 1, - /// /// Existing images will be validated /// - ValidationOnly = 2, + ValidationOnly = 1, + + /// + /// The default + /// + Default = 2, /// /// All providers will be executed to search for new metadata diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 5121fcd6f..06a35ac0d 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -224,6 +224,8 @@ namespace MediaBrowser.Model.Configuration public bool EnableVideoFrameByFrameAnalysis { get; set; } + public bool EnableDateLastRefresh { get; set; } + /// /// Initializes a new instance of the class. /// diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index f40f17588..316809fa8 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Entities.Movies; namespace MediaBrowser.Providers.Manager { @@ -82,7 +83,7 @@ namespace MediaBrowser.Providers.Manager /// ProviderResult. protected MetadataStatus GetLastResult(IHasMetadata item) { - if (item.DateLastSaved == default(DateTime)) + if (GetLastRefreshDate(item) == default(DateTime)) { return new MetadataStatus { ItemId = item.Id }; } @@ -181,11 +182,13 @@ namespace MediaBrowser.Providers.Manager } } - var beforeSaveResult = await BeforeSave(itemOfType, item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata || refreshOptions.MetadataRefreshMode == MetadataRefreshMode.FullRefresh, updateType).ConfigureAwait(false); + var isFirstRefresh = GetLastRefreshDate(item) == default(DateTime); + + var beforeSaveResult = await BeforeSave(itemOfType, isFirstRefresh || refreshOptions.ReplaceAllMetadata || refreshOptions.MetadataRefreshMode == MetadataRefreshMode.FullRefresh, updateType).ConfigureAwait(false); updateType = updateType | beforeSaveResult; // Save if changes were made, or it's never been saved before - if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata) + if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || isFirstRefresh || refreshOptions.ReplaceAllMetadata) { // If any of these properties are set then make sure the updateType is not None, just to force everything to save if (refreshOptions.ForceSave || refreshOptions.ReplaceAllMetadata) @@ -193,6 +196,11 @@ namespace MediaBrowser.Providers.Manager updateType = updateType | ItemUpdateType.MetadataDownload; } + if (refreshOptions.MetadataRefreshMode >= MetadataRefreshMode.Default && refreshOptions.ImageRefreshMode >= ImageRefreshMode.Default) + { + item.DateLastRefreshed = DateTime.UtcNow; + } + // Save to database await SaveItem(metadataResult, updateType, cancellationToken).ConfigureAwait(false); } @@ -207,6 +215,26 @@ namespace MediaBrowser.Providers.Manager return updateType; } + private DateTime GetLastRefreshDate(IHasMetadata item) + { + if (item.DateLastRefreshed != default(DateTime)) + { + return item.DateLastRefreshed; + } + + if (ServerConfigurationManager.Configuration.EnableDateLastRefresh) + { + return item.DateLastRefreshed; + } + + if (item is BoxSet) + { + return item.DateLastRefreshed; + } + + return item.DateLastSaved; + } + protected async Task SaveItem(MetadataResult result, ItemUpdateType reason, CancellationToken cancellationToken) { if (result.Item.SupportsPeople && result.People != null) @@ -222,7 +250,7 @@ namespace MediaBrowser.Providers.Manager item.AfterMetadataRefresh(); return _cachedTask; } - + private readonly Task _cachedResult = Task.FromResult(ItemUpdateType.None); /// /// Befores the save. diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs b/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs index b88e45980..5ff182844 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs @@ -22,6 +22,17 @@ namespace MediaBrowser.Server.Implementations.Collections { } + protected override bool Supports(IHasImages item) + { + // Right now this is the only way to prevent this image from getting created ahead of internet image providers + if (!item.IsLocked) + { + return false; + } + + return base.Supports(item); + } + protected override Task> GetItemsWithImages(IHasImages item) { var playlist = (BoxSet)item; diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 8a19ee431..5c98e401f 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -73,7 +73,7 @@ namespace MediaBrowser.Server.Implementations.Collections try { - _fileSystem.CreateDirectory(path); + _fileSystem.CreateDirectory(path); var collection = new BoxSet { @@ -93,7 +93,12 @@ namespace MediaBrowser.Server.Implementations.Collections if (options.ItemIdList.Count > 0) { - await AddToCollection(collection.Id, options.ItemIdList, false); + await AddToCollection(collection.Id, options.ItemIdList, false, new MetadataRefreshOptions(_fileSystem) + { + // The initial adding of items is going to create a local metadata file + // This will cause internet metadata to be skipped as a result + MetadataRefreshMode = MetadataRefreshMode.FullRefresh + }); } else { @@ -145,10 +150,10 @@ namespace MediaBrowser.Server.Implementations.Collections public Task AddToCollection(Guid collectionId, IEnumerable ids) { - return AddToCollection(collectionId, ids, true); + return AddToCollection(collectionId, ids, true, new MetadataRefreshOptions(_fileSystem)); } - private async Task AddToCollection(Guid collectionId, IEnumerable ids, bool fireEvent) + private async Task AddToCollection(Guid collectionId, IEnumerable ids, bool fireEvent, MetadataRefreshOptions refreshOptions) { var collection = _libraryManager.GetItemById(collectionId) as BoxSet; @@ -186,7 +191,7 @@ namespace MediaBrowser.Server.Implementations.Collections await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); - _providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(_fileSystem)); + _providerManager.QueueRefresh(collection.Id, refreshOptions); if (fireEvent) { diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 93e660fd3..06b9ecabe 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1699,7 +1699,7 @@ namespace MediaBrowser.Server.Implementations.Library if (!refresh) { - refresh = (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + refresh = (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval; } if (refresh) @@ -1796,7 +1796,7 @@ namespace MediaBrowser.Server.Implementations.Library await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); } - var refresh = isNew || (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval; if (refresh) { @@ -1866,7 +1866,7 @@ namespace MediaBrowser.Server.Implementations.Library await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); } - var refresh = isNew || (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval; if (refresh) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 40e837ed7..65125da66 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -706,7 +706,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv isNew = true; } - + item.ChannelId = _tvDtoService.GetInternalChannelId(serviceName, info.ChannelId).ToString("N"); item.CommunityRating = info.CommunityRating; item.OfficialRating = info.OfficialRating; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 4b8388582..cede9350e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -197,6 +197,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(_logger, "TypedBaseItems", "IsHD", "BIT"); _connection.AddColumn(_logger, "TypedBaseItems", "ExternalEtag", "Text"); _connection.AddColumn(_logger, "TypedBaseItems", "ExternalImagePath", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME"); PrepareStatements(); @@ -291,7 +292,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "PreferredMetadataCountryCode", "IsHD", "ExternalEtag", - "ExternalImagePath" + "ExternalImagePath", + "DateLastRefreshed" }; private readonly string[] _mediaStreamSaveColumns = @@ -378,7 +380,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "PreferredMetadataCountryCode", "IsHD", "ExternalEtag", - "ExternalImagePath" + "ExternalImagePath", + "DateLastRefreshed" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -599,6 +602,15 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.ExternalEtag; _saveItemCommand.GetParameter(index++).Value = item.ExternalImagePath; + if (item.DateLastRefreshed == default(DateTime)) + { + _saveItemCommand.GetParameter(index++).Value = null; + } + else + { + _saveItemCommand.GetParameter(index++).Value = item.DateLastRefreshed; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -820,6 +832,11 @@ namespace MediaBrowser.Server.Implementations.Persistence item.ExternalImagePath = reader.GetString(23); } + if (!reader.IsDBNull(24)) + { + item.DateLastRefreshed = reader.GetDateTime(24).ToUniversalTime(); + } + return item; } diff --git a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs index cc0140d68..47ec47f8f 100644 --- a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Photos ImageProcessor = imageProcessor; } - public virtual bool Supports(IHasImages item) + protected virtual bool Supports(IHasImages item) { return true; } diff --git a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs index a699bfabf..9247edadb 100644 --- a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.UserViews return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)).ToList(), 8); } - public override bool Supports(IHasImages item) + protected override bool Supports(IHasImages item) { return item is CollectionFolder; } diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 2b18218a8..8dfbe38f1 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -131,7 +131,7 @@ namespace MediaBrowser.Server.Implementations.UserViews return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary)).ToList()); } - public override bool Supports(IHasImages item) + protected override bool Supports(IHasImages item) { var view = item as UserView; if (view != null)