aggregator

package
v0.3.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

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

Aggregator combines metadata from multiple scrapers based on priority

func New

func New(cfg *config.Config) *Aggregator

New creates a new aggregator

func NewWithDatabase

func NewWithDatabase(cfg *config.Config, db *database.DB) *Aggregator

NewWithDatabase creates a new aggregator with database support for genre replacements and actress aliases. This is the production constructor - for testable constructor see NewWithOptions. Refactored in Epic 8 Story 8.2 to wrap NewWithOptions for backward compatibility.

func NewWithOptions

func NewWithOptions(cfg *config.Config, opts *AggregatorOptions) *Aggregator

NewWithOptions creates a new aggregator with optional dependency injection. If opts is nil or opts fields are nil, real implementations are created or database loading is skipped. If opts fields are non-nil, injected dependencies are used (for testing). Added in Epic 8 Story 8.2 to enable testable aggregator initialization.

Production usage: Use NewWithDatabase() instead Test usage: aggregator.NewWithOptions(cfg, &AggregatorOptions{GenreCache: mockCache})

func (*Aggregator) Aggregate

func (a *Aggregator) Aggregate(results []*models.ScraperResult) (*models.Movie, string, error)

Aggregate combines multiple scraper results into a single Movie

func (*Aggregator) AggregateWithPriority

func (a *Aggregator) AggregateWithPriority(results []*models.ScraperResult, customPriority []string) (*models.Movie, string, error)

func (*Aggregator) ApplyConfiguredTranslation

func (a *Aggregator) ApplyConfiguredTranslation(movie *models.Movie) string

func (*Aggregator) Config

func (a *Aggregator) Config() *config.Config

func (*Aggregator) GetResolvedPriorities

func (a *Aggregator) GetResolvedPriorities() map[string][]string

GetResolvedPriorities returns the cached field-level priority map (for debugging) Implements AggregatorInterface

func (*Aggregator) ReloadGenreReplacements

func (a *Aggregator) ReloadGenreReplacements()

ReloadGenreReplacements reloads the genre replacement cache from database

func (*Aggregator) ReloadWordReplacements

func (a *Aggregator) ReloadWordReplacements()

func (*Aggregator) TemplateEngine

func (a *Aggregator) TemplateEngine() *template.Engine

type AggregatorInterface

type AggregatorInterface interface {
	Aggregate(results []*models.ScraperResult) (*models.Movie, string, error)

	AggregateWithPriority(results []*models.ScraperResult, customPriority []string) (*models.Movie, string, error)

	GetResolvedPriorities() map[string][]string
}

AggregatorInterface abstracts aggregator operations for dependency injection. Allows CLI commands and API endpoints to accept either real Aggregator or test mocks. Added in Epic 8 Story 8.2 to enable testable aggregation logic.

type AggregatorOptions

type AggregatorOptions struct {
	// GenreReplacementRepo is an optional genre replacement repository for tests.
	// If nil, loadGenreReplacementCache() is skipped (empty cache).
	// If non-nil, genre replacements are loaded from the repository during initialization.
	GenreReplacementRepo database.GenreReplacementRepositoryInterface

	// ActressAliasRepo is an optional actress alias repository for tests.
	// If nil, loadActressAliasCache() is skipped (empty cache).
	// If non-nil, actress aliases are loaded from the repository during initialization.
	ActressAliasRepo database.ActressAliasRepositoryInterface

	// WordReplacementRepo is an optional word replacement repository for tests.
	// If nil, loadWordReplacementCache() is skipped (empty cache).
	// If non-nil, word replacements are loaded from the repository during initialization.
	WordReplacementRepo database.WordReplacementRepositoryInterface

	// TemplateEngine is an optional template engine for tests.
	// If nil, a real template.NewEngine() is created.
	// If non-nil, the injected template engine is used.
	TemplateEngine *template.Engine

	// GenreCache is an optional pre-populated genre replacement cache for tests.
	// If non-nil, this cache is used directly without loading from database.
	// Takes precedence over GenreReplacementRepo if both are provided.
	GenreCache map[string]string

	// WordCache is an optional pre-populated word replacement cache for tests.
	// If non-nil, this cache is used directly without loading from database.
	// Takes precedence over WordReplacementRepo if both are provided.
	WordCache map[string]string

	// ActressCache is an optional pre-populated actress alias cache for tests.
	// If non-nil, this cache is used directly without loading from database.
	// Takes precedence over ActressAliasRepo if both are provided.
	ActressCache map[string]string

	// Scrapers is an optional list of scrapers for dependency injection.
	// If non-nil, the scrapers are used in order as their priority for aggregation.
	// If nil, scraperutil.GetPriorities() is used for backward compatibility.
	Scrapers []models.Scraper
}

AggregatorOptions allows optional dependency injection for testing. Fields left nil will be initialized with real implementations or skipped entirely. Added in Epic 8 Story 8.2 to support testable aggregator initialization.

Jump to

Keyboard shortcuts

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