books

package module
v0.0.0-...-8667993 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBookNotFound = errors.New("book not found")

ErrBookNotFound is returned when a book is not found in the database.

Functions

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI returns a human-readable string in SI (decimal) format from the provided size in bytes.

func CreateLibrary

func CreateLibrary(filename string) error

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 Escape

func Escape(filename string) string

Escape replaces special characters in a filename with _.

func GetUniqueName

func GetUniqueName(f string, currentFilename string) (string, error)

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

func JoinNaturally(conjunction string, items []string) string

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

func TruncateFilename(fn string) string

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

type Book struct {
	ID      int64
	Authors []string
	Title   string
	Series  string
	Files   []BookFile
}

Book represents a book in a library.

func ParseFilename

func ParseFilename(filename string, re *regexp.Regexp) (Book, bool)

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

func (bf *BookFile) CalculateHash() error

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.

func (*BookFile) Filename

func (bf *BookFile) Filename(tmpl *template.Template, book *Book) (string, error)

Filename retrieves a book's correct filename, based on the given output template.

func (*BookFile) HashPath

func (bf *BookFile) HashPath() string

HashPath gets the path of a file's hash, relative to books root.

type EpubMetadataParser

type EpubMetadataParser struct{}

EpubMetadataParser parses files using EPUB metadata.

func (*EpubMetadataParser) Parse

func (*EpubMetadataParser) Parse(files []string) (book Book, parsed bool)

Parse parses a list of files using EPUB metadata.

type Library

type Library struct {
	*sql.DB
	// contains filtered or unexported fields
}

Library represents a set of books in persistent storage.

func OpenLibrary

func OpenLibrary(filename, booksRoot string) (*Library, error)

OpenLibrary opens a library stored in a file.

func (*Library) ConvertToEpub

func (lib *Library) ConvertToEpub(file BookFile) error

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

func (lib *Library) GetBookIDByFilename(fn string) (int64, error)

GetBookIDByFilename returns a book ID given a filename relative to books root.

func (*Library) GetBookIDByTitleAndAuthors

func (lib *Library) GetBookIDByTitleAndAuthors(title string, authors []string) (int64, bool, error)

GetBookIDByTitleAndAuthors gets an existing book ID with the given title and authors.

func (*Library) GetBooksByHash

func (lib *Library) GetBooksByHash(hash string) ([]Book, error)

GetBooksByHash retrieves books from the library by the hash of one of their files.

func (*Library) GetBooksByID

func (lib *Library) GetBooksByID(ids []int64) ([]Book, error)

GetBooksByID retrieves books from the library by their id.

func (*Library) GetFilesByID

func (lib *Library) GetFilesByID(ids []int64) ([]BookFile, error)

GetFilesByID gets files for each ID.

func (*Library) ImportBook

func (lib *Library) ImportBook(book Book, tmpl *template.Template, move bool) error

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

func (lib *Library) MergeBooks(ids []int64, tmpl *template.Template) error

MergeBooks merges all of the files from ids into the first one.

func (*Library) Search

func (lib *Library) Search(terms string) ([]Book, error)

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

func (lib *Library) UpdateBook(book Book, tmpl *template.Template, overwriteSeries bool) error

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

type MetadataParser interface {
	Parse(files []string) (book Book, parsed bool)
}

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

type RegexpMetadataParser struct {
	Regexps     []*regexp.Regexp
	RegexpNames []string
}

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.

func (*RegexpMetadataParser) Parse

func (p *RegexpMetadataParser) Parse(files []string) (book Book, parsed bool)

Parse parses a list of files using regexps.

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.

Jump to

Keyboard shortcuts

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