dvr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDVRSyncConfig      = errors.New("dvr sync configuration error")
	ErrSyncAlreadyRunning = errors.New("dvr sync already running")
)
View Source
var (
	ErrUnsupportedProvider = errors.New("unsupported dvr provider")
)

Functions

This section is empty.

Types

type ChannelMapping

type ChannelMapping struct {
	ChannelID        int64  `json:"channel_id"`
	GuideNumber      string `json:"guide_number"`
	GuideName        string `json:"guide_name"`
	Enabled          bool   `json:"enabled"`
	DVRInstanceID    int64  `json:"dvr_instance_id"`
	DVRLineupID      string `json:"dvr_lineup_id,omitempty"`
	DVRLineupChannel string `json:"dvr_lineup_channel,omitempty"`
	DVRStationRef    string `json:"dvr_station_ref,omitempty"`
	DVRCallsignHint  string `json:"dvr_callsign_hint,omitempty"`
}

ChannelMapping stores per-channel DVR lineup association metadata.

type ChannelMappingUpdate

type ChannelMappingUpdate struct {
	DVRLineupID      string `json:"dvr_lineup_id"`
	DVRLineupChannel string `json:"dvr_lineup_channel"`
	DVRStationRef    string `json:"dvr_station_ref"`
	DVRCallsignHint  string `json:"dvr_callsign_hint"`
}

ChannelMappingUpdate is a write payload for one published channel mapping.

type ChannelsProvider

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

ChannelsProvider implements DVRProvider against Channels DVR server APIs.

func NewChannelsProvider

func NewChannelsProvider(baseURL string, client *http.Client) *ChannelsProvider

func (*ChannelsProvider) GetCustomMapping

func (p *ChannelsProvider) GetCustomMapping(ctx context.Context, lineupID string) (map[string]string, error)

func (*ChannelsProvider) ListDeviceChannels

func (p *ChannelsProvider) ListDeviceChannels(ctx context.Context) (map[string]DVRDeviceChannel, error)

func (*ChannelsProvider) ListLineupStations

func (p *ChannelsProvider) ListLineupStations(ctx context.Context, lineupID string) ([]DVRStation, error)

func (*ChannelsProvider) ListLineups

func (p *ChannelsProvider) ListLineups(ctx context.Context) ([]DVRLineup, error)

func (*ChannelsProvider) PutCustomMapping

func (p *ChannelsProvider) PutCustomMapping(ctx context.Context, lineupID string, patch map[string]string) error

func (*ChannelsProvider) RedownloadGuideLineup

func (p *ChannelsProvider) RedownloadGuideLineup(ctx context.Context, lineupID string) error

func (*ChannelsProvider) RefreshDevices

func (p *ChannelsProvider) RefreshDevices(ctx context.Context) error

func (*ChannelsProvider) RefreshGuideStations

func (p *ChannelsProvider) RefreshGuideStations(ctx context.Context) error

func (*ChannelsProvider) ReloadDeviceLineup

func (p *ChannelsProvider) ReloadDeviceLineup(ctx context.Context, deviceID string) error

func (*ChannelsProvider) Type

func (p *ChannelsProvider) Type() ProviderType

type ConfigState

type ConfigState struct {
	Instance        InstanceConfig `json:"instance"`
	CachedLineups   []DVRLineup    `json:"cached_lineups,omitempty"`
	CachedLineupsAt int64          `json:"cached_lineups_at,omitempty"`
	LastSync        *SyncResult    `json:"last_sync,omitempty"`
}

ConfigState is the API view of DVR integration state.

type DVRDeviceChannel

type DVRDeviceChannel struct {
	Key        string `json:"key"`
	DeviceID   string `json:"device_id,omitempty"`
	Number     string `json:"number,omitempty"`
	Name       string `json:"name,omitempty"`
	CallSign   string `json:"call_sign,omitempty"`
	StationRef string `json:"station_ref,omitempty"`
}

DVRDeviceChannel represents one provider device channel entry.

