コード例 #1
0
        /// <summary>
        /// Retrieve the equivalent item if it already exists in the database,
        /// if it does not, fill metadata using the metadata provider, download images and register the item to the
        /// database.
        /// </summary>
        /// <param name="item">The item to retrieve or fill and register</param>
        /// <typeparam name="T">The type of the item</typeparam>
        /// <returns>The existing or filled item.</returns>
        private async Task <T> _RegisterAndFill <T>(T item)
            where T : class, IResource, IThumbnails, IMetadata
        {
            if (item == null || string.IsNullOrEmpty(item.Slug))
            {
                return(null);
            }

            T existing = await _libraryManager.GetOrDefault <T>(item.Slug);

            if (existing != null)
            {
                await _libraryManager.Load(existing, x => x.ExternalIDs);

                return(existing);
            }

            item = await _metadataProvider.Get(item);

            await _thumbnailsManager.DownloadImages(item);

            switch (item)
            {
            case Show show when show.People != null:
                foreach (PeopleRole role in show.People)
                {
                    await _thumbnailsManager.DownloadImages(role.People);
                }
                break;

            case Season season:
                season.Title ??= $"Season {season.SeasonNumber}";
                break;
            }

            return(await _libraryManager.CreateIfNotExists(item));
        }