cdb

package module
v0.0.111 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 21 Imported by: 5

README

cdb

tool for working with calibre's database

Documentation

Index

Constants

View Source
const (
	SavedSearches    = "saved_searches"
	DisplayFields    = "book_display_fields"
	HiddenCategories = "tag_browser_hidden_categories"
	FieldMetadata    = "field_metadata"
)
View Source
const (
	Authors       = "authors"
	AuthorSort    = "author_sort"
	Comments      = "comments"
	Cover         = "cover"
	CustomColumns = "custom_columns"
	Formats       = "formats"
	ID            = "id"
	Identifiers   = "identifiers"
	Languages     = "languages"
	LastModified  = "last_modified"
	Path          = "path"
	Pubdate       = "pubdate"
	Publisher     = "publisher"
	Rating        = "rating"
	Series        = "series"
	SeriesIndex   = "series_index"
	Sort          = "sort"
	SortAs        = "sort_as"
	Tags          = "tags"
	Timestamp     = "timestamp"
	Title         = "title"
	UUID          = "uuid"
	Duration      = "duration"
	Narrators     = "narrators"
)

Variables

This section is empty.

Functions

func AddedInThePastDays

func AddedInThePastDays(d int) string

AddedInThePastDays retrieves the past n days of records.

func CheckLib

func CheckLib(path string) error

CheckLib checks that the calibre database exists or the content server is online.

func ErrFileNotExist

func ErrFileNotExist(path string) error

func FileExist

func FileExist(path string) bool

func ListCommands

func ListCommands() []string

ListCommands lists the available calibredb commands.

func ListPreferences

func ListPreferences() []string

ListPreferences lists the retrievable calibre preferences.

func SrvIsOnline

func SrvIsOnline(u *url.URL) bool

SrvIsOnline tests if the calibredb content server is available.

Types

type Add

type Add struct {
	*Command
}

Add represents 'calibredb add'.

func (*Add) Add

func (c *Add) Add(v string) *Add

Add sets the --add [string] flag for 'calibredb add'.

func (*Add) Automerge

func (c *Add) Automerge(v string) *Add

Automerge sets the --automerge [string] flag for 'calibredb add'.

func (*Add) Duplicates

func (c *Add) Duplicates() *Add

Duplicates sets the --duplicates flag for 'calibredb add'.

func (*Add) Empty

func (c *Add) Empty() *Add

Empty sets the --empty flag for 'calibredb add'.

func (*Add) Ignore

func (c *Add) Ignore(v string) *Add

Ignore sets the --ignore [string] flag for 'calibredb add'.

func (*Add) OneBookPerDirectory

func (c *Add) OneBookPerDirectory() *Add

OneBookPerDirectory sets the --one_book_per_directory flag for 'calibredb add'.

func (*Add) Recurse

func (c *Add) Recurse() *Add

Recurse sets the --recurse flag for 'calibredb add'.

type AddFormat

type AddFormat struct {
	*Command
}

AddFormat represents 'calibredb add_format'.

func (*AddFormat) DontReplace

func (c *AddFormat) DontReplace() *AddFormat

DontReplace sets the --dont_replace flag for 'calibredb add_format'.

type Book

type Book struct {
	EditableFields `yaml:",inline" mapstructure:",squash"`
	Timestamp      time.Time `db:"timestamp" yaml:"timestamp,omitempty" toml:"timestamp,omitempty" json:"timestamp,omitempty"`
	Cover          string    `db:"cover" yaml:"cover,omitempty" toml:"cover,omitempty" json:"cover,omitempty"`
	Formats        []string  `db:"formats" yaml:"formats,omitempty" toml:"formats,omitempty" json:"formats,omitempty"`
	LastModified   time.Time `` /* 150-byte string literal not displayed */
	ID             int       `db:"id" yaml:"id,omitempty" toml:"id,omitempty" json:"id,omitempty"`
	Path           string    `db:"path" yaml:"path,omitempty" toml:"path,omitempty" json:"path,omitempty"`
	UUID           string    `db:"uuid,omitempty" yaml:"uuid,omitempty" toml:"uuid,omitempty" json:"uuid,omitempty"`
	Source         string    `json:"source,omitempty" yaml:"-" toml:"-"`
}

Book represents a book record.

func (*Book) CalibredbFlags added in v0.0.4

func (b *Book) CalibredbFlags() []string

