예제 #1
0
        private async Task ProcessGenresFromEmby(string id, IEnumerable <string> genresNeeded, CancellationToken cancellationToken)
        {
            var query = new ItemsByNameQuery
            {
                ParentId  = id,
                Recursive = true
            };

            var embyGenres = await _embyClient.GetGenresAsync(query, cancellationToken);

            var existingGenres = _genreRepository.GetIds();

            var newGenres = embyGenres
                            .Items
                            .Where(x => genresNeeded.Any(y => y == x.Id))
                            .Where(x => existingGenres.All(y => y != x.Id))
                            .ToList();

            if (newGenres.Any())
            {
                Log.Information($"Need to add {newGenres.Count} genres first ({string.Join(", ", newGenres.Select(x => x.Name))})");
                var genres = newGenres.Select(GenreHelper.ConvertToGenre);
                _genreRepository.AddRangeIfMissing(genres);
            }
            else
            {
                Log.Information("No new genres to add");
            }
        }