示例#1
0
        private int GetConfiguredOrder(BaseItem item, IMetadataProvider provider, LibraryOptions libraryOptions, MetadataOptions globalMetadataOptions)
        {
            // See if there's a user-defined order
            if (provider is ILocalMetadataProvider)
            {
                var configuredOrder = libraryOptions.LocalMetadataReaderOrder ?? globalMetadataOptions.LocalMetadataReaderOrder;

                var index = Array.IndexOf(configuredOrder, provider.Name);

                if (index != -1)
                {
                    return(index);
                }
            }

            // See if there's a user-defined order
            if (provider is IRemoteMetadataProvider)
            {
                var typeOptions      = libraryOptions.GetTypeOptions(item.GetType().Name);
                var typeFetcherOrder = typeOptions?.MetadataFetcherOrder;

                var fetcherOrder = typeFetcherOrder ?? globalMetadataOptions.MetadataFetcherOrder;

                var index = Array.IndexOf(fetcherOrder, provider.Name);

                if (index != -1)
                {
                    return(index);
                }
            }

            // Not configured. Just return some high number to put it at the end.
            return(100);
        }
示例#2
0
        private IEnumerable <IImageProvider> GetImageProviders(BaseItem item, LibraryOptions libraryOptions, MetadataOptions options, ImageRefreshOptions refreshOptions, bool includeDisabled)
        {
            // Avoid implicitly captured closure
            var currentOptions = options;

            var typeOptions      = libraryOptions.GetTypeOptions(item.GetType().Name);
            var typeFetcherOrder = typeOptions?.ImageFetcherOrder;

            return(ImageProviders.Where(i => CanRefresh(i, item, libraryOptions, refreshOptions, includeDisabled))
                   .OrderBy(i =>
            {
                // See if there's a user-defined order
                if (!(i is ILocalImageProvider))
                {
                    var fetcherOrder = typeFetcherOrder ?? currentOptions.ImageFetcherOrder;
                    var index = Array.IndexOf(fetcherOrder, i.Name);

                    if (index != -1)
                    {
                        return index;
                    }
                }

                // Not configured. Just return some high number to put it at the end.
                return 100;
            })
                   .ThenBy(GetOrder));
        }
示例#3
0
        public bool IsImageFetcherEnabled(BaseItem baseItem, LibraryOptions libraryOptions, string name)
        {
            if (baseItem is Channel)
            {
                // Hack alert.
                return(true);
            }

            if (baseItem.SourceType == SourceType.Channel)
            {
                // Hack alert.
                return(!baseItem.EnableMediaSourceDisplay);
            }

            var typeOptions = libraryOptions.GetTypeOptions(baseItem.GetType().Name);

            if (typeOptions != null)
            {
                return(typeOptions.ImageFetchers.Contains(name.AsSpan(), StringComparison.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.AsSpan(), StringComparison.OrdinalIgnoreCase));
        }
示例#4
0
        public async Task <RefreshResult> RefreshImages(
            BaseItem item,
            LibraryOptions libraryOptions,
            IEnumerable <IImageProvider> providers,
            ImageRefreshOptions refreshOptions,
            CancellationToken cancellationToken)
        {
            var oldBackdropImages = Array.Empty <ItemImageInfo>();

            if (refreshOptions.IsReplacingImage(ImageType.Backdrop))
            {
                oldBackdropImages = item.GetImages(ImageType.Backdrop).ToArray();
            }

            var result = new RefreshResult {
                UpdateType = ItemUpdateType.None
            };

            var typeName    = item.GetType().Name;
            var typeOptions = libraryOptions.GetTypeOptions(typeName) ?? new TypeOptions {
                Type = typeName
            };

            // track library limits, adding buffer to allow lazy replacing of current images
            var backdropLimit    = typeOptions.GetLimit(ImageType.Backdrop) + oldBackdropImages.Length;
            var downloadedImages = new List <ImageType>();

            foreach (var provider in providers)
            {
                if (provider is IRemoteImageProvider remoteProvider)
                {
                    await RefreshFromProvider(item, remoteProvider, refreshOptions, typeOptions, backdropLimit, downloadedImages, result, cancellationToken).ConfigureAwait(false);

                    continue;
                }

                if (provider is IDynamicImageProvider dynamicImageProvider)
                {
                    await RefreshFromProvider(item, dynamicImageProvider, refreshOptions, typeOptions, downloadedImages, result, cancellationToken).ConfigureAwait(false);
                }
            }

            // only delete existing multi-images if new ones were added
            if (oldBackdropImages.Length > 0 && oldBackdropImages.Length < item.GetImages(ImageType.Backdrop).Count())
            {
                PruneImages(item, oldBackdropImages);
            }

            return(result);
        }
示例#5
0
        public async Task <RefreshResult> RefreshImages(
            BaseItem item,
            LibraryOptions libraryOptions,
            List <IImageProvider> providers,
            ImageRefreshOptions refreshOptions,
            CancellationToken cancellationToken)
        {
            if (refreshOptions.IsReplacingImage(ImageType.Backdrop))
            {
                ClearImages(item, ImageType.Backdrop);
            }

            if (refreshOptions.IsReplacingImage(ImageType.Screenshot))
            {
                ClearImages(item, ImageType.Screenshot);
            }

            var result = new RefreshResult {
                UpdateType = ItemUpdateType.None
            };

            var typeName    = item.GetType().Name;
            var typeOptions = libraryOptions.GetTypeOptions(typeName) ?? new TypeOptions {
                Type = typeName
            };

            // In order to avoid duplicates, only download these if there are none already
            var backdropLimit    = typeOptions.GetLimit(ImageType.Backdrop);
            var screenshotLimit  = typeOptions.GetLimit(ImageType.Screenshot);
            var downloadedImages = new List <ImageType>();

            foreach (var provider in providers)
            {
                if (provider is IRemoteImageProvider remoteProvider)
                {
                    await RefreshFromProvider(item, libraryOptions, remoteProvider, refreshOptions, typeOptions, backdropLimit, screenshotLimit, downloadedImages, result, cancellationToken).ConfigureAwait(false);

                    continue;
                }

                if (provider is IDynamicImageProvider dynamicImageProvider)
                {
                    await RefreshFromProvider(item, dynamicImageProvider, refreshOptions, typeOptions, downloadedImages, result, cancellationToken).ConfigureAwait(false);
                }
            }

            return(result);
        }