private Book CreateBookFromOpf()
        {
            var book = new Book();

            ReadStringInto("//dc:title", title => book.Name             = title);
            ReadStringInto("//dc:description", summary => book.Overview = summary);
            ReadStringInto("//dc:publisher", publisher => book.AddStudio(publisher));
            ReadStringInto("//dc:identifier[@opf:scheme='ISBN']", isbn => book.SetProviderId("ISBN", isbn));
            ReadStringInto("//dc:identifier[@opf:scheme='AMAZON']", amazon => book.SetProviderId("Amazon", amazon));

            ReadStringInto("//dc:date", date =>
            {
                if (DateTime.TryParse(date, out var dateValue))
                {
                    book.PremiereDate   = dateValue.Date;
                    book.ProductionYear = dateValue.Date.Year;
                }
            });

            var genresNodes = _document.SelectNodes("//dc:subject", _namespaceManager);

            if (genresNodes != null && genresNodes.Count > 0)
            {
                foreach (var node in genresNodes.Cast <XmlNode>().Where(node => !book.Tags.Contains(node.InnerText)))
                {
                    // Adding to tags because we can't be sure the values are all genres
                    book.AddGenre(node.InnerText);
                }
            }

            ReadInt32AttributeInto("//opf:meta[@name='calibre:series_index']", index => book.IndexNumber = index);
            ReadInt32AttributeInto("//opf:meta[@name='calibre:rating']", rating => book.CommunityRating  = rating);

            var seriesNameNode = _document.SelectSingleNode("//opf:meta[@name='calibre:series']", _namespaceManager);

            if (!string.IsNullOrEmpty(seriesNameNode?.Attributes?["content"]?.Value))
            {
                try
                {
                    book.SeriesName = seriesNameNode.Attributes["content"]?.Value;
                }
                catch (Exception)
                {
                    _logger.LogError("Error parsing Calibre series name");
                }
            }

            return(book);
        }
Exemple #2
0
        private Book?ReadComicBookMetadata(ComicBookInfoMetadata comic)
        {
            var book             = new Book();
            var hasFoundMetadata = false;

            hasFoundMetadata |= ReadStringInto(comic.Title, title => book.Name = title);
            hasFoundMetadata |= ReadStringInto(comic.Series, series => book.SeriesName = series);
            hasFoundMetadata |= ReadStringInto(comic.Genre, genre => book.AddGenre(genre));
            hasFoundMetadata |= ReadStringInto(comic.Comments, overview => book.Overview = overview);
            hasFoundMetadata |= ReadStringInto(comic.Publisher, publisher => book.SetStudios(new[] { publisher }));

            if (comic.PublicationYear is not null)
            {
                book.ProductionYear = comic.PublicationYear;
                hasFoundMetadata    = true;
            }

            if (comic.Issue is not null)
            {
                book.IndexNumber = comic.Issue;
                hasFoundMetadata = true;
            }

            if (comic.Tags.Count > 0)
            {
                book.Tags        = comic.Tags.ToArray();
                hasFoundMetadata = true;
            }

            if (comic.PublicationYear is not null && comic.PublicationMonth is not null)
            {
                book.PremiereDate = ReadTwoPartDateInto(comic.PublicationYear.Value, comic.PublicationMonth.Value);
                hasFoundMetadata  = true;
            }

            if (hasFoundMetadata)
            {
                return(book);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <inheritdoc />
        public Book?ReadComicBookMetadata(XDocument xml)
        {
            var book             = new Book();
            var hasFoundMetadata = false;

            hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/Title", title => book.Name = title);
            hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/AlternateSeries", title => book.OriginalTitle = title);
            hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/Series", series => book.SeriesName = series);
            hasFoundMetadata |= ReadIntInto(xml, "ComicInfo/Number", issue => book.IndexNumber = issue);
            hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/Summary", summary => book.Overview = summary);
            hasFoundMetadata |= ReadIntInto(xml, "ComicInfo/Year", year => book.ProductionYear = year);
            hasFoundMetadata |= ReadThreePartDateInto(xml, "ComicInfo/Year", "ComicInfo/Month", "ComicInfo/Day", dateTime => book.PremiereDate = dateTime);
            hasFoundMetadata |= ReadCommaSeperatedStringsInto(xml, "ComicInfo/Genre", genres =>
            {
                foreach (var genre in genres)
                {
                    book.AddGenre(genre);
                }
            });
            hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/Publisher", publisher => book.SetStudios(new[] { publisher }));

            return(hasFoundMetadata ? book : null);
        }