CalibredbFlags is a convenience method for returning a slice of metadata fields to use with the 'set_metadata' command.

func (Book) StringMap

func (b Book) StringMap() map[string]any

StringMap converts a book record to map[string]any.

func (Book) StringMapString added in v0.0.4

func (b Book) StringMapString() map[string]string

StringMapString converts a book record to map[string]string.

func (*Book) URL added in v0.0.4

func (b *Book) URL(urlopt ...*url.URL) string

URL sets the path for a *url.URL and returns a string, by default returns a path.

type BookDecoder added in v0.0.11

type BookDecoder func(r io.Reader) Decoder

BookDecoder takes a io.Writer and returns a type that can Decode a book.

func DecodeJSON added in v0.0.11

func DecodeJSON(s *Serializer) BookDecoder

DecodeJSON configures a JSON BookDecoder.

func DecodeTOML added in v0.0.11

func DecodeTOML(s *Serializer) BookDecoder

DecodeTOML configures a TOML BookDecoder.

func DecodeYAML added in v0.0.11

func DecodeYAML(s *Serializer) BookDecoder

DecodeYAML configures a YAML BookDecoder.

type BookEncoder added in v0.0.11

type BookEncoder func(w io.Writer) Encoder

BookEncoder takes a io.Writer and returns a type that can Encode a book.

func EncodeJSON added in v0.0.11

func EncodeJSON(s *Serializer) BookEncoder

EncodeJSON configures a JSON BookEncoder.

func EncodeTOML added in v0.0.11

func EncodeTOML(s *Serializer) BookEncoder

EncodeTOML configures a TOML BookEncoder.

func EncodeYAML added in v0.0.11

func EncodeYAML(s *Serializer) BookEncoder

EncodeYAML configures a YAML BookEncoder.

type CmdOpt

type CmdOpt func(*Command)

CmdOpt sets options for the calibredb command.

func Authenticate

func Authenticate(user, pass string) CmdOpt

Authenticate is used to pass credentials to the calibre content server.

func DryRun

func DryRun() CmdOpt

DryRun prints the built command.

func Verbose

func Verbose() CmdOpt

Verbose prints the built command and stdout.

type Command

type Command struct {
	CdbCmd string
	// contains filtered or unexported fields
}

Command represents a calibredb command.

func Calibredb

func Calibredb(path string, opts ...CmdOpt) (*Command, error)

Calibredb initializes a command. Path or URL to a library is required.

func (*Command) Add

func (c *Command) Add(files ...string) *Add

Add initializes the add command with the files ...string paramaters.

func (*Command) AddFormat

func (c *Command) AddFormat(id string, file string) *AddFormat

AddFormat initializes the add_format command with the id string, file string paramaters.

func (*Command) Build

func (c *Command) Build() *exec.Cmd

Build compiles the calibredb command to be run.

func (*Command) EmbedMetadata

func (c *Command) EmbedMetadata() *EmbedMetadata

EmbedMetadata initializes the embed_metadata command.

func (*Command) Export

func (c *Command) Export(id ...string) *Export

Export initializes the export command with the id ...string paramaters.

func (*Command) Remove

func (c *Command) Remove() *Remove

Remove initializes the remove command.

func (*Command) RemoveFormat

func (c *Command) RemoveFormat(id string, fmt string) *RemoveFormat

RemoveFormat initializes the remove_format command with the id string, fmt string paramaters.

func (*Command) Run

func (c *Command) Run() (string, error)

Run executes the calibredb command.

func (*Command) SavedSearchesAdd

func (c *Command) SavedSearchesAdd(name string, expression string) *SavedSearchesAdd

SavedSearchesAdd initializes the saved_searches add command with the name string, expression string paramaters.

func (*Command) SavedSearchesList

func (c *Command) SavedSearchesList() *SavedSearchesList

SavedSearchesList initializes the saved_searches list command.

func (*Command) SavedSearchesRemove

func (c *Command) SavedSearchesRemove(name string) *SavedSearchesRemove

SavedSearchesRemove initializes the saved_searches remove command with the name string paramaters.

func (*Command) SetArgs

func (c *Command) SetArgs(args ...string)

SetArgs sets the positional arguments for the calibredb command.

func (*Command) SetFlags

func (c *Command) SetFlags(flags ...string)

SetFlags sets the flags for the calibredb command.

