dvr

package
v1.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ReloadStatusDisabled = "disabled"
	ReloadStatusReloaded = "reloaded"
	ReloadStatusPartial  = "partial"
	ReloadStatusSkipped  = "skipped"
	ReloadStatusUnknown  = "unknown"
)

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

func ProviderBaseURL added in v1.0.3

func ProviderBaseURL(instance InstanceConfig, provider ProviderType) string

ProviderBaseURL resolves the provider-scoped base URL from the merged BaseURL/ChannelsBaseURL/JellyfinBaseURL fields.

func ProviderBaseURLConfigured added in v1.0.3

func ProviderBaseURLConfigured(raw string) bool

ProviderBaseURLConfigured returns true when the value is a non-empty absolute URL with scheme and host.

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 LineupReloadProvider and MappingProvider 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 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.

func NormalizeForProvider added in v1.0.3

func NormalizeForProvider(instance InstanceConfig, provider ProviderType) InstanceConfig

NormalizeForProvider returns a canonical provider-scoped view of the instance.

func NormalizeInstanceConfig added in v1.0.3

func NormalizeInstanceConfig(instance InstanceConfig, current InstanceConfig) InstanceConfig

NormalizeInstanceConfig canonicalizes API update payloads against the current stored instance while preserving existing provider-specific URLs when omitted.

func NormalizeStoredInstance added in v1.0.3

func NormalizeStoredInstance(instance InstanceConfig) InstanceConfig

NormalizeStoredInstance canonicalizes persisted/read-back config shape.

type JellyfinProvider

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

JellyfinProvider implements LineupReloadProvider against Jellyfin Live TV APIs.

func NewJellyfinProvider

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

func (*JellyfinProvider) ListLineups

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

func (*JellyfinProvider) RedownloadGuideLineup

func (p *JellyfinProvider) RedownloadGuideLineup(context.Context, string) 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 LineupReloadProvider added in v1.0.3

type LineupReloadProvider interface {
	ProviderBase
	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
}

LineupReloadProvider supports lineup reload + guide refresh flows.

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 MappingProvider added in v1.0.3

type MappingProvider interface {
	ProviderBase
	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
}

MappingProvider supports forward/reverse mapping sync behavior.

type ProviderBase added in v1.0.3

type ProviderBase interface {
	Type() ProviderType
}

ProviderBase exposes common provider identity behavior.

type ProviderType

type ProviderType string

ProviderType identifies one DVR provider implementation.

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

func NormalizeProviderType added in v1.0.3

func NormalizeProviderType(provider ProviderType) ProviderType

NormalizeProviderType canonicalizes provider values while preserving unknown inputs for upstream validation.

type ReloadOutcome added in v1.0.3

type ReloadOutcome struct {
	Reloaded          bool                    `json:"reloaded"`
	Skipped           bool                    `json:"skipped"`
	Status            string                  `json:"status"`
	SkipReasons       []string                `json:"skip_reasons,omitempty"`
	ReloadedProviders []ProviderType          `json:"reloaded_providers,omitempty"`
	SkippedProviders  map[ProviderType]string `json:"skipped_providers,omitempty"`
}

ReloadOutcome captures provider-aware DVR lineup reload state.

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) ReloadLineupForPlaylistSyncOutcome added in v1.0.3

func (s *Service) ReloadLineupForPlaylistSyncOutcome(ctx context.Context) (ReloadOutcome, error)

ReloadLineupForPlaylistSyncOutcome is the typed variant used by playlist-sync orchestration paths and summary rendering.

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"
)

func NormalizeSyncMode added in v1.0.3

func NormalizeSyncMode(mode SyncMode) SyncMode

NormalizeSyncMode canonicalizes sync mode values and falls back to the configured-only mode for unknown or empty inputs.

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