type DVRLineup

type DVRLineup struct {
	ID   string `json:"id"`
	Name string `json:"name,omitempty"`
}

DVRLineup describes one guide lineup/source.

type DVRProvider

type DVRProvider interface {
	Type() ProviderType
	ListLineups(ctx context.Context) ([]DVRLineup, error)
	ReloadDeviceLineup(ctx context.Context, deviceID string) error
	RefreshGuideStations(ctx context.Context) error
	RedownloadGuideLineup(ctx context.Context, lineupID string) error
	ListDeviceChannels(ctx context.Context) (map[string]DVRDeviceChannel, error)
	ListLineupStations(ctx context.Context, lineupID string) ([]DVRStation, error)
	GetCustomMapping(ctx context.Context, lineupID string) (map[string]string, error)
	PutCustomMapping(ctx context.Context, lineupID string, patch map[string]string) error
	RefreshDevices(ctx context.Context) error
}

DVRProvider encapsulates one provider implementation.

type DVRStation

type DVRStation struct {
	StationRef    string `json:"station_ref"`
	LineupChannel string `json:"lineup_channel,omitempty"`
	CallSign      string `json:"call_sign,omitempty"`
	Name          string `json:"name,omitempty"`
}

DVRStation represents one station entry inside a lineup.

type InstanceConfig

type InstanceConfig struct {
	ID                         int64          `json:"id"`
	Provider                   ProviderType   `json:"provider"`
	ActiveProviders            []ProviderType `json:"active_providers,omitempty"`
	BaseURL                    string         `json:"base_url"`
	ChannelsBaseURL            string         `json:"channels_base_url,omitempty"`
	JellyfinBaseURL            string         `json:"jellyfin_base_url,omitempty"`
	DefaultLineupID            string         `json:"default_lineup_id,omitempty"`
	SyncEnabled                bool           `json:"sync_enabled"`
	SyncCron                   string         `json:"sync_cron,omitempty"`
	SyncMode                   SyncMode       `json:"sync_mode"`
	PreSyncRefreshDevices      bool           `json:"pre_sync_refresh_devices"`
	JellyfinAPIToken           string         `json:"jellyfin_api_token,omitempty"`
	JellyfinAPITokenConfigured bool           `json:"jellyfin_api_token_configured,omitempty"`
	JellyfinTunerHostID        string         `json:"jellyfin_tuner_host_id,omitempty"`
	UpdatedAt                  int64          `json:"updated_at"`
}

InstanceConfig stores one DVR integration endpoint configuration.

type JellyfinProvider

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

JellyfinProvider implements DVRProvider against Jellyfin Live TV APIs.

func NewJellyfinProvider

func NewJellyfinProvider(instance InstanceConfig, client *http.Client) *JellyfinProvider

func (*JellyfinProvider) GetCustomMapping

func (p *JellyfinProvider) GetCustomMapping(context.Context, string) (map[string]string, error)

func (*JellyfinProvider) ListDeviceChannels

func (p *JellyfinProvider) ListDeviceChannels(context.Context) (map[string]DVRDeviceChannel, error)

func (*JellyfinProvider) ListLineupStations

func (p *JellyfinProvider) ListLineupStations(context.Context, string) ([]DVRStation, error)

func (*JellyfinProvider) ListLineups

func (p *JellyfinProvider) ListLineups(context.Context) ([]DVRLineup, error)

func (*JellyfinProvider) PutCustomMapping

func (p *JellyfinProvider) PutCustomMapping(context.Context, string, map[string]string) error

func (*JellyfinProvider) RedownloadGuideLineup

func (p *JellyfinProvider) RedownloadGuideLineup(context.Context, string) error

func (*JellyfinProvider) RefreshDevices

func (p *JellyfinProvider) RefreshDevices(context.Context) error

func (*JellyfinProvider) RefreshGuideStations

func (p *JellyfinProvider) RefreshGuideStations(context.Context) error

func (*JellyfinProvider) ReloadDeviceLineup

