domain

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrItemNotFound indicates the requested media item does not exist
	ErrItemNotFound = errors.New("media item not found")

	// ErrServerOffline indicates the media server is unreachable
	ErrServerOffline = errors.New("media server is unreachable")

	// ErrAuthFailed indicates authentication failed
	ErrAuthFailed = errors.New("authentication token is invalid")
)

Sentinel errors for domain operations

Functions

This section is empty.

Types

type Library

type Library struct {
	ID        string // Server-specific unique identifier
	Name      string // Display name
	Type      string // "movie" or "show"
	UpdatedAt int64  // Server's contentChangedAt timestamp
}

Library represents a media server library section

func (*Library) CanDrillDown

func (l *Library) CanDrillDown() bool

func (*Library) GetAddedAt

func (l *Library) GetAddedAt() int64

func (*Library) GetDescription

func (l *Library) GetDescription() string

func (*Library) GetDuration

func (l *Library) GetDuration() time.Duration

func (*Library) GetID

func (l *Library) GetID() string

func (*Library) GetItemType

func (l *Library) GetItemType() string

func (*Library) GetLibraryID added in v1.0.3

func (l *Library) GetLibraryID() string

func (*Library) GetRating

func (l *Library) GetRating() float64

func (*Library) GetSortTitle

func (l *Library) GetSortTitle() string

func (*Library) GetTitle

func (l *Library) GetTitle() string

func (*Library) GetUpdatedAt

func (l *Library) GetUpdatedAt() int64

func (*Library) GetWatchStatus

func (l *Library) GetWatchStatus() WatchStatus

func (*Library) GetYear

func (l *Library) GetYear() int

type LibraryClient

type LibraryClient interface {
	GetLibraries(ctx context.Context) ([]Library, error)
	GetMovies(ctx context.Context, libID string, offset, limit int) ([]*MediaItem, int, error)
	GetShows(ctx context.Context, libID string, offset, limit int) ([]*Show, int, error)
	GetMixedContent(ctx context.Context, libID string, offset, limit int) ([]ListItem, int, error)
	GetSeasons(ctx context.Context, showID string) ([]*Season, error)
	GetEpisodes(ctx context.Context, seasonID string) ([]*MediaItem, error)
	GetContinueWatching(ctx context.Context) ([]*MediaItem, error)
}

LibraryClient provides network operations for library browsing.

type ListItem

type ListItem interface {
	// GetID returns the unique identifier for this item
	GetID() string

	// GetLibraryID returns the parent library ID
	GetLibraryID() string

	// GetTitle returns the display title
	GetTitle() string

	// GetSortTitle returns the title used for alphabetical sorting (handles "The", "A", etc.)
	GetSortTitle() string

	// GetYear returns the release/air year (0 if not applicable)
	GetYear() int

	// GetDescription returns secondary info for display (e.g., "2024" for movies, "3 Seasons" for shows)
	GetDescription() string

	// GetItemType returns the type identifier: "movie", "show", "season", "episode"
	GetItemType() string

	// GetWatchStatus returns the watch status for indicator rendering
	GetWatchStatus() WatchStatus

	// CanDrillDown returns true if this item can be drilled into (shows child content)
	CanDrillDown() bool

	// GetAddedAt returns the unix timestamp when added to library (0 if not applicable)
	GetAddedAt() int64

	// GetUpdatedAt returns the unix timestamp when last updated (0 if not applicable)
	GetUpdatedAt() int64

	// GetDuration returns the duration (0 if not applicable)
	GetDuration() time.Duration

	// GetRating returns the audience/community rating 0-10 (0 if not applicable)
	GetRating() float64
}

ListItem is the polymorphic interface for items that can be displayed in lists. It provides a common API for display, filtering, and sorting across all content types. Domain entities (MediaItem, Show, Season) implement this interface directly.

type MediaItem

