api

package
v0.0.0-...-0e82b15 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrResponseDataNotString occurs when observe response data is not a string.
	ErrResponseDataNotString = errors.New("response data is not a string")
	// ErrResponseDataNotInt occurs when observe response data is not an integer.
	ErrResponseDataNotInt = errors.New("response data is not an integer")
	// ErrResponseDataNotExpectedFormatNode occurs when observe response data is not expected MPV_FORMAT_NODE type.
	ErrResponseDataNotExpectedFormatNode = errors.New("response data is not of expected MPV_FORMAT_NODE type")

	// ErrPlaybackTimeNotFloat occurs when playback time is not a correct decimal number.
	ErrPlaybackTimeNotFloat = errors.New("playback time could not be converted to a float number")
	// ErrPlaybackPathNotServed occurs when playback path is set to file that is not being served by api.
	ErrPlaybackPathNotServed = errors.New("playback path is not served")

	// ErrPlaylistMapDataNotParsable occurs when data being sent during observation of MPV's "playlist" property is not a correct JSON.
	ErrPlaylistMapDataNotParsable = errors.New("could not parse playlist map data as JSON")
)
View Source
var (
	ErrJSONFileNotAPlaylistFile = errors.New("a JSON file is not a valid playlist file - 'mpvWebApiPlaylist' either not specified or false")
)
View Source
var (
	// ErrPathNotDirectory occurs when provided path is not pointing to a directory.
	ErrPathNotDirectory = errors.New("path does not point to a directory")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Address                 string
	AllowCORS               bool
	ErrWriter               io.Writer
	MpvSocketPath           string
	PathReplacements        []PathReplacement
	PlaylistFilesPrefixes   []string
	OutWriter               io.Writer
	SocketConnectionTimeout time.Duration
	StartMpvInstance        bool
	StatesRepository        state.Repository
	PluginServers           map[string]PluginServer
}

Config controls behaviour of the api server.

type PathReplacement

type PathReplacement struct {
	From string
	To   string
}

type PlaylistFile

type PlaylistFile struct {
	CurrentEntryIdx            int               `json:"CurrentEntryIdx"`
	DirectoryContentsAsEntries bool              `json:"DirectoryContentsAsEntries"`
	Entries                    []playlists.Entry `json:"Entries"`
	MpvWebApiPlaylist          bool              `json:"MpvWebApiPlaylist"`
	Name                       string            `json:"Name"`
	Description                string            `json:"Description"`
}

type PluginApi

type PluginApi interface {
	AddRootDirectories(directories []directories.Entry)
	ChangeChaptersOrder(chapters []int64, force bool) error
	TakeDirectory(path string) (directories.Entry, error)
	LoadPlaylist(uuid string, append bool) error
	LoadFile(filePath string, append bool) error
	LoadFileByUuid(uuid string, append bool) error
	ChangeFullscreen(fullscreen bool) error
	ChangeAudio(audioId string) error
	ChangeChapter(idx int64) error
	ChangeSubtitle(subtitleId string) error
	LoopFile(looped bool) error
	ChangePause(paused bool) error
	PlaylistPlayIndex(idx int) error
	StopPlayback() error
	WaitUntilMediaFileByPath(mediaFilePath string) error
	WaitUntilMediaFileByUuid(uuid string) error
}

type PluginServer

type PluginServer interface {
	Init(apiServ PluginApi) error
	Handler() http.Handler
	PathBase() string
	Name() string
	Shutdown()
}

type Server

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

Server is used to serve API and hold state accessible to the API.

func NewServer

func NewServer(cfg Config) (*Server, error)

NewServer prepares and returns a server that can be used to handle API calls.

func (*Server) AddDirectory

func (s *Server) AddDirectory(dir directories.Entry) error

func (*Server) AddRootDirectories

func (s *Server) AddRootDirectories(rootDirectories []directories.Entry)

AddRootDirectories adds root directories with media files to be handled by the server. If the Directory entries are already present, they are overwritten along with their properties (watched, recursive, etc.). TODO2: at the moment no error is being returned from the directories adding, however some information about unsuccessful attempts should be returned in addition to just printing it in server (for example for REST responses).

func (*Server) ChangeAudio

func (s *Server) ChangeAudio(audioId string) error

func (*Server) ChangeChapter

func (s *Server) ChangeChapter(idx int64) error

func (*Server) ChangeChaptersOrder

func (s *Server) ChangeChaptersOrder(chapters []int64, force bool) error

func (*Server) ChangeFullscreen

func (s *Server) ChangeFullscreen(fullscreen bool) error

func (*Server) ChangePause

func (s *Server) ChangePause(paused bool) error

func (*Server) ChangeSubtitle

func (s *Server) ChangeSubtitle(subtitleID string) error

func (*Server) DefaultPlaylistSelected

func (s *Server) DefaultPlaylistSelected() bool

func (*Server) LoadFile

func (s *Server) LoadFile(filePath string, append bool) error

func (*Server) LoadFileByUuid

func (s *Server) LoadFileByUuid(uuid string, append bool) error

func (*Server) LoadPlaylist

func (s *Server) LoadPlaylist(uuid string, append bool) error

LoadPlaylist instructs mpv to add entries of a playlist to the mpv internal playlist. UUID is a key of a playlist that is unique in the scope of a server's instance. Append specifies whether the playlist should be added to the end of the currently played playlist. When append is false, the new playlist overwrites current playlist and starts playing it immediately. When append is true, a default playlist will be selected and updated with entries from both previously selected playlist and a new appended one (mpv will emit change to playlist property which will set the entries on the default playlist).

func (*Server) LoopFile

func (s *Server) LoopFile(looped bool) error

func (*Server) PlaylistPlayIndex

func (s *Server) PlaylistPlayIndex(idx int) error

func (*Server) Serve

func (s *Server) Serve() error

Serve starts handling plugin API servers passed to the server. It also starts mpv manager and (if neccessary). Blocks until either mpv manager or http server stops serving (with error or nil).

func (*Server) StopPlayback

func (s *Server) StopPlayback() error

func (*Server) StopServing

func (s *Server) StopServing(reason string) error

StopServing instructs server to close API servers & mpv manager with a provided reason.

func (*Server) TakeDirectory

func (s *Server) TakeDirectory(path string) (directories.Entry, error)

func (*Server) WaitUntilMediaFileByPath

func (s *Server) WaitUntilMediaFileByPath(mediaFilePath string) error

func (*Server) WaitUntilMediaFileByUuid

func (s *Server) WaitUntilMediaFileByUuid(uuid string) error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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