providers

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAllProviders

func CheckAllProviders(ctx context.Context)

CheckAllProviders runs health checks on all providers in the global registry.

func Clear

func Clear()

Clear removes all providers from the global registry

func ConfigureAll

func ConfigureAll(cfg *config.Config, logger *slog.Logger)

ConfigureAll configures all registered providers that implement the Configurable interface

func Count

func Count() int

Count returns the number of registered providers in the global registry

func List

func List() []string

List returns the names of all registered providers from the global registry

func Register

func Register(provider Provider) error

Register adds a provider to the global registry

func Unregister

func Unregister(name string) error

Unregister removes a provider from the global registry

Types

type AudioTrack

type AudioTrack struct {
	Index    int    `json:"index"`    // mpv track index (1-based)
	Language string `json:"language"` // "en", "ja", etc.
	Label    string `json:"label"`    // Provider's original label: "English (Dub)", "Japanese (Original)"
	Type     string `json:"type"`     // "dub", "sub", "original", "unknown"
}

AudioTrack represents an audio track option

type Configurable

type Configurable interface {
	SetConfig(cfg *config.Config, logger *slog.Logger)
}

Configurable is an interface for providers that can be configured at runtime

type Episode

type Episode struct {
	ID           string        `json:"id"`
	Number       int           `json:"number"`
	Season       int           `json:"season"`
	Title        string        `json:"title"`
	Synopsis     string        `json:"synopsis"`
	ThumbnailURL string        `json:"thumbnail_url"`
	Duration     time.Duration `json:"duration"`
	ReleaseDate  time.Time     `json:"release_date"`
}

Episode represents a single episode or movie

func GetChaptersAsEpisodesFromAPIInfo

func GetChaptersAsEpisodesFromAPIInfo(ir api.InfoResponse) []Episode

GetChaptersAsEpisodesFromAPIInfo converts manga chapters to episodes

func GetEpisodesFromAPIInfo

func GetEpisodesFromAPIInfo(ir api.InfoResponse, seasonNumber int) []Episode

GetEpisodesFromAPIInfo extracts episodes for a specific season from InfoResponse

func GetEpisodesFromAPIInfoWithMediaID

func GetEpisodesFromAPIInfoWithMediaID(ir api.InfoResponse, seasonNumber int, mediaID string) []Episode

GetEpisodesFromAPIInfoWithMediaID extracts episodes with full media ID prefix for providers like HiAnime Format: {mediaID}$episode${episodeID}

func ParseEpisodeRange

func ParseEpisodeRange(allEpisodes []Episode, rangeStr string) ([]Episode, error)

ParseEpisodeRange parses an episode range string (e.g., "1-5,7,9-12") and returns the matching episodes from the provided list.

Supported formats:

  • Single episode: "5"
  • Range: "1-5"
  • Multiple: "1-5,7,9-12"

type ErrInvalidQuality

type ErrInvalidQuality struct {
	Quality string
}

ErrInvalidQuality is returned when an invalid quality string is provided

func (*ErrInvalidQuality) Error

func (e *ErrInvalidQuality) Error() string

type HealthCheckResult

type HealthCheckResult struct {
	URL         string
	CurlCommand string
	StatusCode  int
	Duration    time.Duration
	Error       string
	CheckedAt   time.Time
}

HealthCheckResult holds detailed health check information

type MangaProvider

type MangaProvider interface {
	Provider
	GetMangaPages(ctx context.Context, chapterID string) ([]string, error)
}

MangaProvider defines the interface for manga providers

type Media

type Media struct {
	ID            string    `json:"id"`
	Title         string    `json:"title"`
	Type          MediaType `json:"type"`
	Year          int       `json:"year"`
	Synopsis      string    `json:"synopsis"`
	PosterURL     string    `json:"poster_url"`
	Rating        float64   `json:"rating"`
	Genres        []string  `json:"genres"`
	TotalEpisodes int       `json:"total_episodes"`
	Status        string    `json:"status"` // "Ongoing", "Completed", etc.
}

Media represents a single media item

func APIResultToMedia

func APIResultToMedia(sr api.SearchResult, mediaType MediaType) Media

APIResultToMedia converts a SearchResult to Media

