book

package
v0.0.0-...-725ffc3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2016 License: GPL-3.0 Imports: 24 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func CheckValidField(field string) (valid bool)

CheckValidField checks if a field is valid.

func CheckValidSortOrder

func CheckValidSortOrder(sortBy string) (valid bool)

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

func IDIsIn

func IDIsIn(a int, known []int) bool

IDIsIn checks if an id is known

func SortBooks

func SortBooks(books []Book, orderBy string)

SortBooks using a specific field.

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 NewBook

func NewBook(ui i.UserInterface, id int, filename string, c e.Config, isRetail bool) *Book

NewBook constructs a valid new Epub

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) AddEpub

func (b *Book) AddEpub(path string, isRetail bool, hash string) (imported bool, err error)

AddEpub to the Library

func (*Book) AddIDToDiff

func (b *Book) AddIDToDiff(rowsIn [][]string) [][]string

AddIDToDiff returns a DiffTable with ID

func (*Book) Check

func (b *Book) Check() (retailHasChanged bool, nonRetailHasChanged bool, err error)

Check epubs integrity.

func (*Book) CleanFilename

func (b *Book) CleanFilename() string

CleanFilename returns a filename

func (*Book) EditField

func (b *Book) EditField(args ...string) error

EditField in current Metadata associated with the Book.

func (*Book) ForceMetadataFieldRefresh

func (b *Book) ForceMetadataFieldRefresh(field string) (err error)

ForceMetadataFieldRefresh overwrites current Metadata for a specific field only.

func (*Book) ForceMetadataRefresh

func (b *Book) ForceMetadataRefresh() (err error)

ForceMetadataRefresh overwrites current Metadata

func (*Book) FromJSON

func (b *Book) FromJSON(jsonBytes []byte) (err error)

FromJSON fills the Epub info from JSON text.

func (*Book) FullPath

func (b *Book) FullPath() string

FullPath of the main Epub of a Book.

func (*Book) Get

func (b *Book) Get(field string) (value string, err error)

Get Book field value

func (*Book) HasEpub

func (b *Book) HasEpub() bool

HasEpub checks if the book has at least one epub

func (*Book) HasHash

func (b *Book) HasHash(hash string) bool

HasHash returns true if it is associated with an Epub with the given hash, according to the GenericBook interface

func (*Book) HasNonRetail

func (b *Book) HasNonRetail() bool

HasNonRetail checks if a non-retail epub is available.

func (*Book) HasRetail

func (b *Book) HasRetail() bool

HasRetail checks if a retail epub is available.

func (*Book) ID

func (b *Book) ID() int

ID returns the Books ID according to the GenericBook interface

func (*Book) Import

func (b *Book) Import(path string, isRetail bool, hash string) (imported bool, err error)

Import an Epub to the Library

func (*Book) JSON

func (b *Book) JSON() (JSONPart string, err error)

JSON returns a JSON representation of the Epub and its metadata.

func (*Book) LongString

func (b *Book) LongString() string

LongString returns a long string representation of Epub

func (*Book) MainEpub

func (b *Book) MainEpub() *Epub

MainEpub of a Book.

func (*Book) OutputDiffTable

func (b *Book) OutputDiffTable(o *Book, diffOnly bool) [][]string

OutputDiffTable returns differences between Books.

func (*Book) Refresh

func (b *Book) Refresh() (wasRenamed []bool, newName []string, err error)

Refresh the filenames of the Epubs associated with this Book.

func (*Book) RefreshEpub

func (b *Book) RefreshEpub(epub Epub, isRetail bool) (bool, string, error)

RefreshEpub one specific epub associated with this Book

func (*Book) Set

func (b *Book) Set(field, value string) error

Set a field value for Book or Metadata

func (*Book) SetExported

func (b *Book) SetExported(isExported bool)

SetExported set the main Epub as exported

func (*Book) SetProgress

func (b *Book) SetProgress(progress string) (err error)

SetProgress sets reading progress

func (*Book) SetReadDate

func (b *Book) SetReadDate(date string)

SetReadDate sets date when finished reading

func (*Book) SetReadDateToday

func (b *Book) SetReadDateToday()

SetReadDateToday sets date when finished reading

func (*Book) ShowInfo

func (b *Book) ShowInfo(fields ...string) string

ShowInfo returns a table with relevant information about a book.

func (*Book) String

func (b *Book) String() string

String returns a string representation of Epub

type Books

type Books []Book

Books is a slice of Book.

func (*Books) Add

func (bks *Books) Add(books ...e.GenericBook)

Add a Book

func (*Books) Authors

func (bks *Books) Authors() (authors map[string]int)

Authors among known epubs.

func (*Books) Books

func (bks *Books) Books() []e.GenericBook

Books returns GenericBooks

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) Exported

func (bks *Books) Exported() e.Collection

Exported among 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) First

func (bks Books) First(nb int) e.Collection

First books

func (*Books) Incomplete

func (bks *Books) Incomplete() e.Collection

Incomplete among Books.

func (Books) Last

func (bks Books) Last(nb int) e.Collection

Last 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

func (bks *Books) Publishers() (publishers map[string]int)

Publishers among known epubs.

func (*Books) RemoveByID

func (bks *Books) RemoveByID(id int) (err error)

RemoveByID a book

func (*Books) Retail

