meta

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 meta connects the server to the Panelarr metadata service, which the library needs: every work is created from one of its entries. It keeps the connection settings, checks that the service is usable and wraps the catalogue calls.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPairNotFound = errors.New("meta: no such duplicate pair")
	// ErrPairDecided is a decision a pair's state doesn't allow (e.g.
	// reopening a confirmed pair).
	ErrPairDecided = errors.New("meta: the pair can't take that decision now")
)

Duplicate review errors.

View Source
var (
	ErrJobNotFound      = errors.New("meta: no such job or run")
	ErrJobNotRunning    = errors.New("meta: the run has finished")
	ErrJobNotCancelable = errors.New("meta: this job can't be cancelled")
)

Job errors.

View Source
var (
	ErrNotConfigured = errors.New("meta: not connected")
	ErrManagedByEnv  = errors.New("meta: the connection is set by PANELARR_META_URL and can't be changed here")
	ErrCheckFailed   = errors.New("meta: the metadata service can't be used with these settings")
	ErrInvalidURL    = errors.New("meta: the URL must be http(s)://host[:port]")
)

Errors callers map to responses.

View Source
var ErrNotFound = errors.New("meta: entry not found")

ErrNotFound is an entry that doesn't exist or that the viewer may not see.

View Source
var ErrRunNotFound = errors.New("meta: no such sync run")

ErrRunNotFound is a sync run meta doesn't know.

Functions

func CoverOf

func CoverOf(images []*metadatav1.Image) *metadatav1.Image

CoverOf picks an entry's cover: the first cover image, else the first image.

func RatingName

func RatingName(r metadatav1.ContentRating) string

RatingName turns an entry's rating into the API's name: safe, suggestive, erotic, pornographic or unknown.

func StatusName

func StatusName(s metadatav1.EntryStatus) string

func TypeName

func TypeName(t metadatav1.EntryType) string

TypeName and StatusName turn entry types and statuses into the API's names ("manga", "releasing"), or "" when unknown.

func Unreachable

func Unreachable(err error) bool

Unreachable reports whether err means the metadata service couldn't be reached at all (no answer: connection refused, DNS, timeout), as opposed to the service answering with an error.

Types

type BadFilterError

type BadFilterError struct{ Field, Value string }

BadFilterError is a filter value the catalogue doesn't know.

func (*BadFilterError) Error

func (e *BadFilterError) Error() string

type BadJobParamsError

type BadJobParamsError struct{ Reason string }

BadJobParamsError is a run meta refused for its params.

func (*BadJobParamsError) Error

func (e *BadJobParamsError) Error() string

type BadRequestError

type BadRequestError struct{ Reason string }

BadRequestError is a request meta refused, with its reason.

func (*BadRequestError) Error

func (e *BadRequestError) Error() string

type Check

type Check struct {
	Configured bool
	Reachable  bool
	KeyValid   bool
	AdminScope bool
	Providers  []Provider
	// Ready: reachable, an admin key, and a provider with entries. Until
	// then the server is degraded and nothing can be added.
	Ready bool
	// Problem says what to do when not ready.
	Problem   string
	CheckedAt time.Time
}

Check is the result of checking the metadata service.

type Client

type Client struct {
	Meta    metav1connect.MetaServiceClient
	Admin   metav1connect.MetaAdminServiceClient
	Clients metav1connect.MetaClientsServiceClient
	Jobs    metav1connect.MetaJobsServiceClient
	// Integrations takes network profiles pushed by the server.
	Integrations metav1connect.MetaIntegrationsServiceClient
	// Duplicates is the duplicate entries review.
	Duplicates metav1connect.MetaDuplicatesServiceClient
}

Client talks to one metadata service over gRPC, the canonical wire for Panelarr services.

func NewClient

func NewClient(conn Conn, hc *http.Client) *Client

NewClient builds a client for conn using hc.

type Conn

type Conn struct {
	// URL is the service's base URL, e.g. "http://meta:8901".
	URL string
	// APIKey is a key with the admin scope.
	APIKey string
}

Conn is how to reach the metadata service.

type DuplicateQuery

type DuplicateQuery struct {
	Status     metav1.DuplicateStatus
	MinScore   float64
	JudgedOnly bool
	PageSize   int32
	PageToken  string
}

DuplicateQuery narrows the review list.

type Error

type Error struct {
	Op  string
	Err error
}

Error is a failed call to the metadata service, so callers that also talk to source plugins can tell whose error it is.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type JobDisabledError

