playlist

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxResponseBytes bounds one remote playlist response. Parsed items
	// can require more memory than their wire representation, so callers should
	// also keep source refresh concurrency bounded.
	DefaultMaxResponseBytes int64 = 64 << 20
	// MaxResponseBytes leaves one byte of headroom for LimitedReader's
	// limit+1 oversize sentinel without overflowing int64.
	MaxResponseBytes int64 = math.MaxInt64 - 1
)

Variables

View Source
var (
	ErrPlaylistSourceNotFound           = errors.New("playlist source not found")
	ErrPlaylistSourceOrderDrift         = errors.New("playlist source set changed")
	ErrPrimaryPlaylistSourceDelete      = errors.New("primary playlist source cannot be deleted")
	ErrPrimaryPlaylistSourceOrderChange = errors.New("primary playlist source cannot be removed from reorder set")
	ErrNoEnabledPlaylistSources         = errors.New("at least one enabled playlist source is required")
	ErrPlaylistResponseTooLarge         = errors.New("playlist response exceeds configured size limit")
)

Functions

func CanonicalPlaylistSourceName added in v1.1.0

func CanonicalPlaylistSourceName(raw string) string

CanonicalPlaylistSourceName returns the normalized comparison key used for source-name uniqueness checks across config, API, and store mutation paths.

func CanonicalPlaylistSourceURL added in v1.1.0

func CanonicalPlaylistSourceURL(raw string) string

CanonicalPlaylistSourceURL returns the normalized comparison key used for source URL uniqueness checks across config, API, and store mutation paths.

Canonicalization rules: - trim surrounding whitespace - lowercase scheme and host - elide default ports - strip fragments and volatile auth/session query parameters - sort remaining query parameters deterministically - if parsing fails, fall back to lowercased raw string

func NormalizePlaylistSourceURL added in v1.1.1

func NormalizePlaylistSourceURL(raw string) string

NormalizePlaylistSourceURL returns the stored playlist URL shape used for fetch operations. It trims surrounding whitespace and lowercases scheme/host without stripping query parameters that may carry real upstream auth tokens.

Types

type CatalogStore

type CatalogStore interface {
	UpsertPlaylistItems(ctx context.Context, items []Item) error
}

CatalogStore persists playlist catalog items.

type Fetcher

type Fetcher interface {
	FetchAndParse(ctx context.Context, playlistURL string) ([]Item, error)
}

Fetcher fetches and parses playlists from an external source.

type Group

type Group struct {
	Name  string `json:"name"`
	Count int    `json:"count"`
}

Group represents a playlist group with item count.

type Item

type Item struct {
	ItemKey            string
	ChannelKey         string
	Name               string
	Group              string
	StreamURL          string
	TVGID              string
	PlaylistSourceID   int64
	PlaylistSourceName string
	Attrs              map[string]string
	FirstSeenAt        int64
	LastSeenAt         int64
	Active             bool
}

Item is a normalized playlist entry used by catalog and favorites workflows.

type Manager

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

Manager fetches and parses remote playlists.

func NewManager

func NewManager(client *http.Client, maxResponseBytes int64) (*Manager, error)

NewManager builds a playlist manager with an explicit per-response wire limit. The limit is required so wiring omissions and invalid values fail at startup instead of silently falling back to a different memory envelope.

func (*Manager) FetchAndParse

func (m *Manager) FetchAndParse(ctx context.Context, playlistURL string) ([]Item, error)

func (*Manager) FetchAndParseEach

func (m *Manager) FetchAndParseEach(ctx context.Context, playlistURL string, onItem func(Item) error) (int, error)

FetchAndParseEach fetches a remote playlist and emits normalized entries incrementally.

func (*Manager) Parse

func (m *Manager) Parse(r io.Reader) ([]Item, error)

func (*Manager) ParseEach

func (m *Manager) ParseEach(r io.Reader, onItem func(Item) error) (int, error)

ParseEach parses playlist content and emits normalized entries incrementally.

type PlaylistSource added in v1.1.0

type PlaylistSource struct {
	SourceID    int64  `json:"source_id"`
	SourceKey   string `json:"source_key"`
	Name        string `json:"name"`
	PlaylistURL string `json:"playlist_url"`
	TunerCount  int    `json:"tuner_count"`
	Enabled     bool   `json:"enabled"`
	OrderIndex  int    `json:"order_index"`
	CreatedAt   int64  `json:"created_at"`
	UpdatedAt   int64  `json:"updated_at"`
}

PlaylistSource describes one configured playlist ingest source.

type PlaylistSourceBulkUpdate added in v1.1.0

type PlaylistSourceBulkUpdate struct {
	SourceID    int64
	Name        string
	PlaylistURL string
	TunerCount  int
	Enabled     bool
}

PlaylistSourceBulkUpdate carries one ordered source mutation entry for atomic multi-source update operations.

type PlaylistSourceCreate added in v1.1.0

type PlaylistSourceCreate struct {
	Name        string `json:"name"`
	PlaylistURL string `json:"playlist_url"`
	TunerCount  int    `json:"tuner_count"`
	Enabled     *bool  `json:"enabled,omitempty"`
}

PlaylistSourceCreate carries create arguments for one playlist source.

type PlaylistSourceUpdate added in v1.1.0

type PlaylistSourceUpdate struct {
	Name        *string `json:"name,omitempty"`
	PlaylistURL *string `json:"playlist_url,omitempty"`
	TunerCount  *int    `json:"tuner_count,omitempty"`
	Enabled     *bool   `json:"enabled,omitempty"`
}

PlaylistSourceUpdate carries mutable source fields.

type Query

type Query struct {
	SourceIDs   []int64
	Group       string
	GroupNames  []string
	Search      string
	SearchRegex bool
	Limit       int
	Offset      int
}

Query controls catalog filtering and pagination.

type Refresher

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

Refresher coordinates fetch + persist operations.

func NewRefresher

func NewRefresher(fetcher Fetcher, store CatalogStore, logger ...*slog.Logger) *Refresher

func (*Refresher) RefreshForSource added in v1.1.0

func (r *Refresher) RefreshForSource(ctx context.Context, source PlaylistSource) (int, error)

RefreshForSource refreshes one playlist source into source-scoped catalog storage.

type SourceCatalogStore added in v1.1.0

type SourceCatalogStore interface {
	UpsertPlaylistItemsForSource(ctx context.Context, sourceID int64, items []Item) error
}

SourceCatalogStore persists playlist items for one playlist source.

Jump to

Keyboard shortcuts

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