library

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package library manages works and users' libraries. A work is one actual work, created from a metadata entry and shared by everyone; each user follows works in their own library. Series on sources are matched to a work (automatically, by searching the sources with the entry's titles, or by hand) and feed its chapters.

Index

Constants

View Source
const (
	KindMatchWork   = "match.work"
	KindMatchSource = "match.source"
)

Task kinds.

View Source
const (
	StateAttached  = "attached"
	StateCandidate = "candidate"
	StateRejected  = "rejected"

	OriginAuto   = "auto"
	OriginManual = "manual"
	OriginURL    = "url"
)

Series states and origins.

View Source
const (
	MatchPending    = "pending"
	MatchMatched    = "matched"
	MatchCandidates = "candidates"
	MatchNone       = "no_match"
	MatchFailed     = "failed"
)

Match statuses per work and source.

Variables

View Source
var (
	ErrNotFound     = errors.New("library: not found")
	ErrNotInLibrary = errors.New("library: not in your library")
	ErrWrongWork    = errors.New("library: the series belongs to another work")
)

Errors callers map to responses.

View Source
var DefaultMatchSettings = MatchSettings{MaxQueries: 5, CandidateScore: 0.6, MaxCandidates: 5, Details: 3}

DefaultMatchSettings are used unless the instance setting says otherwise.

Functions

This section is empty.

Types

type Added

type Added struct {
	Work    db.Work
	AddedAt time.Time
	// New is false when the work was in the library already.
	New bool
}

Added is the outcome of adding a work to a library.

type ChapterHooks

type ChapterHooks interface {
	// SeriesAttached: a series was attached to a work; load its chapters.
	SeriesAttached(ctx context.Context, se db.SourceSeries)
	// WorkChanged: a work's series changed (detached, priorities); rebuild
	// its chapters.
	WorkChanged(ctx context.Context, workID uuid.UUID)
}

ChapterHooks lets the chapters service follow a work's series.

type Cursor

type Cursor struct {
	SortTitle string
	ID        uuid.UUID
}

Cursor continues a library listing.

type Entry

type Entry struct {
	Work         db.Work
	AddedAt      time.Time
	Attached     int
	AutoDownload bool
}

Entry is a work in a user's library.

type EntryCandidate

type EntryCandidate struct {
	Entry        *metav1.EntrySummary
	Score        float64
	MatchedTitle string
	AuthorsMatch *bool
}

EntryCandidate is a catalogue entry that may be a source's series.

type Evidence

type Evidence struct {
	EntryTitle    string   `json:"entry_title,omitempty"`
	MatchedTitle  string   `json:"matched_title,omitempty"`
	Query         string   `json:"query,omitempty"`
	TitleScore    float64  `json:"title_score"`
	AuthorsMatch  *bool    `json:"authors_match,omitempty"`
	SourceAuthors []string `json:"source_authors,omitempty"`
	ChapterCount  *int     `json:"chapter_count,omitempty"`
}

Evidence is why a series was matched to a work.

func EvidenceOf

func EvidenceOf(se db.SourceSeries) Evidence

EvidenceOf decodes a series' evidence.

type FromSource

type FromSource struct {
	// Added is set when the series' catalogue entry was clear: the work is
	// in the library with the series attached.
	Added *Added
	// Candidates otherwise: the caller picks one and adds it with the
	// series attached.
	Candidates []EntryCandidate
}

FromSource is the outcome of adding a series found on a source.

type LibraryPage

type LibraryPage struct {
	Entries []Entry
	// Next is the cursor of the next page; nil on the last.
	Next *Cursor
}

LibraryPage is one page of a library.

type MatchSettings

type MatchSettings struct {
	// MaxQueries caps the searches per source (main title, then
	// alternatives).
	MaxQueries int `json:"max_queries"`
	// CandidateScore is the title similarity a result needs to count as a
	// candidate.
	CandidateScore float64 `json:"candidate_score"`
	// MaxCandidates kept per source.
	MaxCandidates int `json:"max_candidates"`
	// Details is how many top results get their full details (people,
	// chapter count) fetched.
	Details int `json:"details"`
}

MatchSettings tune matching. They are an instance setting ("matching"), with these defaults.

type Service

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

Service manages works and libraries.

func NewService

func NewService(st *store.Store, m *meta.Service, host *plugins.Host, q *queue.Queue, lim *limits.Registry, hub *events.Hub, log *slog.Logger) *Service

NewService returns the library service and registers its task kinds on q.

func (*Service) Add

func (s *Service) Add(ctx context.Context, v Viewer, entryID string, attach *SourceRef) (Added, error)