type JobDisabledError struct{ Reason string }

JobDisabledError is a job that can't run now, and why.

func (*JobDisabledError) Error

func (e *JobDisabledError) Error() string

type JobRunningError

type JobRunningError struct{ RunID string }

JobRunningError is a job that is running already.

func (*JobRunningError) Error

func (e *JobRunningError) Error() string

type Provider

type Provider struct {
	ID      string
	Health  string
	Message string
	Records int64
}

Provider is one metadata provider plugin of the service.

type ProviderUnavailableError

type ProviderUnavailableError struct {
	Provider string
	Message  string
}

ProviderUnavailableError is the metadata service answering that one of its provider plugins can't be reached. The service itself is fine.

func (*ProviderUnavailableError) Error

func (e *ProviderUnavailableError) Error() string

type Query

type Query struct {
	Text      string
	Types     []string
	Statuses  []string
	Genres    []string
	YearFrom  int32
	YearTo    int32
	Sort      string // popularity, rating, updated, year, title, relevance
	Reverse   bool
	Language  string
	PageSize  int32
	PageToken string
}

Query is a catalogue search or browse.

type Service

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

Service holds the connection to the metadata service.

func NewService

func NewService(st *store.Store, box *secret.Box, env Conn, log *slog.Logger) *Service

NewService returns the service. env, when its URL is set, is the connection and can't be changed in the app.

func (*Service) Assignments

func (s *Service) Assignments(ctx context.Context) ([]*metav1.Assignment, error)

Assignments lists every provider meta has, with the network profile the server pushed to it (password left out) and whether its plugin takes profiles.

func (*Service) Browse

func (s *Service) Browse(ctx context.Context, q Query, v Viewer) (*metav1.BrowseResponse, error)

Browse lists the catalogue with filters, showing only what v may see.

func (*Service) CancelJobRun

func (s *Service) CancelJobRun(ctx context.Context, runID string) (*metav1.JobRunSummary, error)

CancelJobRun cancels a running run.

func (*Service) Check

func (s *Service) Check(ctx context.Context, fresh bool) Check

Check checks the current connection. Without fresh, a recent result is reused.

func (*Service) Client

func (s *Service) Client() (*Client, error)

Client returns the current client, or ErrNotConfigured.

func (*Service) ConfirmDuplicate

func (s *Service) ConfirmDuplicate(ctx context.Context, id int64, keep, note string) (*metav1.DuplicatePair, string, error)

ConfirmDuplicate merges a pair into one entry (it can't be undone): keep is "a", "b" or empty for the more popular one. It returns the pair and the entry they are now.

func (*Service) CoverURL

func (s *Service) CoverURL(ctx context.Context, id string, v Viewer) (string, error)

CoverURL returns the source URL of an entry's cover, if v may see the entry. Covers seen in recent lists are remembered, so showing a page of results doesn't cost one lookup per cover.

func (*Service) DismissDuplicate

func (s *Service) DismissDuplicate(ctx context.Context, id int64, note string) (*metav1.DuplicatePair, error)

DismissDuplicate records that a pair are different works.

func (*Service) Duplicate

func (s *Service) Duplicate(ctx context.Context, id int64) (*metav1.DuplicatePair, error)

Duplicate returns one pair.

func (*Service) Duplicates

Duplicates lists suspected duplicate pairs.

func (*Service) GetEntry

func (s *Service) GetEntry(ctx context.Context, id, language string, v Viewer) (*metav1.Entry, error)

GetEntry returns one entry, or ErrNotFound when it doesn't exist or its rating is above what v may see.

func (*Service) Health

func (s *Service) Health(ctx context.Context) (*metav1.GetHealthResponse, error)

Health is meta's own health, per component.

func (*Service) HideUnknown

func (s *Service) HideUnknown(ctx context.Context) bool

HideUnknown reports whether users are kept from entries and sources without a known content rating.

func (*Service) Job

func (s *Service) Job(ctx context.Context, id string) (*metav1.Job, error)

Job returns one of meta's jobs.

func (*Service) JobRun

func (s *Service) JobRun(ctx context.Context, runID string) (*metav1.JobRun, error)

JobRun returns one run in full.

func (*Service) JobRuns

func (s *Service) JobRuns(ctx context.Context, id string, status metav1.JobRunStatus, pageSize int32, token string) ([]*metav1.JobRunSummary, string, error)

JobRuns lists a job's runs, newest first.

func (*Service) Jobs

func (s *Service) Jobs(ctx context.Context) ([]*metav1.Job, error)

Jobs lists meta's jobs.

func (*Service) Judge

Judge returns the decision model settings in force (no API key).

func (*Service) Load

func (s *Service) Load(ctx context.Context) error

Load reads the connection from the environment or the database.

func (*Service) Providers

func (s *Service) Providers(ctx context.Context) ([]*metav1.Provider, error)

Providers lists meta's providers with their plugin, health, schedules, record counts and last runs.

func (*Service) PushProfile

func (s *Service) PushProfile(ctx context.Context, provider string, p *metadatav1.NetworkProfile) error

PushProfile gives a provider its network profile; nil removes the pushed one (meta's own settings apply again).

func (*Service) PutJudge

PutJudge saves decision model settings; an empty API key keeps meta's.

func (*Service) PutSearchEngine

PutSearchEngine saves search engine settings; an empty API key keeps the stored one.

func (*Service) ReadyCheck

func (s *Service) ReadyCheck(ctx context.Context) error

ReadyCheck is the readiness check: it fails while the service isn't ready, which marks the server degraded.

func (*Service) RefreshEntry

func (s *Service) RefreshEntry(ctx context.Context, id string) (*metav1.RefreshEntryResponse, error)

RefreshEntry asks every provider of an entry for fresh data now.

func (*Service) ReopenDuplicate

func (s *Service) ReopenDuplicate(ctx context.Context, id int64) (*metav1.DuplicatePair, error)

ReopenDuplicate takes back a dismissal.

func (*Service) ResetJudge

func (s *Service) ResetJudge(ctx context.Context) (*metav1.DecisionJudgeSettings, error)

ResetJudge forgets the admin's settings (meta's configuration applies).

func (*Service) ResetSearchEngine

ResetSearchEngine forgets the admin's settings (meta's configuration applies again).

