chapters

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: 22 Imported by: 0

Documentation

Overview

Package chapters builds each work's unified chapter list. Every attached series' chapters are kept as the source lists them (the per-source view); chapters with the same number across sources become one canonical chapter with a chosen variant, so gaps in one source are filled from another. Update checks refresh the lists on a schedule and on demand.

Index

Constants

View Source
const (
	ReasonPinned      = "pinned"
	ReasonOnlySource  = "only_source"
	ReasonLanguage    = "language"
	ReasonHealthier   = "healthier_source"
	ReasonPriority    = "priority"
	ReasonNewest      = "newest_upload"
	ReasonFirstListed = "first_listed"
)

Reasons a variant was chosen.

View Source
const KindUpdateSeries = "update.series"

KindUpdateSeries checks one attached series for chapters.

Variables

View Source
var (
	ErrNotFound       = errors.New("chapters: not found")
	ErrNotThisChapter = errors.New("chapters: the variant isn't a copy of this chapter")
)

Errors callers map to responses.

Functions

func DisplayTitle

func DisplayTitle(name string) string

DisplayTitle is a chapter's own name for showing, without its number, volume or scanlator noise; empty when the name has nothing else.

func Label

func Label(number *float64, volume, name string) string

Label names a chapter for showing on its own: "Vol. 2 Chapter 15: Rain", "Chapter 3", or an extra's own name.

func NumberOf

func NumberOf(number *float64, name string) *float64

NumberOf is a variant's chapter number: the source's, or one read from its name ("Chapter 12.5", "Ch. 3", "#7", "12"; see Parse). Negative numbers mean unknown. Extras (a name starting with "Side Story", "Special", "Extra", "Notice", …) have none: they stand apart from the numbered run, whatever number the source gives them.

func VolumeOf

func VolumeOf(volume, name string) string

VolumeOf is a variant's volume: the source's, or one read from its name ("Vol. 2", "Volume 2", "v2", "第2卷"), without leading zeros.

Types

type Chapter

type Chapter struct {
	db.Chapter
	Chosen   *VariantView
	Variants int
	// New: found after the user last looked at the work.
	New bool
}

Chapter is a canonical chapter as a user sees it.

type CheckState

type CheckState struct {
	// LastCheckedAt is the latest check of any of their series; nil when
	// none was checked yet.
	LastCheckedAt *time.Time
	// Checking counts checks running or due now; Failing, series whose
	// last check failed.
	Checking, Failing int
}

CheckState is how the chapter checks of some works stand.

type Choice

type Choice struct {
	Variant Variant
	Reason  string
}

Choice is the variant chosen for a chapter and why.

func Choose

func Choose(g Group, pinned *uuid.UUID, languages []string) Choice

Choose picks a group's preferred variant: a pinned one that still exists and is on a usable source (or nothing else is); else a usable source over an unusable one (turned off, no longer listed), then by preferred language (languages, in order; others after), a healthy source over a failing one, the series' priority, the newest upload, then the source's own order. The reason is the first of these that set the winner apart from the runner-up (an unusable source losing counts as healthier_source).

type Detail

type Detail struct {
	Chapter
	All []VariantView
}

Detail is one chapter with all its variants.

type Group

type Group struct {
	Number   *float64
	ExtraKey string
	Variants []Variant
}

Group is one canonical chapter: a number (or, for chapters without one, the single variant it came from) and its variants.

func GroupVariants

func GroupVariants(vs []Variant) []Group

GroupVariants groups variants into canonical chapters by number; each variant without a number is a chapter of its own. Groups come in number order, extras last.

func (Group) Volume

func (g Group) Volume() string

Volume is the volume most variants give (empty when none does).

type Parsed

type Parsed struct {
	// Number is the chapter number, or nil; NumberEnd ends a range
	// ("Chapter 10-11").
	Number, NumberEnd *float64
	// Volume, without leading zeros; empty when the name doesn't say.
	Volume string
	// Title is the chapter's own name with number, volume and scanlator
	// noise taken out; empty when there's nothing else ("Chapter 12").
	Title string
	// Extra is a side story, special, extra, notice or hiatus: not part of
	// the numbered run, even if it carries a number.
	Extra bool
}

Parsed is what a chapter's name says.

func Parse

func Parse(name string) Parsed

Parse reads a chapter's name.

type Service

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

Service keeps the works' chapters.

func NewService

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

NewService returns the service and registers its task kind on q.

func (*Service) ChecksOf

func (s *Service) ChecksOf(ctx context.Context, workIDs []uuid.UUID) (CheckState, error)

ChecksOf returns how the chapter checks of these works stand.

func (*Service) Get