func (p *JellyfinProvider) ReloadDeviceLineup(ctx context.Context, deviceID string) error

func (*JellyfinProvider) Type

func (p *JellyfinProvider) Type() ProviderType

type LineupSyncResult

type LineupSyncResult struct {
	LineupID           string `json:"lineup_id"`
	ConfiguredChannels int    `json:"configured_channels"`
	ResolvedChannels   int    `json:"resolved_channels"`
	UpdatedCount       int    `json:"updated_count"`
	ClearedCount       int    `json:"cleared_count"`
	UnchangedCount     int    `json:"unchanged_count"`
	AppliedCount       int    `json:"applied_count"`
}

LineupSyncResult captures one lineup's sync work.

type ProviderType

type ProviderType string

ProviderType identifies one DVR provider implementation.

const (
	ProviderChannels ProviderType = "channels"
	ProviderJellyfin ProviderType = "jellyfin"
)

type ReverseSyncRequest

type ReverseSyncRequest struct {
	DryRun         bool   `json:"dry_run"`
	LineupID       string `json:"lineup_id,omitempty"`
	IncludeDynamic bool   `json:"include_dynamic,omitempty"`
}

ReverseSyncRequest controls pull direction sync (DVR -> hdhriptv mappings).

type ReverseSyncResult

type ReverseSyncResult struct {
	StartedAt              int64    `json:"started_at"`
	FinishedAt             int64    `json:"finished_at"`
	DurationMS             int64    `json:"duration_ms"`
	DryRun                 bool     `json:"dry_run"`
	Provider               string   `json:"provider"`
	BaseURL                string   `json:"base_url"`
	HDHRDeviceID           string   `json:"hdhr_device_id,omitempty"`
	LineupID               string   `json:"lineup_id"`
	DeviceChannelCount     int      `json:"device_channel_count"`
	FilteredChannelCount   int      `json:"filtered_channel_count"`
	CandidateCount         int      `json:"candidate_count"`
	ImportedCount          int      `json:"imported_count"`
	UnchangedCount         int      `json:"unchanged_count"`
	MissingTunerCount      int      `json:"missing_tuner_count"`
	MissingMappingCount    int      `json:"missing_mapping_count"`
	MissingStationRefCount int      `json:"missing_station_ref_count"`
	Warnings               []string `json:"warnings,omitempty"`
}

ReverseSyncResult summarizes a reverse sync run.

type Service

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

Service coordinates provider access, sync operations, and mapping persistence.

func NewService

func NewService(store Store, hdhrDeviceID string, client *http.Client) (*Service, error)

func (*Service) GetChannelMapping

func (s *Service) GetChannelMapping(ctx context.Context, channelID int64) (ChannelMapping, error)

func (*Service) GetState

func (s *Service) GetState(ctx context.Context) (ConfigState, error)

func (*Service) ListChannelMappings

func (s *Service) ListChannelMappings(ctx context.Context, enabledOnly bool, includeDynamic bool) ([]ChannelMapping, error)

func (*Service) ListChannelMappingsPaged

func (s *Service) ListChannelMappingsPaged(
	ctx context.Context,
	enabledOnly bool,
	includeDynamic bool,
	limit int,
	offset int,
) ([]ChannelMapping, int, error)

func (*Service) ListLineups

func (s *Service) ListLineups(ctx context.Context, refresh bool) ([]DVRLineup, error)

func (*Service) ReloadLineup

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

func (*Service) ReloadLineupForPlaylistSync

func (s *Service) ReloadLineupForPlaylistSync(ctx context.Context) (bool, bool, string, error)

ReloadLineupForPlaylistSync performs playlist-sync-triggered lineup refresh with provider-aware gating and optional multi-provider fan-out. Missing Jellyfin credentials are treated as explicit non-fatal skips.

func (*Service) ReverseSync

func (s *Service) ReverseSync(ctx context.Context, req ReverseSyncRequest) (ReverseSyncResult, error)