func (*Command) SetMetadata

func (c *Command) SetMetadata(id string) *SetMetadata

SetMetadata initializes the set_metadata command with the id string paramaters.

func (*Command) ShowMetadata

func (c *Command) ShowMetadata(id string) *ShowMetadata

ShowMetadata initializes the show_metadata command with the id string paramaters.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB holds the database connection.

func (*DB) Connect

func (db *DB) Connect(p string) error

Connect opens the database connection.

func (DB) IsConnected

func (db DB) IsConnected() bool

IsConnected checks if the database is connected.

type Decoder added in v0.0.11

type Decoder interface {
	Decode(v any) error
}

Decoder is an interface for types that can decode a book.

type DecoderInit added in v0.0.11

type DecoderInit func(*Serializer) BookDecoder

DecoderInit takes the serializer options and returns a function that initializes a Decoder.

type EditableFields added in v0.0.11

type EditableFields struct {
	Title       string    `db:"title" yaml:"title" toml:"title" json:"title"`
	Authors     []string  `db:"authors" yaml:"authors,omitempty" toml:"authors,omitempty" json:"authors,omitempty"`
	Narrators   []string  `db:"narrators" yaml:"narrators,omitempty" toml:"narrators,omitempty" json:"narrators,omitempty"`
	Series      string    `db:"series" yaml:"series,omitempty" toml:"series,omitempty" json:"series,omitempty"`
	SeriesIndex float64   `` /* 145-byte string literal not displayed */
	Tags        []string  `db:"tags" yaml:"tags,omitempty" toml:"tags,omitempty" json:"tags,omitempty"`
	Pubdate     time.Time `db:"pubdate" yaml:"pubdate,omitempty" toml:"pubdate,omitempty" json:"pubdate,omitempty"`
	Duration    string    `db:"duration" yaml:"duration,omitempty" toml:"duration,omitempty" json:"duration,omitempty"`
	Comments    string    `db:"comments" yaml:"comments,omitempty" toml:"comments,omitempty" json:"comments,omitempty"`
	Rating      int       `db:"rating" yaml:"rating,omitempty" toml:"rating,omitempty" json:"rating,omitempty"`
	Publisher   string    `db:"publisher" yaml:"publisher,omitempty" toml:"publisher,omitempty" json:"publisher,omitempty"`
	Languages   []string  `db:"languages" yaml:"languages,omitempty" toml:"languages,omitempty" json:"languages,omitempty"`
	Identifiers []string  `db:"identifiers" yaml:"identifiers,omitempty" toml:"identifiers,omitempty" json:"identifiers,omitempty"`
	AuthorSort  string    `` /* 140-byte string literal not displayed */
	Sort        string    `db:"sort" yaml:"sort,omitempty" toml:"sort,omitempty" json:"sort,omitempty"`
}

EditableFields are fields that can be set with the calibredb set_metadata command.

type EmbedMetadata

type EmbedMetadata struct {
	*Command
}

EmbedMetadata represents 'calibredb embed_metadata'.

func (*EmbedMetadata) OnlyFormats

func (c *EmbedMetadata) OnlyFormats() *EmbedMetadata

OnlyFormats sets the --only_formats flag for 'calibredb embed_metadata'.

type Encoder added in v0.0.11

type Encoder interface {
	Encode(v any) error
}

Encoder is an interface for types that can Encode a book.

type EncoderInit added in v0.0.11

type EncoderInit func(*Serializer) BookEncoder

EncoderInit takes the serializer options and returns a function that initializes an Encoder.

type Export

type Export struct {
	*Command
}

Export represents 'calibredb export'.

func (*Export) DontAsciiize

func (c *Export) DontAsciiize() *Export

DontAsciiize sets the --dont_asciiize flag for 'calibredb export'.

func (*Export) DontSaveCover

func (c *Export) DontSaveCover() *Export

DontSaveCover sets the --dont_save_cover flag for 'calibredb export'.

func (*Export) DontUpdateMetadata

func (c *Export) DontUpdateMetadata() *Export

DontUpdateMetadata sets the --dont_update_metadata flag for 'calibredb export'.

func (*Export) DontWriteOpf

func (c *Export) DontWriteOpf() *Export

DontWriteOpf sets the --dont_write_opf flag for 'calibredb export'.

func (*Export) Formats

func (c *Export) Formats(v string) *Export

