Documentation ¶
Overview ¶
Package book is a subpackage of Endive, that aims to manipulate epub files and their metadata.
A Book can hold at most 2 epubs: a retail version and/or a non-retail version.
Book Metadata starts with epub Metadata, and holds additionnal information retrieved from online sources (ie, Goodreads).
The Book struct controls where the files are and how they are named.
Index ¶
- Variables
- func CheckValidField(field string) (valid bool)
- func CheckValidSortOrder(sortBy string) (valid bool)
- func CleanSliceAndTagEntries(ui i.UserInterface, local, remote string, options *[]string, ...)
- func IDIsIn(a int, known []int) bool
- func SortBooks(books []Book, orderBy string)
- type Book
- func (b *Book) AddEpub(path string, isRetail bool, hash string) (imported bool, err error)
- func (b *Book) AddIDToDiff(rowsIn [][]string) [][]string
- func (b *Book) Check() (retailHasChanged bool, nonRetailHasChanged bool, err error)
- func (b *Book) CleanFilename() string
- func (b *Book) EditField(args ...string) error
- func (b *Book) ForceMetadataFieldRefresh(field string) (err error)
- func (b *Book) ForceMetadataRefresh() (err error)
- func (b *Book) FromJSON(jsonBytes []byte) (err error)
- func (b *Book) FullPath() string
- func (b *Book) Get(field string) (value string, err error)
- func (b *Book) HasEpub() bool
- func (b *Book) HasHash(hash string) bool
- func (b *Book) HasNonRetail() bool
- func (b *Book) HasRetail() bool
- func (b *Book) ID() int
- func (b *Book) Import(path string, isRetail bool, hash string) (imported bool, err error)
- func (b *Book) JSON() (JSONPart string, err error)
- func (b *Book) LongString() string
- func (b *Book) MainEpub() *Epub
- func (b *Book) OutputDiffTable(o *Book, diffOnly bool) [][]string
- func (b *Book) Refresh() (wasRenamed []bool, newName []string, err error)
- func (b *Book) RefreshEpub(epub Epub, isRetail bool) (bool, string, error)
- func (b *Book) Set(field, value string) error
- func (b *Book) SetExported(isExported bool)
- func (b *Book) SetProgress(progress string) (err error)
- func (b *Book) SetReadDate(date string)
- func (b *Book) SetReadDateToday()
- func (b *Book) ShowInfo(fields ...string) string
- func (b *Book) String() string
- type Books
- func (bks *Books) Add(books ...e.GenericBook)
- func (bks *Books) Authors() (authors map[string]int)
- func (bks *Books) Books() []e.GenericBook
- func (bks Books) Diff(o e.Collection, newB e.Collection, modifiedB e.Collection, ...)
- func (bks *Books) Exported() e.Collection
- func (bks *Books) FindByFullPath(filename string) (e.GenericBook, error)
- func (bks *Books) FindByHash(hash string) (e.GenericBook, error)
- func (bks *Books) FindByID(id int) (e.GenericBook, error)
- func (bks *Books) FindByMetadata(isbn, authors, title string) (e.GenericBook, error)
- func (bks Books) First(nb int) e.Collection
- func (bks *Books) Incomplete() e.Collection
- func (bks Books) Last(nb int) e.Collection
- func (bks *Books) NonRetailOnly() e.Collection
- func (bks *Books) Progress(progress string) e.Collection
- func (bks *Books) Propagate(ui i.UserInterface, c e.Config)
- func (bks *Books) Publishers() (publishers map[string]int)
- func (bks *Books) RemoveByID(id int) (err error)
- func (bks *Books) Retail() e.Collection
- func (bks *Books) Series() (series map[string]int)
- func (bks Books) Sort(sortBy string)
- func (bks Books) Table() string
- func (bks *Books) Tags() (tags map[string]int)
- func (bks *Books) WithID(ids ...int) e.Collection
- type By
- type Epub
- type GoodReads
- type Metadata
- func (i *Metadata) Author() string
- func (i *Metadata) Clean(cfg e.Config)
- func (i *Metadata) Diff(o *Metadata, firstHeader, secondHeader string) string
- func (i *Metadata) Get(field string) (string, error)
- func (i *Metadata) HasAny() bool
- func (i *Metadata) IsComplete() bool
- func (i *Metadata) IsSimilar(o Metadata) bool
- func (i *Metadata) MainSeries() SingleSeries
- func (i *Metadata) Merge(o *Metadata, cfg e.Config, ui i.UserInterface, diffOnly bool) (err error)
- func (i *Metadata) MergeField(o *Metadata, field string, cfg e.Config, ui i.UserInterface, diffOnly bool) (err error)
- func (i *Metadata) OutputDiffTable(o *Metadata, diffOnly bool) [][]string
- func (i *Metadata) SearchOnline(ui i.UserInterface, cfg e.Config, fields ...string) (err error)
- func (i *Metadata) Set(field, value string) error
- func (i *Metadata) String() string
- func (i *Metadata) Title() string
- type RemoteLibraryAPI
- type Series
- type SingleSeries
- type Tag
- type Tags
- func (t *Tags) Add(tags ...Tag) (added bool)
- func (t *Tags) AddFromNames(tags ...string) bool
- func (t *Tags) Clean()
- func (t *Tags) Has(o Tag) (isIn bool, index int)
- func (t *Tags) HasAny() bool
- func (t *Tags) Remove(tags ...Tag) (removed bool)
- func (t *Tags) RemoveFromNames(tags ...string) bool
- func (t Tags) String() string
Constants ¶
This section is empty.
Variables ¶
var MetadataFieldNames = []string{authorField, titleField, yearField, editionYearField, publisherField, descriptionField, languageField, categoryField, typeField, genreField, tagsField, seriesField, isbnField}
MetadataFieldNames is a list of valid field names
Functions ¶
func CheckValidField ¶
CheckValidField checks if a field is valid.
func CheckValidSortOrder ¶
CheckValidSortOrder checks if a sorting field is valid.
func CleanSliceAndTagEntries ¶
func CleanSliceAndTagEntries(ui i.UserInterface, local, remote string, options *[]string, otherStringsToClean ...string)
CleanSliceAndTagEntries as remote or local among a list
Types ¶
type Book ¶
type Book struct { Config e.Config `json:"-"` UI i.UserInterface `json:"-"` BookID int `json:"id"` // associated files RetailEpub Epub `json:"retail"` NonRetailEpub Epub `json:"nonretail"` // metadata Metadata Metadata `json:"metadata"` // user info Progress string `json:"progress"` ReadDate string `json:"readdate"` Rating string `json:"rating"` Review string `json:"review"` IsExported string `json:"exported"` }
Book can manipulate a book. A Book can have multiple epub files.
func NewBookWithMetadata ¶
func NewBookWithMetadata(ui i.UserInterface, id int, filename string, c e.Config, isRetail bool, i Metadata) *Book
NewBookWithMetadata constructs a valid new Epub
func (*Book) AddIDToDiff ¶
AddIDToDiff returns a DiffTable with ID
func (*Book) ForceMetadataFieldRefresh ¶
ForceMetadataFieldRefresh overwrites current Metadata for a specific field only.
func (*Book) ForceMetadataRefresh ¶
ForceMetadataRefresh overwrites current Metadata
func (*Book) HasHash ¶
HasHash returns true if it is associated with an Epub with the given hash, according to the GenericBook interface
func (*Book) HasNonRetail ¶
HasNonRetail checks if a non-retail epub is available.
func (*Book) LongString ¶
LongString returns a long string representation of Epub
func (*Book) OutputDiffTable ¶
OutputDiffTable returns differences between Books.
func (*Book) RefreshEpub ¶
RefreshEpub one specific epub associated with this Book
func (*Book) SetExported ¶
SetExported set the main Epub as exported
func (*Book) SetProgress ¶
SetProgress sets reading progress
func (*Book) SetReadDate ¶
SetReadDate sets date when finished reading
func (*Book) SetReadDateToday ¶
func (b *Book) SetReadDateToday()
SetReadDateToday sets date when finished reading
type Books ¶
type Books []Book
Books is a slice of Book.
func (Books) Diff ¶
func (bks Books) Diff(o e.Collection, newB e.Collection, modifiedB e.Collection, deletedB e.Collection)
Diff detects differences between two sets of Books.
func (*Books) FindByFullPath ¶
func (bks *Books) FindByFullPath(filename string) (e.GenericBook, error)
FindByFullPath among known Books
func (*Books) FindByHash ¶
func (bks *Books) FindByHash(hash string) (e.GenericBook, error)
FindByHash among known Books
func (*Books) FindByID ¶
func (bks *Books) FindByID(id int) (e.GenericBook, error)
FindByID among known Books
func (*Books) FindByMetadata ¶
func (bks *Books) FindByMetadata(isbn, authors, title string) (e.GenericBook, error)
FindByMetadata among known Books
func (*Books) NonRetailOnly ¶
func (bks *Books) NonRetailOnly() e.Collection
NonRetailOnly among Books.
func (*Books) Progress ¶
func (bks *Books) Progress(progress string) e.Collection
Progress among Books.
func (*Books) Propagate ¶
func (bks *Books) Propagate(ui i.UserInterface, c e.Config)
Propagate for all Books to be aware of Config and UI.
func (*Books) Publishers ¶
Publishers among known epubs.
type Epub ¶
type Epub struct { Config en.Config `json:"-"` UI i.UserInterface `json:"-"` Filename string `json:"filename"` // relative to LibraryRoot Hash string `json:"hash"` NeedsReplacement string `json:"replace"` }
Epub can manipulate an epub file.
func (*Epub) FlagForReplacement ¶
FlagForReplacement an epub of insufficient quality
func (*Epub) FullPath ¶
FullPath returns the absolute file path. if it is in the library, prepends LibraryRoot. if it is outside, return Filename directly.
func (*Epub) ReadMetadata ¶
ReadMetadata from epub file
type GoodReads ¶
type GoodReads struct { }
GoodReads implements RemoteLibraryAPI and retrieves information from goodreads.com.
func (GoodReads) GetBookIDByISBN ¶
GetBookIDByISBN gets a Goodreads ID from an ISBN
type Metadata ¶
type Metadata struct { BookTitle string `json:"title" xml:"title"` ImageURL string `json:"image_url" xml:"image_url"` NumPages string `json:"num_pages" xml:"num_pages"` Authors []string `json:"authors" xml:"authors>author>name"` ISBN string `json:"isbn" xml:"isbn13"` OriginalYear string `json:"year" xml:"work>original_publication_year"` EditionYear string `json:"edition_year" xml:"publication_year"` Description string `json:"description" xml:"description"` Series Series `json:"series" xml:"series_works>series_work"` AverageRating string `json:"average_rating" xml:"average_rating"` Tags Tags `json:"tags" xml:"popular_shelves>shelf"` Category string `json:"category"` Type string `json:"type"` Genre string `json:"genre"` Language string `json:"language" xml:"language_code"` Publisher string `json:"publisher" xml:"publisher"` }
Metadata contains all of the known book metadata.
func (*Metadata) IsComplete ¶
IsComplete checks if metadata looks complete
func (*Metadata) MainSeries ¶
func (i *Metadata) MainSeries() SingleSeries
MainSeries return the main Series of Metadata.
func (*Metadata) MergeField ¶
func (i *Metadata) MergeField(o *Metadata, field string, cfg e.Config, ui i.UserInterface, diffOnly bool) (err error)
MergeField with another Metadata.
func (*Metadata) OutputDiffTable ¶
OutputDiffTable returns differences between Metadatas.
func (*Metadata) SearchOnline ¶
SearchOnline tries to find metadata from online sources.
type RemoteLibraryAPI ¶
type RemoteLibraryAPI interface { GetBook(id, key string) (Metadata, error) GetBookIDByQuery(author, title, key string) (id string, err error) GetBookIDByISBN(isbn, key string) (id string, err error) }
RemoteLibraryAPI is the interface for accessing remote library information.
type Series ¶
type Series []SingleSeries
Series can track a series and an epub's position.
func (*Series) AddFromString ¶
AddFromString a series, checking for correct form.
type SingleSeries ¶
type SingleSeries struct { Name string `json:"name" xml:"series>title"` Position string `json:"index" xml:"user_position"` }
SingleSeries holds the name and index of a series a Book is part of.
func (SingleSeries) String ¶
func (s SingleSeries) String() string
String outputs a single series info.
type Tag ¶
type Tag struct {
Name string `json:"name" xml:"name,attr"`
}
Tag holds the name of a tag.
type Tags ¶
type Tags []Tag
Tags can track a book's Tags
func (*Tags) AddFromNames ¶
AddFromNames Tags to the list, from []string
func (*Tags) RemoveFromNames ¶
RemoveFromNames Tags to the list, from []string