type MediaItem struct {
	ID         string        // Server-specific unique identifier
	Title      string        // Display title
	SortTitle  string        // Title used for sorting
	LibraryID  string        // Parent library ID
	Summary    string        // Plot synopsis
	Year       int           // Release year
	AddedAt    int64         // Unix timestamp when added to library
	UpdatedAt  int64         // Unix timestamp when last updated
	Duration   time.Duration // Total runtime
	ViewOffset time.Duration // Watch progress
	IsPlayed   bool          // Whether item is marked as watched
	Type       MediaType     // Movie or Episode

	// Episode-specific fields (empty for movies)
	ShowTitle  string // Parent show name
	ShowID     string // Parent show ID (for navigation)
	SeasonNum  int    // Season number (0 = specials)
	EpisodeNum int    // Episode number within season
	ParentID   string // Season ID (for navigation)

	// Rating (0-10 scale, audience/community rating)
	Rating float64

	// Content rating (e.g., "PG-13", "R", "TV-MA")
	ContentRating string

	// Technical metadata
	AirDate       string // Full release/air date (e.g. "2023-10-25")
	FileSize      int64  // File size in bytes
	Bitrate       int    // Bitrate in kbps
	Width         int    // Video width in pixels
	Height        int    // Video height in pixels
	VideoCodec    string // Normalized: "HEVC", "H.264", "AV1"
	AudioCodec    string // Normalized: "AAC", "AC3", "DTS"
	AudioChannels int    // Channel count: 2, 6, 8
	Container     string // "mkv", "mp4"

	// Image URLs
	ThumbURL string // Poster/thumbnail image URL
	ArtURL   string // Background art URL
}

MediaItem represents a playable item (Movie or Episode)

func (*MediaItem) CanDrillDown

func (m *MediaItem) CanDrillDown() bool

func (MediaItem) ChannelLayout

func (m MediaItem) ChannelLayout() string

ChannelLayout returns the audio channel layout as a string

func (MediaItem) EpisodeCode

func (m MediaItem) EpisodeCode() string

EpisodeCode returns the formatted episode code (e.g., "S01E05")

func (MediaItem) FormattedDuration

func (m MediaItem) FormattedDuration() string

FormattedDuration returns the duration in a human-readable format

func (MediaItem) FormattedFileSize

func (m MediaItem) FormattedFileSize() string

FormattedFileSize returns the file size in a human-readable format

func (*MediaItem) GetAddedAt

func (m *MediaItem) GetAddedAt() int64

func (*MediaItem) GetDescription

func (m *MediaItem) GetDescription() string

func (*MediaItem) GetDuration

func (m *MediaItem) GetDuration() time.Duration

func (*MediaItem) GetID

func (m *MediaItem) GetID() string

func (*MediaItem) GetItemType

func (m *MediaItem) GetItemType() string

func (*MediaItem) GetLibraryID added in v1.0.3

func (m *MediaItem) GetLibraryID() string

func (*MediaItem) GetRating

func (m *MediaItem) GetRating() float64

func (*MediaItem) GetSortTitle

func (m *MediaItem) GetSortTitle() string

func (*MediaItem) GetTitle

func (m *MediaItem) GetTitle() string

func (*MediaItem) GetUpdatedAt

func (m *MediaItem) GetUpdatedAt() int64

func (*MediaItem) GetWatchStatus

func (m *MediaItem) GetWatchStatus() WatchStatus

func (*MediaItem) GetYear

func (m *MediaItem) GetYear() int

func (MediaItem) Resolution

func (m MediaItem) Resolution() string

Resolution returns a human-readable resolution string based on video width and height

func (MediaItem) ShouldResume

func (m MediaItem) ShouldResume() bool

ShouldResume returns true if playback should resume from saved position

func (MediaItem) WatchStatus

func (m MediaItem) WatchStatus() WatchStatus

WatchStatus returns the watch status of the media item

type MediaType

type MediaType int

MediaType distinguishes content types

const (
	MediaTypeMovie MediaType = iota
	MediaTypeShow
	MediaTypeSeason
	MediaTypeEpisode
)

type PlayableMedia added in v1.0.1

type PlayableMedia struct {
	URL       string
	Subtitles []Subtitle
}

PlayableMedia describes everything the player needs to play an item: the main media URL plus any external (sidecar) subtitle tracks the server exposes.

type PlaybackClient

type PlaybackClient interface {
	ResolvePlayable(ctx context.Context, itemID string) (PlayableMedia, error)
	MarkPlayed(ctx context.Context, itemID string) error
	MarkUnplayed(ctx context.Context, itemID string) error
	// UpdateProgress reports the current playback position to the server.
	// positionMs is the current position in milliseconds.
	UpdateProgress(ctx context.Context, itemID string, positionMs int64) error
}

PlaybackClient provides network operations for media playback.

type Playlist