Add puts the work of a metadata entry into v's library, creating the work when nobody has it yet and starting its source matching. With attach, that series is attached to the work first.

func (*Service) AddFromSource

func (s *Service) AddFromSource(ctx context.Context, v Viewer, ref SourceRef) (FromSource, error)

AddFromSource finds the catalogue entry of a series seen on a source and, when it is clear (the exact title and a shared author, one such entry), adds that work with the series attached.

func (*Service) Attach

func (s *Service) Attach(ctx context.Context, v Viewer, workID, seriesID uuid.UUID) (db.SourceSeries, error)

Attach makes a candidate (or a rejected series) the work's series on its source; the one attached before becomes a candidate.

func (*Service) AttachRef

func (s *Service) AttachRef(ctx context.Context, v Viewer, workID uuid.UUID, ref SourceRef, origin string) (db.SourceSeries, error)

AttachRef attaches a series given by source and key (e.g. picked while browsing).

func (*Service) AttachURL

func (s *Service) AttachURL(ctx context.Context, v Viewer, workID uuid.UUID, rawURL string) (db.SourceSeries, error)

AttachURL attaches the series a pasted URL points to.

func (*Service) Detach

func (s *Service) Detach(ctx context.Context, v Viewer, workID, seriesID uuid.UUID) (db.SourceSeries, error)

Detach rejects a series for the work: matching won't attach it again.

func (*Service) Get

func (s *Service) Get(ctx context.Context, v Viewer, id uuid.UUID) (Work, error)

Get returns a work as v sees it, with its matching state per source v may use.

func (*Service) List

func (s *Service) List(ctx context.Context, v Viewer, query string, after *Cursor, limit int) (LibraryPage, error)

List returns a page of v's library by title, hiding works v may no longer see (their ceiling or allowed sources changed).

func (*Service) RefreshFromMeta

func (s *Service) RefreshFromMeta(ctx context.Context, limit int) (updated, conflicts int, err error)

RefreshFromMeta copies the latest display fields (title, cover, status, rating, …) of up to limit followed works from the metadata service, least recently refreshed first. When the service merged an entry into another, the work follows the new entry, unless another work already has it: then both stay and the conflict is logged (merging works comes later).

func (*Service) Rematch

func (s *Service) Rematch(ctx context.Context, workID, by uuid.UUID, force bool) (db.Task, error)

Rematch queues matching of a work against every usable source.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, v Viewer, workID uuid.UUID) error

Remove takes a work out of v's library. Files are never deleted here.

func (*Service) SearchSource

func (s *Service) SearchSource(ctx context.Context, v Viewer, workID uuid.UUID, sourceID, query string, page uint32, filters []*sourcev1.FilterValue) (SourceSearch, error)

SearchSource searches one source v may use for the work, to fix its match by hand. ErrNotFound when v can't see the work or use the source.

func (*Service) SetChapterHooks

func (s *Service) SetChapterHooks(h ChapterHooks)

SetChapterHooks connects the chapters service.

func (*Service) SetPriority

func (s *Service) SetPriority(ctx context.Context, v Viewer, workID, seriesID uuid.UUID, priority int32) (db.SourceSeries, error)

SetPriority sets a series' priority for choosing chapter variants.

func (*Service) VisibleWorks

func (s *Service) VisibleWorks(ctx context.Context, v Viewer) ([]uuid.UUID, error)

VisibleWorks returns the works of v's library v may still see.

type SourceRef

type SourceRef struct {
	SourceID string
	Key      string
}

SourceRef names a series on a source.

type SourceSearch

type SourceSearch struct {
	plugins.Page
	Known map[string]db.SourceSeries
}

SourceSearch is a search of one source for a work, with the series the work already knows on it, by key.

type Viewer

type Viewer struct {
	UserID      uuid.UUID
	Grants      users.Grants
	Admin       bool
	HideUnknown bool
}

Viewer is who is looking.

func (Viewer) Visible

func (v Viewer) Visible(w db.Work, attachedSources []string) bool

Visible reports whether v may see a work: within their ceiling, and either not matched to any source yet or matched to one they may use.

type Work

type Work struct {
	db.Work
	InLibrary bool
	AddedAt   *time.Time
	Sources   []WorkSource
}

Work is a work with what a viewer sees of it.

type WorkSource

type WorkSource struct {
	Source     plugins.Source
	Status     string
	Message    string
	Queries    []string
	CheckedAt  *time.Time
	Attached   *db.SourceSeries
	Candidates []db.SourceSeries
}

WorkSource is how a work stands on one source.

Jump to

Keyboard shortcuts

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