type MediaDetails

type MediaDetails struct {
	Media
	Seasons   []Season `json:"seasons"`
	Cast      []string `json:"cast"`
	Studio    string   `json:"studio"`   // For anime
	Director  string   `json:"director"` // For movies
	AniListID int      `json:"anilist_id,omitempty"`
	IMDBID    string   `json:"imdb_id,omitempty"`
}

MediaDetails provides extended information about a media item

func APIInfoToMediaDetails

func APIInfoToMediaDetails(ir api.InfoResponse, mediaType MediaType) *MediaDetails

APIInfoToMediaDetails converts InfoResponse to MediaDetails

type MediaType

type MediaType string

MediaType represents the type of media content

const (
	MediaTypeAnime        MediaType = "anime"
	MediaTypeMovie        MediaType = "movie"
	MediaTypeTV           MediaType = "tv"
	MediaTypeMovieTV      MediaType = "movie_tv"       // Supports both movies and TV
	MediaTypeAnimeMovieTV MediaType = "anime_movie_tv" // Supports anime, movies, and TV
	MediaTypeManga        MediaType = "manga"          // Supports manga
	MediaTypeAll          MediaType = "all"            // Supports all types
)

type Provider

type Provider interface {
	// Metadata
	Name() string
	Type() MediaType

	// Search and discovery
	Search(ctx context.Context, query string) ([]Media, error)
	GetTrending(ctx context.Context) ([]Media, error)
	GetRecent(ctx context.Context) ([]Media, error)

	// Media details
	GetMediaDetails(ctx context.Context, id string) (*MediaDetails, error)
	GetSeasons(ctx context.Context, mediaID string) ([]Season, error)
	GetEpisodes(ctx context.Context, seasonID string) ([]Episode, error)

	// Stream URLs
	GetStreamURL(ctx context.Context, episodeID string, quality Quality) (*StreamURL, error)
	GetAvailableQualities(ctx context.Context, episodeID string) ([]Quality, error)

	// Health check
	HealthCheck(ctx context.Context) error
}

Provider defines the interface for streaming providers

func Get

func Get(name string) (Provider, error)

Get returns a provider by name from the global registry

func GetAll

func GetAll() []Provider

GetAll returns all registered providers from the global registry

func GetByType

func GetByType(mediaType MediaType) []Provider

GetByType returns all providers that support the given media type from the global registry

type ProviderStatus

type ProviderStatus struct {
	ProviderName string
	Healthy      bool
	Status       string // e.g., "Online", "Offline", "Error: ...", "Checking..."
	LastCheck    time.Time
	LastResult   *HealthCheckResult
}

ProviderStatus holds the health status of a provider

func GetProviderStatuses

func GetProviderStatuses() []*ProviderStatus

GetProviderStatuses returns the health statuses from the global registry.

type Quality

type Quality string

Quality represents video quality levels

const (
	Quality360p  Quality = "360p"
	Quality480p  Quality = "480p"
	Quality720p  Quality = "720p"
	Quality1080p Quality = "1080p"
	Quality1440p Quality = "1440p"
	Quality4K    Quality = "2160p"
	QualityAuto  Quality = "auto"
)

func ParseQuality

func ParseQuality(s string) (Quality, error)

ParseQuality parses a quality string into a Quality type

func (Quality) ResolutionHeight

func (q Quality) ResolutionHeight() int

ResolutionHeight returns the vertical resolution in pixels

func (Quality) String

func (q Quality) String() string

String returns the string representation of Quality

type Registry

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

Registry manages registered providers and their health statuses

func GetRegistry

func GetRegistry() *Registry

GetRegistry returns the global registry instance

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new provider registry

func (*Registry) CheckAllProviders

func (r *Registry) CheckAllProviders(ctx context.Context)

CheckAllProviders runs a health check on all registered providers concurrently.

func (*Registry) Clear

func (r *Registry) Clear()

Clear removes all providers from the registry

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered providers

func (*Registry) Get

func (r *Registry) Get(name string) (Provider, error)

Get returns a provider by name

func (*Registry) GetAll

func (r *Registry) GetAll() []Provider

GetAll returns all registered providers