func (*Service) RunJob

func (s *Service) RunJob(ctx context.Context, id string, params map[string]string) (*metav1.JobRunSummary, error)

RunJob starts one of meta's jobs now.

func (*Service) RunSync

func (s *Service) RunSync(ctx context.Context, provider, kind string) (string, error)

RunSync starts a sync of a provider in the metadata service and returns the run's ID.

func (*Service) Save

func (s *Service) Save(ctx context.Context, conn Conn) (Check, error)

Save tests conn and, when the service is reachable and the key has the admin scope, stores it (the key encrypted) and switches to it. A service without provider data is saved too: the check says what's missing.

func (*Service) Search

func (s *Service) Search(ctx context.Context, q Query, v Viewer) (*metav1.SearchResponse, error)

Search searches the catalogue by text, showing only what v may see.

func (*Service) SearchEngine

SearchEngine returns the search engine settings in force and its state.

func (*Service) SetHTTPClient

func (s *Service) SetHTTPClient(hc *http.Client)

SetHTTPClient replaces the HTTP client (tests).

func (*Service) Status

func (s *Service) Status(ctx context.Context) Status

Status returns the connection and a check no older than checkTTL.

func (*Service) SyncRun

func (s *Service) SyncRun(ctx context.Context, id string) (*metav1.SyncRun, error)

SyncRun returns one sync run in full.

func (*Service) SyncRuns

func (s *Service) SyncRuns(ctx context.Context, provider string, pageSize int32, token string) ([]*metav1.SyncRun, string, error)

SyncRuns lists sync runs, newest first, of one provider or all.

func (*Service) TestJudge

TestJudge asks the model about a made-up pair without saving.

func (*Service) TestSearchEngine

func (s *Service) TestSearchEngine(ctx context.Context, st *metav1.SearchEngineSettings) (bool, string, error)

TestSearchEngine tries search engine settings without saving them.

type Status

type Status struct {
	URL          string
	ManagedByEnv bool
	Check        Check
}

Status is the connection and its last check.

type Viewer

type Viewer struct {
	// Ceiling is the strongest rating shown: safe, suggestive, erotic or
	// pornographic.
	Ceiling string
	// Admin viewers always see unrated entries.
	Admin bool
}

Viewer is who is looking: it decides which content ratings show.

Directories

Path Synopsis
Package metatest runs a fake metadata service for tests: the real gRPC API over cleartext HTTP/2, with keys, providers and entries set by the test.
Package metatest runs a fake metadata service for tests: the real gRPC API over cleartext HTTP/2, with keys, providers and entries set by the test.

Jump to

Keyboard shortcuts

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