Documentation ¶
Index ¶
- Variables
- func NormalizeDate(stamp string) string
- func NormalizeISBN(isbn string) (string, error)
- func ParseTimestamp(stamp string) (t time.Time, err error)
- func Year(stamp string) string
- type Book
- func (b *Book) CheckCompleteness() error
- func (b *Book) CheckConformity() error
- func (b *Book) CheckContentSecurity() error
- func (b *Book) CleanMetadata() error
- func (b Book) CompareWith(b1 *Book) (SimilarityLevel, string)
- func (b *Book) CompleteFrom(b1 *Book)
- func (b *Book) CompleteFromMap(m map[string]string) error
- func (b *Book) GuessFromMetadata() error
- func (b Book) ISBN10() (string, error)
- func (b Book) ISBN13() (string, error)
- func (b *Book) MergeWith(b1 *Book, override bool)
- func (b *Book) PublishedYear() string
- func (b *Book) ReplaceFrom(b1 *Book)
- func (b *Book) ReplaceFromMap(m map[string]string) error
- func (b *Book) SearchOnGooglebooks(MaxResults int) ([]*Book, error)
- func (b *Book) SetAuthors(authors []string)
- func (b *Book) SetDescription(desc string)
- func (b *Book) SetISBN(isbn string)
- func (b *Book) SetLanguage(lang string)
- func (b *Book) SetPublishedDate(date string)
- type Report
- func (r Report) HasIssue() bool
- func (r Report) HasSimilarBook() bool
- func (r Report) HasWarning() bool
- func (r Report) NeedReview() bool
- func (r *Report) ReportIssue(format string, a ...interface{})
- func (r *Report) ReportSimilarBook(book *Book)
- func (r *Report) ReportWarning(format string, a ...interface{})
- type SimilarityLevel
Constants ¶
This section is empty.
Variables ¶
var ( // Verbose is the logger of book package that provides feedback of operation // done on books. Verbose = log.New(io.Discard, log.Prefix(), log.Flags()) // Debug is the logger of book package that provides information for // debugging purpose. Debug = log.New(io.Discard, log.Prefix(), log.Flags()) // ErrUnknownFormat is raised if supplied file format is unknown. ErrUnknownFormat = errors.New("unknown file format") )
Functions ¶
func NormalizeDate ¶ added in v0.2.0
NormalizeDate standardizes time stamps format using 2006-01-02 notation. If initial date is only a year, or only a year and a month, it does not substitute day or month to 01.
func NormalizeISBN ¶ added in v0.2.0
NormalizeISBN returns a cleaned ISBN_13 identifier. If isbn is in ISBN_10 format it will be converted to ISBN_13. If isbn is not a valid ISBN format, an error will be raised.
func ParseTimestamp ¶ added in v0.2.0
ParseTimestamp parses a time stamp, trying different time format.
Types ¶
type Book ¶
type Book struct { // Path is the location of the book's file in the file-system. Path string // Title is the book's title. Title string // Authors is the list names of the authors and/or editors for this book. Authors []string // ISBN is the unique industry standard identifier for this book. // libro tends to prefer ISBN_13 format when available or when it can be // derived from an ISBN_10. ISBN10 and ISBN13 methods can be invoked to // convert from one format to the other. // Most Book's functions dealing with ISBN will better work if ISBN is // 'normalized' using Book.SetISBN. ISBN string `json:",omitempty"` // AlternateISBN contains a list of alternate ISBN that are related to the // Book, like ISBN of the same book but corresponding to a different // edition or a different edition support. // This property is mostly here to support Book's metadata guessing // heuristic. AlternateISBN []string `json:",omitempty"` // SubTitle is the book's sub-title. SubTitle string `json:",omitempty"` // Publisher is the publisher of this book. Publisher string `json:",omitempty"` // PublishedDate is the date of publication of this book. // `libro` tries to normalize dates using '2006-01-02' format. When // 'precision' of date is not enough to capture known month or days, date // is cut to '2006-01' or simply to '2006'. // Most Book's functions dealing with Date will better work if Date is // 'normalized' using Book.SetPublishedDate. PublishedDate string `json:",omitempty"` // Description is the synopsis of the book. The text of the description // is formatted in HTML and includes simple formatting elements. Description string `json:",omitempty"` // Series is the series to which this book belongs to. Series string `json:",omitempty"` // SeriesIndex is the position in the series to which the book belongs to. SeriesIndex float64 `json:",omitempty"` // SeriesTitle is the book's title in the series (without Series nor // SubTitle information). SeriesTitle string `json:",omitempty"` // Language is the book's language. It is the two-letter ISO 639-1 code // such as 'fr', 'en'. Language string `json:",omitempty"` // PageCount is total number of pages of this book. PageCount int64 `json:",omitempty"` // Subject is the list of subject categories, such as "Fiction", // "Suspense". Subject []string `json:",omitempty"` // ToReview collects messages that report events encountered during Book's // processing that deserve end-user attention. *Report }
Book represents a book.
func NewFromContent ¶ added in v0.4.0
NewFromContent creates a Book whose information are guessed from its Content.
func NewFromEpub ¶ added in v0.2.0
NewFromEpub create a Book by populating information out of an EPUB file's Metadata.
func NewFromFile ¶
NewFromFile creates a new Book and populates its information according to the file's metadata.
func NewFromFilename ¶ added in v0.4.0
NewFromFilename creates a Book whose information are guessed from its filename.
func NewFromMap ¶ added in v0.2.0
NewFromMap creates a Book's from to the attributes defined as a map where keys are attribute's name (insensitive to case) and value is a string representation of the attribute's value. For attributes that accept a list of values (like Authors or Subject), provided map value should be formatted like "val0 & val1" (individual value in as string separated by '&').
func (*Book) CheckCompleteness ¶ added in v0.4.2
CheckCompletness assesses whether Book has enough Metadata to be identified by the end-user.
func (*Book) CheckConformity ¶ added in v0.4.2
CheckConformity uses EPUBcheck to verify that the book complies with EPUB specification so that it will likely be properly rendered by most reading systems.
func (*Book) CheckContentSecurity ¶ added in v0.4.0
CheckContentSecurity verifies that Book's content does not contain unsafe HTML.
func (*Book) CleanMetadata ¶ added in v0.3.0
CleanMetadata cleans Book's metadata.
func (Book) CompareWith ¶ added in v0.4.0
func (b Book) CompareWith(b1 *Book) (SimilarityLevel, string)
CompareWith assesses the similarity level between two books with a short explanation of the rational.
func (*Book) CompleteFrom ¶ added in v0.2.0
CompleteFrom completes Book's attributes by setting empty values to the corresponding value of the provided 'b1' Book. CompleteFrom is a shortcut to call MergeWith with override set to false.
func (*Book) CompleteFromMap ¶ added in v0.2.0
CompleteFromMap completes Book's attributes by setting empty values to the corresponding value of the provided map. map format is similar to NewFromMap.
func (*Book) GuessFromMetadata ¶ added in v0.2.0
GuessFromMetadata tries to guess Book's information based on known attributes (like Book's Title).
func (Book) ISBN10 ¶ added in v0.2.1
ISBN10 returns the ISBN_10 identifier of Book. ISBN10 assumes that b.ISBN is a "cleaned" ISBN (only digits, no '-' or things like that)
func (Book) ISBN13 ¶ added in v0.2.1
ISBN13 returns the ISBN_13 identifier of Book. ISBN13 assumes that b.ISBN is a "cleaned" ISBN (only digits, no '-' or things like that)
func (*Book) MergeWith ¶ added in v0.2.0
MergeWith merges Book with 'b1' Book. If override is set, Book's attributes are replaced by the none-empty corresponding attribute of 'b1' Book.
func (*Book) PublishedYear ¶ added in v0.4.1
PublishedYear returns the year of publication. Returns an empty string if Book's PublishedDate is empty or if its format cannot be recognized.
func (*Book) ReplaceFrom ¶ added in v0.2.0
ReplaceFrom completes and replaces Book's attributes using the non-empty corresponding value of the provided 'b1' Book. ReplaceFrom is a shortcut to call MergeWith with override set to true.
func (*Book) ReplaceFromMap ¶ added in v0.2.0
ReplaceFromMap completes and replaces Book's attributes using the non-empty corresponding value of the provided map. map format is similar to NewFromMap.
func (*Book) SearchOnGooglebooks ¶ added in v0.4.0
SearchOnGooglebooks search Googlebooks for the Book. At most MaxResults Books are returned.
func (*Book) SetAuthors ¶ added in v0.2.1
SetAuthors sets Book's Authors and tries to keep Authors' names and surnames in a pre-defined order.
func (*Book) SetDescription ¶ added in v0.4.0
SetDescription sets Book's Description and tries to clean it from un-helping HTML formatting directives.
func (*Book) SetISBN ¶ added in v0.2.1
SetISBN sets Book's ISBN and tries to normalize it to ISBN_13 format. SetISBN reports non-recognized ISBN but do not fail.
func (*Book) SetLanguage ¶ added in v0.4.1
SetLanguage sets Book's Language and tries to filter exotic language names.
func (*Book) SetPublishedDate ¶ added in v0.2.1
SetPublishedDate sets Book's PublishedDate and tries to normalize its format.
type Report ¶ added in v0.2.1
type Report struct { // Issues collects messages that report events encountered during Book's // processing that deserve end-user attention. Issues []string `json:",omitempty"` // Warnings collects messages that report events encountered during Book's // processing that might deserve end-user attention. Warnings []string `json:",omitempty"` // SimilarBooks collects alternative Book's metadata that are possibly // better or more complete than actual metada set. `libro`is for some reasons // usually not sure enough whether they are corresponding to exactly the // same book. SimilarBooks []*Book `json:",omitempty"` }
Report represents a set of indications about libro's automatic or semi-automatic activities to the end-user that deserve attention or arbitration.
func (Report) HasIssue ¶ added in v0.4.1
HasIssue returns whether Report contains at least one Issue.
func (Report) HasSimilarBook ¶ added in v0.4.1
HasSimilarBook returns whether Report contains at least one similar Book.
func (Report) HasWarning ¶ added in v0.4.1
HasWarning returns whether Report contains at least one Warning.
func (Report) NeedReview ¶ added in v0.2.1
NeedReview returns whether Report contains messages that benefit from a end-user review.
func (*Report) ReportIssue ¶ added in v0.2.1
ReportIssue reports a (possible) issue encountered during Book's processing that deserves end-user attention.
func (*Report) ReportSimilarBook ¶ added in v0.2.1
ReportSimilarBook reports possible similar Book.
func (*Report) ReportWarning ¶ added in v0.4.1
ReportWarning reports a (possible) issue encountered during Book's processing that light deserves end-user attention.
type SimilarityLevel ¶ added in v0.4.0
type SimilarityLevel int
SimilarityLevel indicate the similarity level between two elements.
const ( // AreNotComparable indicates that two elements are not comparable. AreNotComparable SimilarityLevel = iota // AreNotTheSame indicates that two elements are different. AreNotTheSame // AreMaybeTheSame indicates that two elements are maybe the same. AreMaybeTheSame // AreAlmostTheSame indicates that elements are almost the same. AreAlmostTheSame // AreTheSame indicates that elements are the same. AreTheSame )
func (SimilarityLevel) String ¶ added in v0.4.0
func (lvl SimilarityLevel) String() string
String outputs a human understandable description of a SimilarityLevel.