Pass TypeOptions instead of full LibraryOptions

This commit is contained in:
Joe Rogers 2021-12-18 21:40:27 +01:00
parent d5e2c2fb5e
commit a7c009e2eb
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4
5 changed files with 31 additions and 41 deletions

View File

@ -35,7 +35,7 @@ namespace MediaBrowser.Controller.BaseItemManager
public SemaphoreSlim MetadataRefreshThrottler { get; private set; }
/// <inheritdoc />
public bool IsMetadataFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
public bool IsMetadataFetcherEnabled(BaseItem baseItem, TypeOptions? libraryTypeOptions, string name)
{
if (baseItem is Channel)
{
@ -49,10 +49,9 @@ namespace MediaBrowser.Controller.BaseItemManager
return !baseItem.EnableMediaSourceDisplay;
}
var typeOptions = libraryOptions.GetTypeOptions(baseItem.GetType().Name);
if (typeOptions != null)
if (libraryTypeOptions != null)
{
return typeOptions.MetadataFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
return libraryTypeOptions.MetadataFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
}
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, baseItem.GetType().Name, StringComparison.OrdinalIgnoreCase));
@ -61,7 +60,7 @@ namespace MediaBrowser.Controller.BaseItemManager
}
/// <inheritdoc />
public bool IsImageFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
public bool IsImageFetcherEnabled(BaseItem baseItem, TypeOptions? libraryTypeOptions, string name)
{
if (baseItem is Channel)
{
@ -75,10 +74,9 @@ namespace MediaBrowser.Controller.BaseItemManager
return !baseItem.EnableMediaSourceDisplay;
}
var typeOptions = libraryOptions.GetTypeOptions(baseItem.GetType().Name);
if (typeOptions != null)
if (libraryTypeOptions != null)
{
return typeOptions.ImageFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
return libraryTypeOptions.ImageFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
}
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, baseItem.GetType().Name, StringComparison.OrdinalIgnoreCase));

View File

@ -18,18 +18,18 @@ namespace MediaBrowser.Controller.BaseItemManager
/// Is metadata fetcher enabled.
/// </summary>
/// <param name="baseItem">The base item.</param>
/// <param name="libraryOptions">The library options.</param>
/// <param name="libraryTypeOptions">The type options for <c>baseItem</c> from the library (if defined).</param>
/// <param name="name">The metadata fetcher name.</param>
/// <returns><c>true</c> if metadata fetcher is enabled, else false.</returns>
bool IsMetadataFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name);
bool IsMetadataFetcherEnabled(BaseItem baseItem, TypeOptions? libraryTypeOptions, string name);
/// <summary>
/// Is image fetcher enabled.
/// </summary>
/// <param name="baseItem">The base item.</param>
/// <param name="libraryOptions">The library options.</param>
/// <param name="libraryTypeOptions">The type options for <c>baseItem</c> from the library (if defined).</param>
/// <param name="name">The image fetcher name.</param>
/// <returns><c>true</c> if image fetcher is enabled, else false.</returns>
bool IsImageFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name);
bool IsImageFetcherEnabled(BaseItem baseItem, TypeOptions? libraryTypeOptions, string name);
}
}

View File