type Playlist struct {
	ID           string        // Playlist identifier
	Title        string        // Display title
	PlaylistType string        // "video", "audio", "photo"
	Smart        bool          // Smart/dynamic playlist
	ItemCount    int           // Number of items in playlist
	Duration     time.Duration // Total duration of all items
	UpdatedAt    int64         // Unix timestamp when last updated
}

Playlist represents a user-created playlist

func (*Playlist) CanDrillDown

func (p *Playlist) CanDrillDown() bool

func (*Playlist) GetAddedAt

func (p *Playlist) GetAddedAt() int64

func (*Playlist) GetDescription

func (p *Playlist) GetDescription() string

func (*Playlist) GetDuration

func (p *Playlist) GetDuration() time.Duration

func (*Playlist) GetID

func (p *Playlist) GetID() string

func (*Playlist) GetItemType

func (p *Playlist) GetItemType() string

func (*Playlist) GetLibraryID added in v1.0.3

func (p *Playlist) GetLibraryID() string

func (*Playlist) GetRating

func (p *Playlist) GetRating() float64

func (*Playlist) GetSortTitle

func (p *Playlist) GetSortTitle() string

func (*Playlist) GetTitle

func (p *Playlist) GetTitle() string

func (*Playlist) GetUpdatedAt

func (p *Playlist) GetUpdatedAt() int64

func (*Playlist) GetWatchStatus

func (p *Playlist) GetWatchStatus() WatchStatus

func (*Playlist) GetYear

func (p *Playlist) GetYear() int

type PlaylistClient

type PlaylistClient interface {
	GetPlaylists(ctx context.Context) ([]*Playlist, error)
	GetPlaylistItems(ctx context.Context, playlistID string) ([]*MediaItem, error)
	CreatePlaylist(ctx context.Context, title string, itemIDs []string) (*Playlist, error)
	AddToPlaylist(ctx context.Context, playlistID string, itemIDs []string) error
	RemoveFromPlaylist(ctx context.Context, playlistID string, itemID string) error
	DeletePlaylist(ctx context.Context, playlistID string) error
}

PlaylistClient provides network operations for playlist management.

type ProgressFunc

type ProgressFunc func(loaded, total int)

ProgressFunc reports download progress to TUI. Called repeatedly during pagination: (50, 500), (100, 500), ...

type SearchClient

type SearchClient interface {
	Search(ctx context.Context, query string) ([]*MediaItem, error)
}

SearchClient provides network search functionality.

type Season

type Season struct {
	ID             string // Server-specific unique identifier
	LibraryID      string // Parent library ID
	ShowID         string // Parent show ID
	ShowTitle      string // Parent show name
	SeasonNum      int    // Season number (0 = Specials)
	Title          string // "Season 1" or custom name
	EpisodeCount   int    // Total number of episodes
	UnwatchedCount int    // Number of unwatched episodes

	// Image URLs
	ThumbURL string // Poster/thumbnail image URL
}

Season represents a season container

func (*Season) CanDrillDown

func (s *Season) CanDrillDown() bool

func (Season) DisplayTitle

func (s Season) DisplayTitle() string

DisplayTitle returns the display title for the season

func (*Season) GetAddedAt

func (s *Season) GetAddedAt() int64

func (*Season) GetDescription

func (s *Season) GetDescription() string

func (*Season) GetDuration

func (s *Season) GetDuration() time.Duration

func (*Season) GetID

func (s *Season) GetID() string

func (*Season) GetItemType

func (s *Season) GetItemType() string

func (*Season) GetLibraryID added in v1.0.3

func (s *Season) GetLibraryID() string

func (*Season) GetRating

func (s *Season) GetRating() float64

func (*Season) GetSortTitle

func (s *Season) GetSortTitle() string

func (*Season) GetTitle

func (s *Season) GetTitle() string

func (*Season) GetUpdatedAt

func (s *Season) GetUpdatedAt() int64

func (*Season) GetWatchStatus

func (s *Season) GetWatchStatus() WatchStatus

func (*Season) GetYear

func (s *Season) GetYear() int

func (Season) WatchStatus

func (s Season) WatchStatus() WatchStatus

WatchStatus returns the watch status of the season

type Show

type Show struct {
	ID             string // Server-specific unique identifier
	Title          string // Series title
	SortTitle      string // Title used for sorting
	LibraryID      string // Parent library ID
	Summary        string // Series synopsis
	Year           int    // First air year
	AddedAt        int64  // Unix timestamp when added to library
	UpdatedAt      int64  // Unix timestamp when last updated
	SeasonCount    int    // Total number of seasons
	EpisodeCount   int    // Total number of episodes
	UnwatchedCount int    // Number of unwatched episodes

	// Rating (0-10 scale, audience/community rating)
	Rating float64

	// Content rating (e.g., "TV-MA", "TV-PG")
	ContentRating string

	// Image URLs
	ThumbURL string // Poster/thumbnail image URL
	ArtURL   string // Background art URL
}