func (s *Service) Get(ctx context.Context, workID, chapterID, userID uuid.UUID) (Detail, error)

Get returns a chapter of a work with all its variants.

func (*Service) List

func (s *Service) List(ctx context.Context, workID, userID uuid.UUID) ([]Chapter, error)

List returns a work's chapters in reading order (numbered ones by number, extras after), with the chosen variant and whether each is new for userID.

func (*Service) MarkSeen

func (s *Service) MarkSeen(ctx context.Context, userID, workID uuid.UUID) (bool, error)

MarkSeen clears a user's "new" badges of a work.

func (*Service) NewCounts

func (s *Service) NewCounts(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]int64, error)

NewCounts returns how many new chapters each of a user's works has.

func (*Service) OnNewChapters

func (s *Service) OnNewChapters(f func(ctx context.Context, workID uuid.UUID, chapterIDs []uuid.UUID))

OnNewChapters sets what happens when a work gains chapters (e.g. automatic downloads).

func (*Service) Pin

func (s *Service) Pin(ctx context.Context, chapterID uuid.UUID, variantID *uuid.UUID) (db.Chapter, error)

Pin forces a variant for a chapter (nil unpins), then re-chooses.

func (*Service) QueueUpdate

func (s *Service) QueueUpdate(ctx context.Context, se db.SourceSeries, by uuid.UUID, priority int32, runAfter time.Time) (db.Task, error)

QueueUpdate queues a chapter check of an attached series.

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, workID, by uuid.UUID) (int, error)

Refresh queues chapter checks of every attached series of a work, ahead of scheduled ones.

func (*Service) RefreshWorks

func (s *Service) RefreshWorks(ctx context.Context, workIDs []uuid.UUID, by uuid.UUID) (int, error)

RefreshWorks queues chapter checks of every attached series of these works, ahead of scheduled ones, and returns how many series it queued.

func (*Service) ScheduleAll

func (s *Service) ScheduleAll(ctx context.Context, spread time.Duration) (int, error)

ScheduleAll queues chapter checks of every attached series of works someone follows, spread over spread so sources aren't hit at once.

func (*Service) SeriesAttached

func (s *Service) SeriesAttached(ctx context.Context, se db.SourceSeries)

SeriesAttached checks a newly attached series' chapters soon.

func (*Service) SeriesChapters

func (s *Service) SeriesChapters(ctx context.Context, workID, seriesID uuid.UUID) (db.SourceSeries, []db.SourceChapter, error)

SeriesChapters returns a series' chapters exactly as its source lists them (the per-source view), including ones it no longer lists.

func (*Service) SourcesChanged

func (s *Service) SourcesChanged(ctx context.Context, sourceIDs []string)

SourcesChanged chooses the chapter copies again of every work with a series on these sources, after they became usable or stopped being usable: copies on an unusable source give way, and come back with it.

func (*Service) Unify

func (s *Service) Unify(ctx context.Context, workID uuid.UUID) (int, error)

Unify rebuilds a work's canonical chapters from its attached series and returns how many chapters are new.

func (*Service) UnifyAll

func (s *Service) UnifyAll(ctx context.Context) (int, error)

UnifyAll rebuilds every work's chapters from the chapters stored, without asking any source: after a change to how chapter names are read. It returns how many works it went through.

func (*Service) Updates

func (s *Service) Updates(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID, before *UpdateCursor, limit int) ([]Update, error)

Updates returns a page of the chapters that appeared in these works of a user's library after they added each, newest first.

func (*Service) WorkChanged

func (s *Service) WorkChanged(ctx context.Context, workID uuid.UUID)

WorkChanged rebuilds a work's chapters after its series changed.

type Update

type Update = db.UpdatesRow

Update is one chapter in the feed.

type UpdateCursor

type UpdateCursor struct {
	AppearedAt time.Time
	ChapterID  uuid.UUID
}

UpdateCursor is where a feed page ends.

type Variant

type Variant struct {
	ID         uuid.UUID
	SeriesID   uuid.UUID
	SourceID   string
	Key        string
	Name       string
	Number     *float64
	Volume     string
	Scanlator  string
	Lang       string
	UploadedAt *time.Time
	Position   int32
	// Priority is the series' priority for the work.
	Priority int32
	// Health is the source's: ok, failing or unknown.
	Health string
	// Unusable is a source that is turned off, no longer listed by its
	// plugin, or whose plugin is turned off.
	Unusable bool
	// Announce is a variant a later check of its series found: a chapter
	// made for it appears in the updates feed.
	Announce bool
}

Variant is one source's copy of a chapter.

type VariantView

type VariantView struct {
	Variant
	SourceName string
}

VariantView is a variant with its source's name.

Jump to

Keyboard shortcuts

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