Formats sets the --formats [string] flag for 'calibredb export'.

func (*Export) ReplaceWhitespace

func (c *Export) ReplaceWhitespace() *Export

ReplaceWhitespace sets the --replace_whitespace flag for 'calibredb export'.

func (*Export) SingleDir

func (c *Export) SingleDir() *Export

SingleDir sets the --single_dir flag for 'calibredb export'.

func (*Export) Template

func (c *Export) Template(v string) *Export

Template sets the --template [string] flag for 'calibredb export'.

func (*Export) Timefmt

func (c *Export) Timefmt(v string) *Export

Timefmt sets the --timefmt [string] flag for 'calibredb export'.

func (*Export) ToDir

func (c *Export) ToDir(v string) *Export

ToDir sets the --to_dir [string] flag for 'calibredb export'.

func (*Export) ToLowercase

func (c *Export) ToLowercase() *Export

ToLowercase sets the --to_lowercase flag for 'calibredb export'.

type Lib

type Lib struct {
	*DB

	Name         string
	Path         string
	IsAudiobooks bool
	// contains filtered or unexported fields
}

Lib represents a calibre library.

func NewLib

func NewLib(path string, opts ...Option) *Lib

NewLib initializes a library.

func (*Lib) GetBooks

func (l *Lib) GetBooks(q sq.Sqlizer) (Records, error)

GetBooks runs a database query. Takes an squirrel.Sqlizer interface to generate the sql.

func (*Lib) GetPreference

func (l *Lib) GetPreference(c string) ([]byte, error)

GetPreference gets a calibre preference.

func (*Lib) NewQuery

func (l *Lib) NewQuery() *Query

NewQuery initializes a database query.

type Model

type Model struct {
	CategorySort string `yaml:"category_sort" db:"category_sort"`
	Column       string `yaml:"column" db:"column"`
	Colnum       int    `yaml:"colnum" db:"id"`
	IsCategory   bool   `yaml:"is_category" db:"is_category"`
	IsCustom     bool   `yaml:"is_custom" db:"is_custom"`
	IsEditable   bool   `yaml:"is_editable" db:"is_editable"`
	IsNames      bool   `yaml:"is_names" db:"is_names"`
	JoinTable    string `yaml:"join_table" db:"join_table"`
	Label        string `yaml:"label" db:"label"`
	LinkColumn   string `yaml:"link_column" db:"link_column"`
	Name         string `yaml:"name" db:"name"`
	Table        string `yaml:"table" db:"table"`
}

Model represents a book field.

func GetModel added in v0.0.4

func GetModel(l string) Model

func (Model) Join added in v0.0.4

func (m Model) Join(v []string) string

func (Model) Split added in v0.0.4

func (m Model) Split(v string) []string

func (Model) ToSql

func (m Model) ToSql() string

ToSql returns a model's sql expression as a string.

func (Model) ToSqlJSON added in v0.0.4

func (m Model) ToSqlJSON() string

type Models

type Models map[string]Model

Models is a map of Model.

func AllModels

func AllModels() Models

AllModels returns all possible book fields.

func AudiobookModels

func AudiobookModels() Models

AudiobookModels returns the default book fields with Duration and Narrators.

func DefaultModels

func DefaultModels() Models

DefaultModels returns the default book fields.

func (Models) Editable

func (m Models) Editable() Models

Editable returns the list of editable book fields.

type Option

type Option func(*Lib)

Option is a set a library option.

func IsAudiobooks

func IsAudiobooks() Option

IsAudiobooks marks a library as containing audiobooks.

func PrintQuery added in v0.0.4

func PrintQuery() Option

PrintQuery prints the database query to stdout.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query represents a database query.

func NewQuery

func NewQuery(cols []string) *Query

NewQuery initializes a query builder.

func (*Query) Filter

func (q *Query) Filter(w string) *Query

Filter takes an arbitrary WHERE expression.

func (*Query) GetByID

func (q *Query) GetByID(ids ...any) *Query

GetByID retrieves records by id.

func (*Query) Limit

func (q *Query) Limit(v int) *Query

Limit sets the number of records returned.

func (*Query) Page

func (q *Query) Page(v int) *Query

Page is used with the limit to determine OFFSET.

func (*Query) Sort

func (q *Query) Sort(v string) *Query

Sort sets Sort By. Takes a string argument in the form of 'sort:order'.

