Documentation
¶
Overview ¶
Package ratings caches licensed, owner-keyed rating data. Values preserve their source scale; Plex's main rating fields alone use the 0–10 scale.
Index ¶
- Constants
- type Badge
- type Options
- type Presented
- type PresentedSource
- type Service
- func (s *Service) Backfill(ctx context.Context)
- func (s *Service) Cached(ctx context.Context, t *core.Title) ([]Badge, error)
- func (s *Service) CachedMany(ctx context.Context, titles []core.Title) (map[core.RatingKey][]Badge, error)
- func (s *Service) MigrateSecrets(ctx context.Context) (int, error)
- func (s *Service) Prune(ctx context.Context) (int64, error)
- func (s *Service) Queue(t core.Title)
- func (s *Service) Refresh(ctx context.Context, t *core.Title) ([]Badge, error)
- func (s *Service) Router(cat core.Catalog) http.Handler
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SaveSettings(ctx context.Context, v Settings) error
- func (s *Service) Settings(ctx context.Context) (Settings, error)
- func (s *Service) WithSettingsSnapshot(ctx context.Context) context.Context
- type Settings
Constants ¶
const Redacted = "[configured]"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Badge ¶
type Badge struct {
Source string `json:"source"`
Value float64 `json:"value"`
Scale float64 `json:"scale"`
Votes int64 `json:"votes,omitempty"`
}
type Options ¶
type Options struct {
Client *http.Client
OMDbBaseURL string
MDBListBaseURL string
Now func() time.Time
// Sealer protects the stored API key, bound to its provider; nil
// stores it as given.
Sealer config.FieldSealer
// Certification receives the US certification (IMDb's, e.g. "TV-G")
// a provider reports with a fresh fetch, so the catalogue can rate
// titles TMDB leaves unrated. Nil ignores it.
Certification func(ctx context.Context, key core.RatingKey, label, provider string) error
// Unrated lists catalogue titles without a rating, by key after the
// given one; Run looks a few of them up each cycle (Backfill). Nil
// disables the backfill.
Unrated func(ctx context.Context, after core.RatingKey, limit int) ([]core.Title, error)
}
type Presented ¶ added in v0.3.0
type Presented struct {
Community *float64
Critic *float64
Sources []PresentedSource
}
Presented is the wire-neutral form of one title's cached provider ratings. Community is 0–10 and Critic is 0–100, matching the Jellyfin and Emby fields Android TV divides by 10 and 100. A nil pointer means that configured source had no cached value. Sources lists every cached badge, including Letterboxd, under its own name.
type PresentedSource ¶ added in v0.3.0
PresentedSource is one named score. Score is 0–100. Display is the source scale the viewer reads.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) Backfill ¶ added in v0.3.0
Backfill queues the next few catalogue titles without a rating that the provider has not answered within the cache interval, so their certification (Options.Certification) reaches titles nobody opens, such as ones a library rule hides. It walks the catalogue by key and wraps.
func (*Service) CachedMany ¶ added in v0.3.0
func (s *Service) CachedMany(ctx context.Context, titles []core.Title) (map[core.RatingKey][]Badge, error)
CachedMany is Cached for a page. Missing and expired titles are omitted. The provider being disabled returns an empty map and a nil error.
func (*Service) MigrateSecrets ¶ added in v0.2.4
MigrateSecrets seals an API key stored in plaintext; it returns 1 when it rewrote the settings. The row is replaced only if unchanged since read, and a key that does not open is left untouched.
func (*Service) Prune ¶
Prune deletes rating rows older than the maximum cache interval. It is meant to be called periodically.
func (*Service) Queue ¶
Queue is bounded, deduplicated and nonblocking; Run owns the network worker.
func (*Service) Refresh ¶
Refresh returns fresh-or-cached badges for t.
Semântica de concorrência: nenhum lock é segurado durante o HTTP — flightMu só protege o map flights (leitura/escrita curta), e cache/DB são acessados sem lock global. Chamadas concorrentes para a MESMA key compartilham um único fetch em voo (singleflight): quem espera recebe o resultado (badges/err) do líder, sem disparar outro request. Se o contexto do líder encerrou o fetch (abandoned) e o contexto de quem espera ainda está vivo, quem espera NÃO herda esse erro de cancelamento: ele refaz — vira o próximo líder ou entra no fetch seguinte. Se o contexto de quem espera é cancelado enquanto aguarda, ele retorna ctx.Err() sem cancelar o fetch do líder. Keys diferentes fazem fetch em paralelo.