func (bks *Books) Retail() e.Collection

Retail among Books.

func (*Books) Series

func (bks *Books) Series() (series map[string]int)

Series associated with known epubs.

func (Books) Sort

func (bks Books) Sort(sortBy string)

Sort books

func (Books) Table

func (bks Books) Table() string

Table of books

func (*Books) Tags

func (bks *Books) Tags() (tags map[string]int)

Tags associated with known epubs.

func (*Books) WithID

func (bks *Books) WithID(ids ...int) e.Collection

WithID among Books.

type By

type By func(p1, p2 *Book) bool

By is the type of a "less" function that defines the ordering of its Book arguments.

func (By) Sort

func (by By) Sort(books []Book)

Sort is a method on the function type, By, that sorts the argument slice according to the function.

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) Check

func (e *Epub) Check() (hasChanged bool, err error)

Check the retail epub integrity.

func (*Epub) FlagForReplacement

func (e *Epub) FlagForReplacement(flag bool)

FlagForReplacement an epub of insufficient quality

func (*Epub) FullPath

func (e *Epub) FullPath() string

FullPath returns the absolute file path. if it is in the library, prepends LibraryRoot. if it is outside, return Filename directly.

func (*Epub) GetHash

func (e *Epub) GetHash() (err error)

GetHash calculates an epub's current hash

func (*Epub) ReadMetadata

func (e *Epub) ReadMetadata() (info Metadata, err error)

ReadMetadata from epub file

type GoodReads

type GoodReads struct {
}

GoodReads implements RemoteLibraryAPI and retrieves information from goodreads.com.

func (GoodReads) GetBook

func (g GoodReads) GetBook(id, key string) (Metadata, error)

GetBook returns a GoodreadsBook from its Goodreads ID

func (GoodReads) GetBookIDByISBN

func (g GoodReads) GetBookIDByISBN(isbn, key string) (id string, err error)

GetBookIDByISBN gets a Goodreads ID from an ISBN

func (GoodReads) GetBookIDByQuery

func (g GoodReads) GetBookIDByQuery(author, title, key string) (id string, err error)

GetBookIDByQuery gets a Goodreads ID from a query

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) Author

func (i *Metadata) Author() string

Author returns Metadata's main author.

func (*Metadata) Clean

func (i *Metadata) Clean(cfg e.Config)

Clean cleans up the Metadata

func (*Metadata) Diff

func (i *Metadata) Diff(o *Metadata, firstHeader, secondHeader string) string

Diff returns differences between Metadatas.

func (*Metadata) Get

func (i *Metadata) Get(field string) (string, error)

Get Metadata field value

func (*Metadata) HasAny

func (i *Metadata) HasAny() bool

HasAny checks if metadata was parsed.

func (*Metadata) IsComplete

func (i *Metadata) IsComplete() bool

IsComplete checks if metadata looks complete

func (*Metadata) IsSimilar

func (i *Metadata) IsSimilar(o Metadata) bool

IsSimilar checks if metadata is similar to known Metadata.

func (*Metadata) MainSeries

func (i *Metadata) MainSeries() SingleSeries

MainSeries return the main Series of Metadata.

func (*Metadata) Merge

func (i *Metadata) Merge(o *Metadata, cfg e.Config, ui i.UserInterface, diffOnly bool) (err error)

Merge with another 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

func (i *Metadata) OutputDiffTable(o *Metadata, diffOnly bool) [][]string

OutputDiffTable returns differences between Metadatas.

func (*Metadata) SearchOnline

func (i *Metadata) SearchOnline(ui i.UserInterface, cfg e.Config, fields ...string) (err error)

SearchOnline tries to find metadata from online sources.

func (*Metadata) Set

func (i *Metadata) Set(field, value string) error

Set Metadata field with a string value

func (*Metadata) String

func (i *Metadata) String() string

String returns a representation of Metadata

func (*Metadata) Title

func (i *Metadata) Title() string

Title returns Metadata's main title.

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

func (s *Series) AddFromString(candidate string) (seriesModified bool, err error)

AddFromString a series, checking for correct form.

func (*Series) Has

func (s *Series) Has(seriesName string) (hasSeries bool, index int, position string)

Has checks if epub is part of a series

func (*Series) HasAny

func (s *Series) HasAny() bool

HasAny checks if epub is part of any series

func (Series) String

func (s Series) String() string

String outputs a series info.

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) Add

func (t *Tags) Add(tags ...Tag) (added bool)

Add Tags to the list

func (*Tags) AddFromNames

func (t *Tags) AddFromNames(tags ...string) bool

AddFromNames Tags to the list, from []string

func (*Tags) Clean

func (t *Tags) Clean()

Clean a list of tags.

func (*Tags) Has

func (t *Tags) Has(o Tag) (isIn bool, index int)

Has finds out if a Tag is already in list.

func (*Tags) HasAny

func (t *Tags) HasAny() bool

HasAny checks if epub is part of any series

func (*Tags) Remove

func (t *Tags) Remove(tags ...Tag) (removed bool)

Remove Tags from the list

func (*Tags) RemoveFromNames

func (t *Tags) RemoveFromNames(tags ...string) bool

RemoveFromNames Tags to the list, from []string

func (Tags) String

func (t Tags) String() string

String give a string representation of Tags.

Jump to

Keyboard shortcuts

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