func (*Registry) GetByType

func (r *Registry) GetByType(mediaType MediaType) []Provider

GetByType returns all providers that support the given media type

func (*Registry) GetProviderStatuses

func (r *Registry) GetProviderStatuses() []*ProviderStatus

GetProviderStatuses returns the health status of all registered providers.

func (*Registry) List

func (r *Registry) List() []string

List returns the names of all registered providers

func (*Registry) Reconfigure

func (r *Registry) Reconfigure(cfg *config.Config, logger *slog.Logger)

Reconfigure updates providers based on configuration

func (*Registry) Register

func (r *Registry) Register(provider Provider) error

Register adds a provider to the registry

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a provider from the registry

type RemoteProvider

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

RemoteProvider adapts the local Provider interface to a remote API

func NewRemoteProvider

func NewRemoteProvider(name string, pType MediaType, cfg *config.Config, logger *slog.Logger) *RemoteProvider

NewRemoteProvider creates a new remote provider adapter

func (*RemoteProvider) GetAvailableQualities

func (p *RemoteProvider) GetAvailableQualities(ctx context.Context, episodeID string) ([]Quality, error)

func (*RemoteProvider) GetEpisodes

func (p *RemoteProvider) GetEpisodes(ctx context.Context, seasonID string) ([]Episode, error)

func (*RemoteProvider) GetMediaDetails

func (p *RemoteProvider) GetMediaDetails(ctx context.Context, id string) (*MediaDetails, error)

func (*RemoteProvider) GetRecent

func (p *RemoteProvider) GetRecent(ctx context.Context) ([]Media, error)

func (*RemoteProvider) GetSeasons

func (p *RemoteProvider) GetSeasons(ctx context.Context, mediaID string) ([]Season, error)

func (*RemoteProvider) GetStreamURL

func (p *RemoteProvider) GetStreamURL(ctx context.Context, episodeID string, quality Quality) (*StreamURL, error)

func (*RemoteProvider) GetTrending

func (p *RemoteProvider) GetTrending(ctx context.Context) ([]Media, error)

func (*RemoteProvider) HealthCheck

func (p *RemoteProvider) HealthCheck(ctx context.Context) error

func (*RemoteProvider) Name

func (p *RemoteProvider) Name() string

func (*RemoteProvider) Search

func (p *RemoteProvider) Search(ctx context.Context, query string) ([]Media, error)

func (*RemoteProvider) Type

func (p *RemoteProvider) Type() MediaType

type Season

type Season struct {
	ID     string `json:"id"`
	Number int    `json:"number"`
	Title  string `json:"title"`
}

Season represents a season of a TV show

type StreamType

type StreamType string

StreamType represents the type of stream

const (
	StreamTypeHLS  StreamType = "hls"  // HTTP Live Streaming (.m3u8)
	StreamTypeDASH StreamType = "dash" // MPEG-DASH (.mpd)
	StreamTypeMP4  StreamType = "mp4"  // Direct MP4
	StreamTypeMKV  StreamType = "mkv"  // Direct MKV
)

type StreamURL

type StreamURL struct {
	URL         string            `json:"url"`
	Quality     Quality           `json:"quality"`
	Type        StreamType        `json:"type"`
	Headers     map[string]string `json:"headers,omitempty"`
	Subtitles   []Subtitle        `json:"subtitles,omitempty"`
	AudioTracks []AudioTrack      `json:"audio_tracks,omitempty"`
	Referer     string            `json:"referer,omitempty"`
}

StreamURL contains streaming information

func APISourceToStreamURL

func APISourceToStreamURL(s api.Source, referer, origin string) *StreamURL

APISourceToStreamURL converts a Source to StreamURL

type Subtitle

type Subtitle struct {
	Language string `json:"language"`
	URL      string `json:"url"`
	Format   string `json:"format"` // srt, vtt, ass
}

Subtitle represents a subtitle track

func APISubtitlesToSubtitles

func APISubtitlesToSubtitles(apiSubtitles []api.Subtitle) []Subtitle

APISubtitlesToSubtitles converts API subtitles to Subtitle

Directories

Path Synopsis
anime
manga
movies

Jump to

Keyboard shortcuts

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