private async Task AddMoviesToCollection(IReadOnlyCollection <Movie> movies, string tmdbCollectionId, BoxSet boxSet) { int minimumNumberOfMovies = Plugin.Instance.PluginConfiguration.MinimumNumberOfMovies; if (movies.Count < minimumNumberOfMovies) { _logger.LogInformation("Minimum number of movies is {Count}, but there is/are only {MovieCount}: {MovieNames}", minimumNumberOfMovies, movies.Count, string.Join(", ", movies.Select(m => m.Name))); return; } // Create the box set if it doesn't exist, but don't add anything to it on creation if (boxSet == null) { var tmdbCollectionName = GetTmdbCollectionName(movies); if (string.IsNullOrWhiteSpace(tmdbCollectionName)) { _logger.LogError("Can't get a proper box set name for the movies {MovieNames}. Make sure is propertly assigned to the movie info.", string.Join(", ", movies.Select(m => m.Name))); return; } if (Plugin.Instance.PluginConfiguration.StripCollectionKeywords) { tmdbCollectionName = tmdbCollectionName.Replace("Collection", String.Empty).Trim(); } _logger.LogInformation("Box Set for {TmdbCollectionName} ({TmdbCollectionId}) does not exist. Creating it now!", tmdbCollectionName, tmdbCollectionId); boxSet = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions { Name = tmdbCollectionName, ProviderIds = new Dictionary <string, string> { { MetadataProvider.Tmdb.ToString(), tmdbCollectionId } } }).ConfigureAwait(false); } var itemsToAdd = movies .Where(m => !boxSet.ContainsLinkedChildByItemId(m.Id)) .Select(m => m.Id) .ToList(); if (!itemsToAdd.Any()) { _logger.LogInformation("The movies {MovieNames} is/are already in their proper box set, {BoxSetName}", string.Join(", ", movies.Select(m => m.Name)), boxSet.Name); return; } await _collectionManager.AddToCollectionAsync(boxSet.Id, itemsToAdd).ConfigureAwait(false); }
private void AddMoviesToCollection(IReadOnlyCollection <Movie> movies, string tmdbCollectionId, BoxSet boxSet) { int minimumNumberOfMovies = Plugin.Instance.PluginConfiguration.MinimumNumberOfMovies; if (movies.Count < minimumNumberOfMovies) { _logger.LogInformation("Minimum number of movies is {Count}, but there is/are only {MovieCount}: {MovieNames}", minimumNumberOfMovies, movies.Count, string.Join(", ", movies.Select(m => m.Name))); return; } // Create the box set if it doesn't exist, but don't add anything to it on creation if (boxSet == null) { var tmdbCollectionName = movies.First().TmdbCollectionName; _logger.LogInformation("Box Set for {TmdbCollectionName} ({TmdbCollectionId}) does not exist. Creating it now!", tmdbCollectionName, tmdbCollectionId); boxSet = _collectionManager.CreateCollection(new CollectionCreationOptions { Name = tmdbCollectionName, ProviderIds = new Dictionary <string, string> { { MetadataProviders.Tmdb.ToString(), tmdbCollectionId } } }); } var itemsToAdd = movies .Where(m => !boxSet.ContainsLinkedChildByItemId(m.Id)) .Select(m => m.Id) .ToList(); if (!itemsToAdd.Any()) { _logger.LogInformation("The movies {MovieNames} is/are already in their proper box set, {BoxSetName}", string.Join(", ", movies.Select(m => m.Name)), boxSet.Name); return; } _collectionManager.AddToCollection(boxSet.Id, itemsToAdd); }