Show represents a TV series container

func (*Show) CanDrillDown

func (s *Show) CanDrillDown() bool

func (*Show) GetAddedAt

func (s *Show) GetAddedAt() int64

func (*Show) GetDescription

func (s *Show) GetDescription() string

func (*Show) GetDuration

func (s *Show) GetDuration() time.Duration

func (*Show) GetID

func (s *Show) GetID() string

func (*Show) GetItemType

func (s *Show) GetItemType() string

func (*Show) GetLibraryID added in v1.0.3

func (s *Show) GetLibraryID() string

func (*Show) GetRating

func (s *Show) GetRating() float64

func (*Show) GetSortTitle

func (s *Show) GetSortTitle() string

func (*Show) GetTitle

func (s *Show) GetTitle() string

func (*Show) GetUpdatedAt

func (s *Show) GetUpdatedAt() int64

func (*Show) GetWatchStatus

func (s *Show) GetWatchStatus() WatchStatus

func (*Show) GetYear

func (s *Show) GetYear() int

func (Show) WatchStatus

func (s Show) WatchStatus() WatchStatus

WatchStatus returns the watch status of the show

type Store

type Store interface {
	// === Libraries ===
	GetLibraries() ([]Library, bool)
	SaveLibraries(libs []Library) error

	// === Library Content ===
	GetMovies(libID string) ([]*MediaItem, bool)
	SaveMovies(libID string, movies []*MediaItem, serverTS int64) error

	GetShows(libID string) ([]*Show, bool)
	SaveShows(libID string, shows []*Show, serverTS int64) error

	GetMixedContent(libID string) ([]ListItem, bool)
	SaveMixedContent(libID string, items []ListItem, serverTS int64) error

	// === Hierarchical (TV) ===
	GetSeasons(libID, showID string) ([]*Season, bool)
	SaveSeasons(libID, showID string, seasons []*Season) error

	GetEpisodes(libID, showID, seasonID string) ([]*MediaItem, bool)
	GetAllEpisodes(libID string) ([]*MediaItem, bool)
	SaveEpisodes(libID, showID, seasonID string, episodes []*MediaItem) error

	// === Playlists ===
	GetPlaylists() ([]*Playlist, bool)
	SavePlaylists(playlists []*Playlist) error

	GetPlaylistItems(playlistID string) ([]*MediaItem, bool)
	SavePlaylistItems(playlistID string, items []*MediaItem) error

	// === Local Queue ===
	GetQueueItems() ([]*MediaItem, bool)
	SaveQueueItems(items []*MediaItem) error

	// === Freshness ===
	IsValid(libID string, serverTS int64) bool

	// === Invalidation ===
	InvalidateLibrary(libID string)
	InvalidateShow(libID, showID string)
	InvalidateSeason(libID, showID, seasonID string)
	InvalidatePlaylists()
	InvalidatePlaylistItems(playlistID string)
	InvalidateQueue()
	InvalidateAll()

	Close() error
}

Store handles local cache (BoltDB + memory). TUI reads directly from Store for cache access.

type Subtitle added in v1.0.1

type Subtitle struct {
	URL      string // Direct URL the player can fetch
	Language string // ISO language code, e.g. "eng", "spa"
	Title    string // Human-readable label (may be empty)
	Codec    string // e.g. "srt", "ass", "vtt"
	Default  bool   // Server marked this track as default
	Forced   bool   // Forced subtitle track
}

Subtitle describes an external subtitle track that the player should side-load.

type SyncResult

type SyncResult struct {
	LibraryID string // Which library this result is for
	FromCache bool   // true if cache was fresh (no network fetch)
	Count     int    // total items after sync
}

SyncResult summarizes what happened during a sync operation.

type WatchStatus

type WatchStatus int

WatchStatus represents the viewing state of media

const (
	WatchStatusUnwatched WatchStatus = iota
	WatchStatusInProgress
	WatchStatusWatched
)

func (WatchStatus) String

func (w WatchStatus) String() string

String returns a human-readable representation of the watch status

Jump to

Keyboard shortcuts

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