book

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2022 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 CompareNormalizedDate added in v0.2.0

func CompareNormalizedDate(date1, date2 string) (string, bool)

CompareNormalizedDate compares two 'normalized' date and returns the most 'precise' one in case of equality.

func NormalizeDate added in v0.2.0

func NormalizeDate(stamp string) string

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

func NormalizeISBN(isbn string) (string, error)

NormalizeISBN returns a cleaned ISBN_13 identifier. If isbn is in ISBN_10 format it will be converted to ISBN_13. If isbn is in a non-supported format, the 'cleaned' ISBN is returned and an error will be raised.

func ParseTimestamp added in v0.2.0

func ParseTimestamp(stamp string) (t time.Time, err error)

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.
	// Most Book's functions dealing with ISBN will better work if ISBN is
	// 'normalized' using book.NormalizeISBN.
	ISBN 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.
	// Most Book's functions dealing with Date will better work if Date is
	// 'normalized' using book.NormalizeDate.
	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 th eseries (whithout 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"`
}

Book represents a book.

func New

func New() *Book

New creates a new Book

func NewFromEpub added in v0.2.0

func NewFromEpub(path string) (*Book, error)

NewFromEpub create a Book by populating information out of an EPUB file's Metadata.

func NewFromFile

func NewFromFile(path string) (*Book, error)

NewFromFile creates a new Book and populates its information according to the file's metadata.

func NewFromMap added in v0.2.0

func NewFromMap(m map[string]string) (*Book, error)

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) CompleteFrom added in v0.2.0

func (b *Book) CompleteFrom(b1 *Book)

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

func (b *Book) CompleteFromMap(m map[string]string) error

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) FromGooglebooks added in v0.2.0

func (b *Book) FromGooglebooks() error

FromGooglebooks gets Book's metadata from Googlebooks. If searching Googlebooks successfully found a Book with same ISBN, Book's metadata are superseded by Googlebooks' one, otherwise the best match is use to complete Book's metada.

func (*Book) GuessFromFilename added in v0.2.0

func (b *Book) GuessFromFilename() error

GuessFromFilename tries to guess Book's information based on its filename.

func (*Book) GuessFromMetadata added in v0.2.0

func (b *Book) GuessFromMetadata() error

GuessFromMetadata tries to guess Book's information based on known attributes (like Book's Title).

func (*Book) IsComplete

func (b *Book) IsComplete() bool

IsComplete gives an evaluation whether a Book's information seems complete enough. Objective is to provide a way for the tool to decide whether a human intervention is a good idea.

func (*Book) MergeWith added in v0.2.0

func (b *Book) MergeWith(b1 *Book, override bool)

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) ReplaceFrom added in v0.2.0

func (b *Book) ReplaceFrom(b1 *Book)

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

func (b *Book) ReplaceFromMap(m map[string]string) error

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) SearchGooglebooks added in v0.2.0

func (b Book) SearchGooglebooks() ([]*Book, error)

SearchGooglebooks search Googlebooks for same or similar Books.

func (Book) String

func (b Book) String() string

String proposes an easy-to-read raw representation of a Book.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL