2020-12-03 03:51:53 +01:00
|
|
|
using System;
|
2020-10-28 00:57:52 +01:00
|
|
|
using System.Linq;
|
2020-12-03 03:51:53 +01:00
|
|
|
using System.Threading;
|
2020-12-03 08:07:51 +01:00
|
|
|
using MediaBrowser.Common.Configuration;
|
2020-10-28 00:57:52 +01:00
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.BaseItemManager
|
|
|
|
{
|
|
|
|
/// <inheritdoc />
|
|
|
|
public class BaseItemManager : IBaseItemManager
|
|
|
|
{
|
|
|
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
|
|
|
|
2020-12-03 08:07:51 +01:00
|
|
|
private int _metadataRefreshConcurrency = 0;
|
|
|
|
|
2020-10-28 00:57:52 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="BaseItemManager"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
|
|
|
public BaseItemManager(IServerConfigurationManager serverConfigurationManager)
|
|
|
|
{
|
|
|
|
_serverConfigurationManager = serverConfigurationManager;
|
2020-12-03 03:51:53 +01:00
|
|
|
|
2020-12-03 08:07:51 +01:00
|
|
|
_metadataRefreshConcurrency = GetMetadataRefreshConcurrency();
|
|
|
|
SetupMetadataThrottler();
|
2020-12-03 03:51:53 +01:00
|
|
|
|
2020-12-03 08:07:51 +01:00
|
|
|
_serverConfigurationManager.ConfigurationUpdated += (object sender, EventArgs e) =>
|
|
|
|
{
|
|
|
|
int newMetadataRefreshConcurrency = GetMetadataRefreshConcurrency();
|
|
|
|
if (_metadataRefreshConcurrency != newMetadataRefreshConcurrency)
|
2020-12-03 03:51:53 +01:00
|
|
|
{
|
2020-12-03 08:07:51 +01:00
|
|
|
_metadataRefreshConcurrency = newMetadataRefreshConcurrency;
|
|
|
|
SetupMetadataThrottler();
|
2020-12-03 03:51:53 +01:00
|
|
|
}
|
2020-12-03 08:07:51 +01:00
|
|
|
};
|
2020-10-28 00:57:52 +01:00
|
|
|
}
|
|
|
|
|
2020-12-03 03:51:53 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
public Lazy<SemaphoreSlim> MetadataRefreshThrottler { get; private set; }
|
|
|
|
|
2020-10-28 00:57:52 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
public bool IsMetadataFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
|
|
|
|
{
|
|
|
|
if (baseItem is Channel)
|
|
|
|
{
|
2020-11-08 14:42:54 +01:00
|
|
|
// Hack alert.
|
2020-10-28 00:57:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (baseItem.SourceType == SourceType.Channel)
|
|
|
|
{
|
2020-11-08 14:42:49 +01:00
|
|
|
// Hack alert.
|
2020-10-28 00:57:52 +01:00
|
|
|
return !baseItem.EnableMediaSourceDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
var typeOptions = libraryOptions.GetTypeOptions(GetType().Name);
|
|
|
|
if (typeOptions != null)
|
|
|
|
{
|
|
|
|
return typeOptions.ImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!libraryOptions.EnableInternetProviders)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, GetType().Name, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public bool IsImageFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
|
|
|
|
{
|
|
|
|
if (baseItem is Channel)
|
|
|
|
{
|
2020-11-08 14:42:40 +01:00
|
|
|
// Hack alert.
|
2020-10-28 00:57:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (baseItem.SourceType == SourceType.Channel)
|
|
|
|
{
|
2020-11-08 14:42:33 +01:00
|
|
|
// Hack alert.
|
2020-10-28 00:57:52 +01:00
|
|
|
return !baseItem.EnableMediaSourceDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
var typeOptions = libraryOptions.GetTypeOptions(GetType().Name);
|
|
|
|
if (typeOptions != null)
|
|
|
|
{
|
|
|
|
return typeOptions.ImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!libraryOptions.EnableInternetProviders)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, GetType().Name, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
}
|
2020-12-03 08:07:51 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the metadata refresh throttler.
|
|
|
|
/// </summary>
|
|
|
|
private void SetupMetadataThrottler()
|
|
|
|
{
|
|
|
|
MetadataRefreshThrottler = new Lazy<SemaphoreSlim>(() => new SemaphoreSlim(_metadataRefreshConcurrency));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the metadata refresh concurrency.
|
|
|
|
/// </summary>
|
|
|
|
private int GetMetadataRefreshConcurrency()
|
|
|
|
{
|
|
|
|
var concurrency = _serverConfigurationManager.Configuration.LibraryMetadataRefreshConcurrency;
|
|
|
|
|
|
|
|
if (concurrency <= 0)
|
|
|
|
{
|
|
|
|
concurrency = Environment.ProcessorCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return concurrency;
|
|
|
|
}
|
2020-10-28 00:57:52 +01:00
|
|
|
}
|
2020-11-08 14:42:33 +01:00
|
|
|
}
|