@ -321,7 +321,7 @@ namespace MediaBrowser.Providers.Manager
var typeOptions = libraryOptions.GetTypeOptions(item.GetType().Name);
var fetcherOrder = typeOptions?.ImageFetcherOrder ?? options.ImageFetcherOrder;
return _imageProviders.Where(i => CanRefreshImages(i, item, libraryOptions, refreshOptions, includeDisabled))
return _imageProviders.Where(i => CanRefreshImages(i, item, typeOptions, refreshOptions, includeDisabled))
.OrderBy(i => GetConfiguredOrder(fetcherOrder, i.Name))
.ThenBy(GetDefaultOrder);
}
@ -343,7 +343,7 @@ namespace MediaBrowser.Providers.Manager
var metadataFetcherOrder = typeOptions?.MetadataFetcherOrder ?? globalMetadataOptions.MetadataFetcherOrder;
return _metadataProviders.OfType<IMetadataProvider<T>>()
.Where(i => CanRefreshMetadata(i, item, libraryOptions, includeDisabled, forceEnableInternetMetadata))
.Where(i => CanRefreshMetadata(i, item, typeOptions, includeDisabled, forceEnableInternetMetadata))
.OrderBy(i =>
{
// local and remote providers will be interleaved in the final order
@ -361,7 +361,7 @@ namespace MediaBrowser.Providers.Manager
private bool CanRefreshMetadata(
IMetadataProvider provider,
BaseItem item,
LibraryOptions libraryOptions,
TypeOptions? libraryTypeOptions,
bool includeDisabled,
bool forceEnableInternetMetadata)
{
@ -375,7 +375,7 @@ namespace MediaBrowser.Providers.Manager
if (provider is IRemoteMetadataProvider)
{
if (!forceEnableInternetMetadata && !_baseItemManager.IsMetadataFetcherEnabled(item, libraryOptions, provider.Name))
if (!forceEnableInternetMetadata && !_baseItemManager.IsMetadataFetcherEnabled(item, libraryTypeOptions, provider.Name))
{
return false;
}
@ -402,7 +402,7 @@ namespace MediaBrowser.Providers.Manager
private bool CanRefreshImages(
IImageProvider provider,
BaseItem item,
LibraryOptions libraryOptions,
TypeOptions? libraryTypeOptions,
ImageRefreshOptions refreshOptions,
bool includeDisabled)
{
@ -419,7 +419,7 @@ namespace MediaBrowser.Providers.Manager
if (provider is IRemoteImageProvider || provider is IDynamicImageProvider)
{
if (!_baseItemManager.IsImageFetcherEnabled(item, libraryOptions, provider.Name))
if (!_baseItemManager.IsImageFetcherEnabled(item, libraryTypeOptions, provider.Name))
{
return false;
}

View File

@ -20,17 +20,13 @@ namespace Jellyfin.Controller.Tests
{
BaseItem item = (BaseItem)Activator.CreateInstance(itemType)!;
var libraryOptions = new LibraryOptions
{
TypeOptions = new[]
{
new TypeOptions
var libraryTypeOptions = itemType == typeof(Book)
? new TypeOptions
{
Type = "Book",
MetadataFetchers = new[] { "LibraryEnabled" }
}
}
};
: null;
var serverConfiguration = new ServerConfiguration();
foreach (var typeConfig in serverConfiguration.MetadataOptions)
@ -43,7 +39,7 @@ namespace Jellyfin.Controller.Tests
.Returns(serverConfiguration);
var baseItemManager = new BaseItemManager(serverConfigurationManager.Object);
var actual = baseItemManager.IsMetadataFetcherEnabled(item, libraryOptions, fetcherName);
var actual = baseItemManager.IsMetadataFetcherEnabled(item, libraryTypeOptions, fetcherName);
Assert.Equal(expected, actual);
}
@ -57,17 +53,13 @@ namespace Jellyfin.Controller.Tests
{
BaseItem item = (BaseItem)Activator.CreateInstance(itemType)!;
var libraryOptions = new LibraryOptions
{
TypeOptions = new[]
{
new TypeOptions
var libraryTypeOptions = itemType == typeof(Book)
? new TypeOptions
{
Type = "Book",
ImageFetchers = new[] { "LibraryEnabled" }
}
}
};
: null;
var serverConfiguration = new ServerConfiguration();
foreach (var typeConfig in serverConfiguration.MetadataOptions)
@ -80,7 +72,7 @@ namespace Jellyfin.Controller.Tests
.Returns(serverConfiguration);
var baseItemManager = new BaseItemManager(serverConfigurationManager.Object);
var actual = baseItemManager.IsImageFetcherEnabled(item, libraryOptions, fetcherName);
var actual = baseItemManager.IsImageFetcherEnabled(item, libraryTypeOptions, fetcherName);
Assert.Equal(expected, actual);
}

View File

@ -131,7 +131,7 @@ namespace Jellyfin.Providers.Tests.Manager
};
var baseItemManager = new Mock<IBaseItemManager>(MockBehavior.Strict);
baseItemManager.Setup(i => i.IsImageFetcherEnabled(item, It.IsAny<LibraryOptions>(), providerName))
baseItemManager.Setup(i => i.IsImageFetcherEnabled(item, It.IsAny<TypeOptions>(), providerName))
.Returns(baseItemEnabled);
using var providerManager = GetProviderManager(baseItemManager: baseItemManager.Object);
@ -219,7 +219,7 @@ namespace Jellyfin.Providers.Tests.Manager
metadataFetcherOrder: serverRemoteOrder?.Select(nameProvider).ToArray());
var baseItemManager = new Mock<IBaseItemManager>(MockBehavior.Strict);
baseItemManager.Setup(i => i.IsMetadataFetcherEnabled(item, It.IsAny<LibraryOptions>(), It.IsAny<string>()))
baseItemManager.Setup(i => i.IsMetadataFetcherEnabled(item, It.IsAny<TypeOptions>(), It.IsAny<string>()))
.Returns(true);
using var providerManager = GetProviderManager(serverConfiguration: serverConfiguration, baseItemManager: baseItemManager.Object);
@ -302,7 +302,7 @@ namespace Jellyfin.Providers.Tests.Manager
var provider = MockIMetadataProviderMapper<MetadataTestItem, MetadataTestItemInfo>(providerType.Name, providerName, forced: providerForced);
var baseItemManager = new Mock<IBaseItemManager>(MockBehavior.Strict);
baseItemManager.Setup(i => i.IsMetadataFetcherEnabled(item, It.IsAny<LibraryOptions>(), providerName))
baseItemManager.Setup(i => i.IsMetadataFetcherEnabled(item, It.IsAny<TypeOptions>(), providerName))
.Returns(baseItemEnabled);
using var providerManager = GetProviderManager(baseItemManager: baseItemManager.Object);