func (*Service) ReverseSyncChannel

func (s *Service) ReverseSyncChannel(
	ctx context.Context,
	channelID int64,
	req ReverseSyncRequest,
) (ReverseSyncResult, error)

func (*Service) Sync

func (s *Service) Sync(ctx context.Context, req SyncRequest) (SyncResult, error)

func (*Service) TestConnection

func (s *Service) TestConnection(ctx context.Context) (TestResult, error)

func (*Service) UpdateChannelMapping

func (s *Service) UpdateChannelMapping(
	ctx context.Context,
	channelID int64,
	update ChannelMappingUpdate,
) (ChannelMapping, error)

func (*Service) UpdateConfig

func (s *Service) UpdateConfig(ctx context.Context, instance InstanceConfig) (ConfigState, error)

type Store

type Store interface {
	GetDVRInstance(ctx context.Context) (InstanceConfig, error)
	UpsertDVRInstance(ctx context.Context, instance InstanceConfig) (InstanceConfig, error)
	ListChannelsForDVRSync(ctx context.Context, dvrInstanceID int64, enabledOnly bool, includeDynamic bool) ([]ChannelMapping, error)
	ListChannelsForDVRSyncPaged(ctx context.Context, dvrInstanceID int64, enabledOnly bool, includeDynamic bool, limit, offset int) ([]ChannelMapping, int, error)
	GetChannelDVRMapping(ctx context.Context, dvrInstanceID, channelID int64) (ChannelMapping, error)
	UpsertChannelDVRMapping(ctx context.Context, mapping ChannelMapping) (ChannelMapping, error)
	DeleteChannelDVRMapping(ctx context.Context, dvrInstanceID, channelID int64) error
}

Store describes persistence operations required by DVR integration.

type SyncMode

type SyncMode string

SyncMode controls how sync applies and clears mappings.

const (
	SyncModeConfiguredOnly SyncMode = "configured_only"
	SyncModeMirrorDevice   SyncMode = "mirror_device"
)

type SyncRequest

type SyncRequest struct {
	DryRun         bool `json:"dry_run"`
	IncludeDynamic bool `json:"include_dynamic,omitempty"`
}

SyncRequest controls sync execution behavior.

type SyncResult

type SyncResult struct {
	StartedAt            int64                        `json:"started_at"`
	FinishedAt           int64                        `json:"finished_at"`
	DurationMS           int64                        `json:"duration_ms"`
	DryRun               bool                         `json:"dry_run"`
	Provider             string                       `json:"provider"`
	BaseURL              string                       `json:"base_url"`
	HDHRDeviceID         string                       `json:"hdhr_device_id,omitempty"`
	SyncMode             SyncMode                     `json:"sync_mode"`
	DeviceChannelCount   int                          `json:"device_channel_count"`
	FilteredChannelCount int                          `json:"filtered_channel_count"`
	UpdatedCount         int                          `json:"updated_count"`
	ClearedCount         int                          `json:"cleared_count"`
	UnchangedCount       int                          `json:"unchanged_count"`
	MissingTunerCount    int                          `json:"missing_tuner_count"`
	UnresolvedCount      int                          `json:"unresolved_count"`
	Lineups              []LineupSyncResult           `json:"lineups"`
	Warnings             []string                     `json:"warnings,omitempty"`
	PatchPreview         map[string]map[string]string `json:"patch_preview,omitempty"`
}

SyncResult summarizes one sync run.

type TestResult

type TestResult struct {
	Reachable              bool   `json:"reachable"`
	Provider               string `json:"provider"`
	BaseURL                string `json:"base_url"`
	DeviceChannelCount     int    `json:"device_channel_count"`
	FilteredChannelCount   int    `json:"filtered_channel_count"`
	HDHRDeviceID           string `json:"hdhr_device_id,omitempty"`
	HDHRDeviceFilterActive bool   `json:"hdhr_device_filter_active"`
}

TestResult summarizes provider connectivity.

Jump to

Keyboard shortcuts

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