func (*Query) ToSql

func (q *Query) ToSql() (string, []any, error)

ToSql satisfies squirrel.Sqlizer to build the sql expression with paramaters.

type Records added in v0.0.4

type Records struct {
	// contains filtered or unexported fields
}

func (Records) Books added in v0.0.4

func (r Records) Books() ([]Book, error)

func (Records) MarshalJSON added in v0.0.4

func (r Records) MarshalJSON() ([]byte, error)

func (Records) StringMap added in v0.0.4

func (r Records) StringMap() ([]map[string]any, error)

func (Records) StringMapString added in v0.0.4

func (r Records) StringMapString() ([]map[string]string, error)

func (Records) UnmarshalJSON added in v0.0.4

func (r Records) UnmarshalJSON(d []byte) error

type Remove

type Remove struct {
	*Command
}

Remove represents 'calibredb remove'.

func (*Remove) Permanent

func (c *Remove) Permanent() *Remove

Permanent sets the --permanent flag for 'calibredb remove'.

type RemoveFormat

type RemoveFormat struct {
	*Command
}

RemoveFormat represents 'calibredb remove_format'.

type SavedSearchesAdd

type SavedSearchesAdd struct {
	*Command
}

SavedSearchesAdd represents 'calibredb saved_searches add'.

type SavedSearchesList

type SavedSearchesList struct {
	*Command
}

SavedSearchesList represents 'calibredb saved_searches list'.

type SavedSearchesRemove

type SavedSearchesRemove struct {
	*Command
}

SavedSearchesRemove represents 'calibredb saved_searches remove'.

type Serializer added in v0.0.11

type Serializer struct {
	Indent   int
	Format   string
	Editable bool
	Book     *Book
	// contains filtered or unexported fields
}

Serializer holds the options for encoding or decoding a book.

func NewSerializer added in v0.0.11

func NewSerializer(b *Book, opts ...SerializerOpt) *Serializer

NewSerializer constructs a serializer for a book with default options.

func (*Serializer) Decoder added in v0.0.11

func (s *Serializer) Decoder(init DecoderInit) *Serializer

Decoder takes a DecoderInit and sets the BookDecoder.

func (*Serializer) Encoder added in v0.0.11

func (s *Serializer) Encoder(init EncoderInit) *Serializer

Encoder takes a EncoderInit and sets the BookEncoder.

func (*Serializer) ReadFile added in v0.0.11

func (s *Serializer) ReadFile(path string) error

ReadFile reads a file for decoding.

func (*Serializer) ReadFrom added in v0.0.11

func (s *Serializer) ReadFrom(r io.Reader) error

ReadFrom reads from io.Reader for decoding.

func (*Serializer) WriteFile added in v0.0.11

func (s *Serializer) WriteFile(name string) error

WriteFile writes an encoded book to disk.

func (*Serializer) WriteTo added in v0.0.11

func (s *Serializer) WriteTo(w io.Writer) error

WriteTo writes an encoded book to io.Writer.

type SerializerOpt added in v0.0.11

type SerializerOpt func(*Serializer)

SerializerOpt sets the options for a serializer.

func EditableOnly added in v0.0.11

func EditableOnly() SerializerOpt

EditableOnly sets the option for serializing only editable book fields.

func WithFormat added in v0.0.11

func WithFormat(ext string) SerializerOpt

WithFormat sets the encoding format extension.

func WithIndent added in v0.0.11

func WithIndent(n int) SerializerOpt

WithIndent sets the number of spaces for indenting.

type SetMetadata

type SetMetadata struct {
	*Command
}

SetMetadata represents 'calibredb set_metadata'.

func (*SetMetadata) Field

func (c *SetMetadata) Field(v string) *SetMetadata

Field sets the --field [string] flag for 'calibredb set_metadata'.

func (*SetMetadata) ListFields

func (c *SetMetadata) ListFields() *SetMetadata

ListFields sets the --list_fields flag for 'calibredb set_metadata'.

type ShowMetadata

type ShowMetadata struct {
	*Command
}

ShowMetadata represents 'calibredb show_metadata'.

func (*ShowMetadata) AsOpf

func (c *ShowMetadata) AsOpf() *ShowMetadata

AsOpf sets the --as_opf flag for 'calibredb show_metadata'.

Directories

Path Synopsis
internal
gen

Jump to

Keyboard shortcuts

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