Exemple #1
0
        public override IEnumerable <ExtraFile> CreateAfterAuthorScan(Author author, List <BookFile> bookFiles)
        {
            var metadataFiles = _metadataFileService.GetFilesByAuthor(author.Id);

            _cleanMetadataService.Clean(author);

            if (!_diskProvider.FolderExists(author.Path))
            {
                _logger.Info("Author folder does not exist, skipping metadata creation");
                return(Enumerable.Empty <MetadataFile>());
            }

            var files = new List <MetadataFile>();

            foreach (var consumer in _metadataFactory.Enabled())
            {
                var consumerFiles = GetMetadataFilesForConsumer(consumer, metadataFiles);

                files.AddIfNotNull(ProcessAuthorMetadata(consumer, author, consumerFiles));
                files.AddRange(ProcessAuthorImages(consumer, author, consumerFiles));

                foreach (var bookFile in bookFiles)
                {
                    files.AddIfNotNull(ProcessBookMetadata(consumer, author, bookFile, consumerFiles));
                }
            }

            _metadataFileService.Upsert(files);

            return(files);
        }
Exemple #2
0
        public void Clean(Author author)
        {
            _logger.Debug("Cleaning missing metadata files for author: {0}", author.Name);

            var metadataFiles = _metadataFileService.GetFilesByAuthor(author.Id);

            foreach (var metadataFile in metadataFiles)
            {
                if (!_diskProvider.FileExists(Path.Combine(author.Path, metadataFile.RelativePath)))
                {
                    _logger.Debug("Deleting metadata file from database: {0}", metadataFile.RelativePath);
                    _metadataFileService.Delete(metadataFile.Id);
                }
            }
        }
Exemple #3
0
        public void Clean()
        {
            if (!_configService.CleanupMetadataImages)
            {
                return;
            }

            var authors         = _authorService.AllAuthorPaths();
            var imageExtensions = new List <string> {
                ".jpg", ".png", ".gif"
            };

            foreach (var author in authors)
            {
                var images = _metaFileService.GetFilesByAuthor(author.Key)
                             .Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && imageExtensions.Any(x => c.RelativePath.EndsWith(x, StringComparison.InvariantCultureIgnoreCase)));

                foreach (var image in images)
                {
                    try
                    {
                        var path = Path.Combine(author.Value, image.RelativePath);
                        if (!IsValid(path))
                        {
                            _logger.Debug("Deleting invalid image file " + path);
                            DeleteMetadata(image.Id, path);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "Couldn't validate image {0}", image.RelativePath);
                    }
                }
            }

            _configService.CleanupMetadataImages = false;
        }