Beispiel #1
0
        /// <inheritdoc/>
        protected override async Task Validate(Season resource)
        {
            await base.Validate(resource);

            if (resource.ShowID <= 0)
            {
                if (resource.Show == null)
                {
                    throw new ArgumentException($"Can't store a season not related to any show " +
                                                $"(showID: {resource.ShowID}).");
                }
                resource.ShowID = resource.Show.ID;
            }

            if (resource.ExternalIDs != null)
            {
                foreach (MetadataID id in resource.ExternalIDs)
                {
                    id.Provider = _database.LocalEntity <Provider>(id.Provider.Slug)
                                  ?? await _providers.CreateIfNotExists(id.Provider);

                    id.ProviderID = id.Provider.ID;
                }
                _database.MetadataIds <Season>().AttachRange(resource.ExternalIDs);
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        protected override async Task Validate(Library resource)
        {
            await base.Validate(resource);

            if (string.IsNullOrEmpty(resource.Slug))
            {
                throw new ArgumentException("The library's slug must be set and not empty");
            }
            if (string.IsNullOrEmpty(resource.Name))
            {
                throw new ArgumentException("The library's name must be set and not empty");
            }
            if (resource.Paths == null || !resource.Paths.Any())
            {
                throw new ArgumentException("The library should have a least one path.");
            }

            if (resource.Providers != null)
            {
                resource.Providers = await resource.Providers
                                     .SelectAsync(x => _providers.CreateIfNotExists(x))
                                     .ToListAsync();

                _database.AttachRange(resource.Providers);
            }
        }
        /// <inheritdoc />
        protected override async Task Validate(Collection resource)
        {
            await base.Validate(resource);

            if (string.IsNullOrEmpty(resource.Slug))
            {
                throw new ArgumentException("The collection's slug must be set and not empty");
            }
            if (string.IsNullOrEmpty(resource.Name))
            {
                throw new ArgumentException("The collection's name must be set and not empty");
            }

            if (resource.ExternalIDs != null)
            {
                foreach (MetadataID id in resource.ExternalIDs)
                {
                    id.Provider = _database.LocalEntity <Provider>(id.Provider.Slug)
                                  ?? await _providers.CreateIfNotExists(id.Provider);

                    id.ProviderID = id.Provider.ID;
                }
                _database.MetadataIds <Collection>().AttachRange(resource.ExternalIDs);
            }
        }
Beispiel #4
0
        /// <inheritdoc />
        protected override async Task Validate(People resource)
        {
            await base.Validate(resource);

            if (resource.ExternalIDs != null)
            {
                foreach (MetadataID id in resource.ExternalIDs)
                {
                    id.Provider = _database.LocalEntity <Provider>(id.Provider.Slug)
                                  ?? await _providers.CreateIfNotExists(id.Provider);

                    id.ProviderID = id.Provider.ID;
                }
                _database.MetadataIds <People>().AttachRange(resource.ExternalIDs);
            }

            if (resource.Roles != null)
            {
                foreach (PeopleRole role in resource.Roles)
                {
                    role.Show = _database.LocalEntity <Show>(role.Show.Slug)
                                ?? await _shows.Value.CreateIfNotExists(role.Show);

                    role.ShowID = role.Show.ID;
                    _database.Entry(role).State = EntityState.Added;
                }
            }
        }
        /// <inheritdoc />
        protected override async Task Validate(Studio resource)
        {
            await base.Validate(resource);

            if (resource.ExternalIDs != null)
            {
                foreach (MetadataID id in resource.ExternalIDs)
                {
                    id.Provider = _database.LocalEntity <Provider>(id.Provider.Slug)
                                  ?? await _providers.CreateIfNotExists(id.Provider);

                    id.ProviderID = id.Provider.ID;
                }
                _database.MetadataIds <Studio>().AttachRange(resource.ExternalIDs);
            }
        }
Beispiel #6
0
        /// <inheritdoc />
        protected override async Task Validate(Show resource)
        {
            await base.Validate(resource);

            if (resource.Studio != null)
            {
                resource.Studio = await _studios.CreateIfNotExists(resource.Studio);

                resource.StudioID = resource.Studio.ID;
            }

            if (resource.Genres != null)
            {
                resource.Genres = await resource.Genres
                                  .SelectAsync(x => _genres.CreateIfNotExists(x))
                                  .ToListAsync();

                _database.AttachRange(resource.Genres);
            }

            if (resource.ExternalIDs != null)
            {
                foreach (MetadataID id in resource.ExternalIDs)
                {
                    id.Provider = _database.LocalEntity <Provider>(id.Provider.Slug)
                                  ?? await _providers.CreateIfNotExists(id.Provider);

                    id.ProviderID = id.Provider.ID;
                }
                _database.MetadataIds <Show>().AttachRange(resource.ExternalIDs);
            }

            if (resource.People != null)
            {
                foreach (PeopleRole role in resource.People)
                {
                    role.People = _database.LocalEntity <People>(role.People.Slug)
                                  ?? await _people.CreateIfNotExists(role.People);

                    role.PeopleID = role.People.ID;
                    _database.Entry(role).State = EntityState.Added;
                }
            }
        }
Beispiel #7
0
        /// <inheritdoc />
        public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken)
        {
            float percent = 0;

            progress.Report(0);

            foreach (IMetadataProvider provider in _metadataProviders)
            {
                if (string.IsNullOrEmpty(provider.Provider.Slug))
                {
                    throw new TaskFailedException($"Empty provider slug (name: {provider.Provider.Name}).");
                }
                await _providers.CreateIfNotExists(provider.Provider);

                await _thumbnails.DownloadImages(provider.Provider);

                percent += 100f / _metadataProviders.Count;
                progress.Report(percent);
            }
            progress.Report(100);
        }