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
- Variables
- type Added
- type ChapterHooks
- type Cursor
- type Entry
- type EntryCandidate
- type Evidence
- type FromSource
- type LibraryPage
- type MatchSettings
- type Service
- func (s *Service) Add(ctx context.Context, v Viewer, entryID string, attach *SourceRef) (Added, error)
- func (s *Service) AddFromSource(ctx context.Context, v Viewer, ref SourceRef) (FromSource, error)
- func (s *Service) Attach(ctx context.Context, v Viewer, workID, seriesID uuid.UUID) (db.SourceSeries, error)
- func (s *Service) AttachRef(ctx context.Context, v Viewer, workID uuid.UUID, ref SourceRef, origin string) (db.SourceSeries, error)
- func (s *Service) AttachURL(ctx context.Context, v Viewer, workID uuid.UUID, rawURL string) (db.SourceSeries, error)
- func (s *Service) Detach(ctx context.Context, v Viewer, workID, seriesID uuid.UUID) (db.SourceSeries, error)
- func (s *Service) Get(ctx context.Context, v Viewer, id uuid.UUID) (Work, error)
- func (s *Service) List(ctx context.Context, v Viewer, query string, after *Cursor, limit int) (LibraryPage, error)
- func (s *Service) RefreshFromMeta(ctx context.Context, limit int) (updated, conflicts int, err error)
- func (s *Service) Rematch(ctx context.Context, workID, by uuid.UUID, force bool) (db.Task, error)
- func (s *Service) Remove(ctx context.Context, v Viewer, workID uuid.UUID) error
- func (s *Service) SearchSource(ctx context.Context, v Viewer, workID uuid.UUID, sourceID, query string, ...) (SourceSearch, error)
- func (s *Service) SetChapterHooks(h ChapterHooks)
- func (s *Service) SetPriority(ctx context.Context, v Viewer, workID, seriesID uuid.UUID, priority int32) (db.SourceSeries, error)
- func (s *Service) VisibleWorks(ctx context.Context, v Viewer) ([]uuid.UUID, error)
- type SourceRef
- type SourceSearch
- type Viewer
- type Work
- type WorkSource
Constants ¶
const ( KindMatchWork = "match.work" KindMatchSource = "match.source" )
Task kinds.
const ( StateAttached = "attached" StateCandidate = "candidate" StateRejected = "rejected" OriginAuto = "auto" OriginManual = "manual" OriginURL = "url" )
Series states and origins.
const ( MatchPending = "pending" MatchMatched = "matched" MatchCandidates = "candidates" MatchNone = "no_match" MatchFailed = "failed" )
Match statuses per work and source.
Variables ¶
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.
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 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 ¶
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 ¶
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) 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.
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 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.