Documentation
¶
Index ¶
- Variables
- func ByteCountSI(b int64) string
- func CreateLibrary(filename string) error
- func Escape(filename string) string
- func GetUniqueName(f string, currentFilename string) (string, error)
- func JoinNaturally(conjunction string, items []string) string
- func TruncateFilename(fn string) string
- type Book
- type BookExistsError
- type BookFile
- type EpubMetadataParser
- type Library
- func (lib *Library) ConvertToEpub(file BookFile) error
- func (lib *Library) GetBookIDByFilename(fn string) (int64, error)
- func (lib *Library) GetBookIDByTitleAndAuthors(title string, authors []string) (int64, bool, error)
- func (lib *Library) GetBooksByHash(hash string) ([]Book, error)
- func (lib *Library) GetBooksByID(ids []int64) ([]Book, error)
- func (lib *Library) GetFilesByID(ids []int64) ([]BookFile, error)
- func (lib *Library) ImportBook(book Book, tmpl *template.Template, move bool) error
- func (lib *Library) MergeBooks(ids []int64, tmpl *template.Template) error
- func (lib *Library) Search(terms string) ([]Book, error)
- func (lib *Library) SearchPaged(terms string, offset, limit, moreResultsLimit int) (books []Book, moreResults int, err error)
- func (lib *Library) UpdateBook(book Book, tmpl *template.Template, overwriteSeries bool) error
- type MetadataParser
- type RegexpMetadataParser
Constants ¶
This section is empty.
Variables ¶
var ErrBookNotFound = errors.New("book not found")
ErrBookNotFound is returned when a book is not found in the database.
Functions ¶
func ByteCountSI ¶
ByteCountSI returns a human-readable string in SI (decimal) format from the provided size in bytes.
func CreateLibrary ¶
CreateLibrary initializes a new library in the specified file. Once CreateLibrary is called, the file will be ready to open and accept new books. Warning: This function sets up a new library for the first time. To get a Library based on an existing library file, call OpenLibrary.
func GetUniqueName ¶
GetUniqueName checks to see if a file named f already exists, and if so, finds a unique name. If, while finding a new name, the current filename is matched, just return the current filename.
func JoinNaturally ¶
JoinNaturally joins a slice of strings separated by a comma and space, putting the conjunction before the last item. If there are only two items, they will be separated by the conjunction (surrounded by spaces), with no comma. Examples: first item first item and second item first item, second item, and third item
func TruncateFilename ¶
TruncateFilename truncates each path segment to 255 bytes. The filename portion is truncated to 250 bytes to leave room for getUniqueFilename, and bytes are removed just before the extension.
Types ¶
type Book ¶
Book represents a book in a library.
func ParseFilename ¶
ParseFilename creates a new Book given a filename and regular expression. The named groups author, title, series, and extension in the regular expression will map to their respective fields in the resulting book.
type BookExistsError ¶
type BookExistsError struct { BookID int64 // contains filtered or unexported fields }
BookExistsError is returned by UpdateBook when a book with the given title and authors already exists in the database, and is not the one we're trying to update.
func (BookExistsError) Error ¶
func (bee BookExistsError) Error() string
type BookFile ¶
type BookFile struct { ID int64 Extension string Tags []string Hash string OriginalFilename string CurrentFilename string FileMtime time.Time FileSize int64 Source string }
BookFile represents a file linked to a book.
func (*BookFile) CalculateHash ¶
CalculateHash calculates the hash of b.OriginalFilename and updates book.Hash. If a value is stored in the user.hash xattr, that value will be used instead of hashing the file's contents.
type EpubMetadataParser ¶
type EpubMetadataParser struct{}
EpubMetadataParser parses files using EPUB metadata.
type Library ¶
Library represents a set of books in persistent storage.
func OpenLibrary ¶
OpenLibrary opens a library stored in a file.
func (*Library) ConvertToEpub ¶
ConvertToEpub converts a file to epub, and caches it in LIBRARY_ROOT/cache. This depends on ebook-convert, which takes the original filename, and the new filename, in that order. the file's hash, with the extension .epub, will be the name of the cached file.
func (*Library) GetBookIDByFilename ¶
GetBookIDByFilename returns a book ID given a filename relative to books root.
func (*Library) GetBookIDByTitleAndAuthors ¶
GetBookIDByTitleAndAuthors gets an existing book ID with the given title and authors.
func (*Library) GetBooksByHash ¶
GetBooksByHash retrieves books from the library by the hash of one of their files.
func (*Library) GetBooksByID ¶
GetBooksByID retrieves books from the library by their id.
func (*Library) GetFilesByID ¶
GetFilesByID gets files for each ID.
func (*Library) ImportBook ¶
ImportBook adds a book to a library. The file referred to by book.OriginalFilename will either be copied or moved to the location referred to by book.CurrentFilename, relative to the configured books root. The book will not be imported if another book already in the library has the same hash.
func (*Library) MergeBooks ¶
MergeBooks merges all of the files from ids into the first one.
func (*Library) Search ¶
Search searches the library for books. By default, all fields are searched, but field:terms+to+search will limit to that field only. Fields: author, title, series, extension, tags, filename, source. Example: author:Stephen+King title:Shining
func (*Library) SearchPaged ¶
func (lib *Library) SearchPaged(terms string, offset, limit, moreResultsLimit int) (books []Book, moreResults int, err error)
SearchPaged implements book searching, both paged and non paged. Set limit to 0 to return all results. moreResults will be set to the number of additional results not returned, with a maximum of moreResultsLimit.
func (*Library) UpdateBook ¶
UpdateBook updates the authors and title of an existing book in the database, specified by book.ID. If the existing book's series is not empty, it will not be updated unless overwriteSeries is true.
type MetadataParser ¶
A MetadataParser is used to parse the metadata for a book from a list of BookFiles. As some implementations will use info from BookFiles to make parsing decisions, it is best to populate these as much as possible before passing them to Parse.
type RegexpMetadataParser ¶
A RegexpMetadataParser parses book metadata using each BookFile’s OriginalFilename. The first regular expression to match any files will be used, and if it matches multiple files, the authors/series/title combination that occurs most often will be used to set these fields on the book. Each BookFile will still have their tags and extension set individually. Each file’s extension will be trimmed before regular expressions are tested. If a file doesn’t match the used regular expression, it will be included with its extension and no tags. Regexps and RegexpNames must match.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
books/edit
Package edit contains sub commands for editing books from the command line.
|
Package edit contains sub commands for editing books from the command line. |