Пример #1
0
        public async Task <ActionResult <CollectionCreationResult> > CreateCollection(
            [FromQuery] string?name,
            [FromQuery] string?ids,
            [FromQuery] Guid?parentId,
            [FromQuery] bool isLocked = false)
        {
            var userId = _authContext.GetAuthorizationInfo(Request).UserId;

            var item = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions
            {
                IsLocked   = isLocked,
                Name       = name,
                ParentId   = parentId,
                ItemIdList = RequestHelpers.Split(ids, ',', true),
                UserIds    = new[] { userId }
            }).ConfigureAwait(false);

            var dtoOptions = new DtoOptions().AddClientFields(Request);

            var dto = _dtoService.GetBaseItemDto(item, dtoOptions);

            return(new CollectionCreationResult
            {
                Id = dto.Id
            });
        }
Пример #2
0
        public async Task <ActionResult <CollectionCreationResult> > CreateCollection(
            [FromQuery] string?name,
            [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] ids,
            [FromQuery] Guid?parentId,
            [FromQuery] bool isLocked = false)
        {
            var userId = (await _authContext.GetAuthorizationInfo(Request).ConfigureAwait(false)).UserId;

            var item = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions
            {
                IsLocked   = isLocked,
                Name       = name,
                ParentId   = parentId,
                ItemIdList = ids,
                UserIds    = new[] { userId }
            }).ConfigureAwait(false);

            var dtoOptions = new DtoOptions().AddClientFields(Request);

            var dto = _dtoService.GetBaseItemDto(item, dtoOptions);

            return(new CollectionCreationResult
            {
                Id = dto.Id
            });
        }
Пример #3
0
        public static Task CreateCollectionAsync(this ICollectionManager manager, CollectionSpec spec, Action <CreateCollectionOptions> configureOptions)
        {
            var options = new CreateCollectionOptions();

            configureOptions(options);

            return(manager.CreateCollectionAsync(spec, options));
        }
Пример #4
0
        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);
        }
Пример #5
0
 public static Task CreateCollectionAsync(this ICollectionManager manager, CollectionSpec spec)
 {
     return(manager.CreateCollectionAsync(spec, CreateCollectionOptions.Default));
 }