lib

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// MPVErrors is a channel to receive mpv error messages.
	MPVErrors chan string

	// MPVFileLoaded is a channel to receive file-loaded events.
	MPVFileLoaded chan struct{}
)
View Source
var (

	// PlistCtx is used here and the UI playlist code
	// to detect if the user tried to cancel the playlist
	// loading.
	PlistCtx context.Context

	// PlistCancel is used to cancel the playlist loading.
	PlistCancel context.CancelFunc
)

Functions

func AddToHistory

func AddToHistory(text string)

AddToHistory adds text to the history buffer. Taken from https://github.com/abs-lang/abs/repl/history.go (addToHistory)

func CloseInstances

func CloseInstances(socket string)

CloseInstances sends a quit command to instances running on the socket.

func ConfigPath

func ConfigPath(ftype string) (string, error)

ConfigPath returns the absolute path for the given filetype: socket, history and config, and performs actions related to it.

func FormatDuration

func FormatDuration(duration int) string

FormatDuration takes a duration as seconds and returns a hh:mm:ss string.

func FormatPublished

func FormatPublished(published string) string

FormatPublished takes a duration in the format: "1 day ago", and returns it in the format: "1d".

func GetDataFromURL

func GetDataFromURL(uri string) []string

GetDataFromURL parses specific url fields and returns their values.

func GetProgress

func GetProgress(width int) (string, string, error)

GetProgress renders a progress bar and media data.

func HistoryForward

func HistoryForward() string

HistoryForward moves a step forward in the history buffer, and returns a text.

func HistoryReverse

func HistoryReverse() string

HistoryReverse moves a step back in the history buffer, and returns a text.

func IsValidURL

func IsValidURL(uri string) (*url.URL, error)

IsValidURL checks if a URL is valid.

func LoadPlaylist added in v0.0.5

func LoadPlaylist(id string, audio bool) error

LoadPlaylist takes a playlist ID, determines whether to play video or just audio (according to the audio parameter), and appropriately loads the URLs into mpv.

func LoadVideo

func LoadVideo(id string, audio bool) error

LoadVideo takes a video ID, determines whether to play video or just audio (according to the audio parameter), and appropriately loads the URLs into mpv.

func MPVStart

func MPVStart() error

MPVStart loads the mpv executable, and connects to the socket.

func SaveHistory

func SaveHistory()

SaveHistory saves the contents of the history buffer to the history file. Taken from https://github.com/abs-lang/abs/repl/history.go (saveHistory)

func SendRequest

func SendRequest(ctx context.Context, c *Client, param string) (*http.Response, error)

SendRequest sends a request to a url and returns a response.

func SetupConfig

func SetupConfig() error

SetupConfig checks for the config directory, and creates one if it doesn't exist.

func SetupFlags

func SetupFlags() error

SetupFlags sets up the commandline flags

func SetupHistory

func SetupHistory()

SetupHistory reads the history file and loads the search history. Taken from https://github.com/abs-lang/abs/repl/history.go (Start)

func SuspendApp added in v0.0.4

func SuspendApp(t tcell.Screen)

SuspendApp suspends the application.

func UpdateClient

func UpdateClient() error

UpdateClient queries available instances and updates the client.

Types

type ChannelResult added in v0.0.5

type ChannelResult struct {
	Title       string           `json:"title"`
	ChannelID   string           `json:"authorId"`
	Author      string           `json:"author"`
	Description string           `json:"description"`
	ViewCount   int              `json:"viewCount"`
	Videos      []PlaylistVideo  `json:"videos"`
	Playlists   []PlaylistResult `json:"playlists"`
}

ChannelResult stores the channel data.

type Client

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

Client stores the host and http client data.

func GetClient

func GetClient() *Client

GetClient returns the Current client.

func NewClient

func NewClient(host string) *Client

NewClient creates a new client.

func (*Client) Channel added in v0.0.5

func (c *Client) Channel(id, stype, params string, cancel bool) (ChannelResult, error)

Channel gets the playlist with the given ID and returns a ChannelResult. If id is blank, it indicates that more results are to be loaded for the same channel ID (stored in plistid). When cancel is true, it will stop loading the channel.

func (*Client) ChannelPlaylists added in v0.0.5

func (c *Client) ChannelPlaylists(id string, cancel bool) (ChannelResult, error)

ChannelPlaylists loads only the playlists present in the channel.

func (*Client) ChannelSearch added in v0.0.6

func (c *Client) ChannelSearch(id, query string, getmore bool) ([]SearchResult, error)

ChannelSearch searches for a query string in the channel.

func (*Client) ChannelVideos added in v0.0.5

func (c *Client) ChannelVideos(id string, cancel bool) (ChannelResult, error)

ChannelVideos loads only the videos present in the channel.

func (*Client) ClientRequest

func (c *Client) ClientRequest(ctx context.Context, param string) (*http.Response, error)

ClientRequest sends a request to the API and returns a response.

func (*Client) Playlist added in v0.0.5

func (c *Client) Playlist(id string, cancel bool) (PlaylistResult, error)

Playlist gets the playlist with the given ID and returns a PlaylistResult. If id is blank, it indicates that more results are to be loaded for the same playlist ID (stored in plistid). When cancel is true, it will stop loading the playlist.

func (*Client) Search

func (c *Client) Search(stype, text string, getmore bool, chanid ...string) ([]SearchResult, error)

Search searches for the given string and returns a SearchResult slice. It queries for two pages of results, and keeps a track of the number of pages currently returned. If the getmore parameter is true, it will add two more pages to the already tracked page number, and return the result.

func (*Client) Video

func (c *Client) Video(id string) (VideoResult, error)

Video gets the video with the given ID and returns a VideoResult.

type Connector

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

Connector stores the mpvipc connection data.

func GetMPV

func GetMPV() *Connector

GetMPV returns the currently active mpvipc instance.

func MPVConnect

func MPVConnect(socket string, mpvexec bool) (*Connector, error)

MPVConnect attempts to connect to the mpv instance.

func NewConnector

func NewConnector(conn *mpvipc.Connection) *Connector

NewConnector returns a Connector with an active mpvipc connection.

func (*Connector) Call

func (c *Connector) Call(args ...interface{}) (interface{}, error)

Call sends a command to the mpv instance.

func (*Connector) CycleLoop

func (c *Connector) CycleLoop()

CycleLoop toggles between looping a file, playlist or none.

func (*Connector) CycleMute added in v0.0.5

func (c *Connector) CycleMute()

CycleMute toggles the playback mute state.

func (*Connector) CyclePaused

func (c *Connector) CyclePaused()

CyclePaused toggles between pause and play states.

func (*Connector) CycleShuffle

func (c *Connector) CycleShuffle()

CycleShuffle cycles the playlist's shuffle state.

func (*Connector) Duration

func (c *Connector) Duration() int

Duration returns the total duration of the file.

func (*Connector) Get

func (c *Connector) Get(prop string) (interface{}, error)

Get gets a property from the mpv instance.

func (*Connector) IsClosed

func (c *Connector) IsClosed() bool

IsClosed checks if mpv has exited.

func (*Connector) IsEOF

func (c *Connector) IsEOF() bool

IsEOF checks if an already loaded file has finished playback.

func (*Connector) IsIdle

func (c *Connector) IsIdle() bool

IsIdle checks if mpv is currently idle.

func (*Connector) IsMuted added in v0.0.5

func (c *Connector) IsMuted() bool

IsMuted checks if playback is muted.

func (*Connector) IsPaused

func (c *Connector) IsPaused() bool

IsPaused checks if mpv is paused.

func (*Connector) IsShuffle

func (c *Connector) IsShuffle() bool

IsShuffle checks if the playlist is shuffled.

func (*Connector) LoadFile added in v0.0.2

func (c *Connector) LoadFile(title string, duration int, files ...string) error

LoadFile loads the given file into mpv along with the relevant metadata. If the files parameter contains more than one filename argument, it will consider the first entry as the video file and the second entry as the audio file, set the relevant options and pass them to mpv.

func (*Connector) LoadPlaylist added in v0.0.2

func (c *Connector) LoadPlaylist(plpath string, replace bool) error

LoadPlaylist loads a playlist file. If replace is false, it appends the loaded playlist to the current playlist, otherwise it replaces the current playlist.

func (*Connector) LoopType

func (c *Connector) LoopType(file bool) string

LoopType determines if the loop option is set, and determines if it is one of loop-file or loop-playlist.

func (*Connector) MPVStop

func (c *Connector) MPVStop(rm bool)

MPVStop sends a quit command to the mpv executable.

func (*Connector) MediaType

func (c *Connector) MediaType() string

MediaType determines if currently playing file is of audio or video type.

func (*Connector) Next

func (c *Connector) Next()

Next plays the next item in the playlist.

func (*Connector) Play

func (c *Connector) Play()

Play starts the playback.

func (*Connector) PlaylistClear

func (c *Connector) PlaylistClear()

PlaylistClear clears the playlist.

func (*Connector) PlaylistCount

func (c *Connector) PlaylistCount() int

PlaylistCount returns the total amount of files in the playlist.

func (*Connector) PlaylistData

func (c *Connector) PlaylistData() string

PlaylistData return the current playlist data.

func (*Connector) PlaylistDelete added in v0.0.2

func (c *Connector) PlaylistDelete(entry int)

PlaylistDelete deletes an entry from the playlist.

func (*Connector) PlaylistMove added in v0.0.2

func (c *Connector) PlaylistMove(a, b int)

PlaylistMove moves an entry to a different index in the playlist.

func (*Connector) PlaylistPlayLatest

func (c *Connector) PlaylistPlayLatest()

PlaylistPlayLatest plays the latest entry in the playlist.

func (*Connector) PlaylistPos

func (c *Connector) PlaylistPos() int

PlaylistPos returns the current position of the file in the playlist.

func (*Connector) PlaylistTitle added in v0.0.2

func (c *Connector) PlaylistTitle(pos int) string

PlaylistTitle returns the title, or filename of the playlist entry if title is not available.

func (*Connector) Prev

func (c *Connector) Prev()

Prev plays the previous item in the playlist.

func (*Connector) SeekBackward

func (c *Connector) SeekBackward()

SeekBackward seeks the track backward.

func (*Connector) SeekForward

func (c *Connector) SeekForward()

SeekForward seeks the track forward.

func (*Connector) Set

func (c *Connector) Set(prop string, value interface{}) error

Set sets a property in the mpv instance.

func (*Connector) SetPlaylistPos

func (c *Connector) SetPlaylistPos(pos int)

SetPlaylistPos sets the playlist position.

func (*Connector) Stop

func (c *Connector) Stop()

Stop stops the playback.

func (*Connector) TimePosition

func (c *Connector) TimePosition() int

TimePosition returns the current position in the file.

func (*Connector) WaitUntilClosed

func (c *Connector) WaitUntilClosed()

WaitUntilClosed waits until a connection is closed.

type FormatData added in v0.0.4

type FormatData struct {
	Type       string `json:"type"`
	URL        string `json:"url"`
	Itag       string `json:"itag"`
	Resolution string `json:"resolution,omitempty"`
}

FormatData stores the media format data.

type PlaylistResult added in v0.0.5

type PlaylistResult struct {
	Title       string          `json:"title"`
	PlaylistID  string          `json:"playlistId"`
	Author      string          `json:"author"`
	Description string          `json:"description"`
	VideoCount  int             `json:"videoCount"`
	ViewCount   int             `json:"viewCount"`
	Videos      []PlaylistVideo `json:"videos"`
}

PlaylistResult stores the playlist data.

type PlaylistVideo added in v0.0.5

type PlaylistVideo struct {
	Title         string `json:"title"`
	VideoID       string `json:"videoId"`
	Author        string `json:"author"`
	LengthSeconds int    `json:"lengthSeconds"`
}

PlaylistVideo stores the playlist's video data.

type SearchResult

type SearchResult struct {
	Type          string `json: "type"`
	Title         string `json: "title"`
	AuthorID      string `json: "authorId"`
	VideoID       string `json: "videoId"`
	PlaylistID    string `json: "playlistId"`
	Author        string `json: "author"`
	PublishedText string `json: "publishedText"`
	Description   string `json: "description"`
	VideoCount    int    `json: "videoCount"`
	LengthSeconds int    `json: "lengthSeconds"`
}

SearchResult stores the search result data.

type VideoResult

type VideoResult struct {
	Title           string       `json:"title"`
	Author          string       `json:"author"`
	VideoID         string       `json:"videoId"`
	LengthSeconds   int          `json:"lengthSeconds"`
	FormatStreams   []FormatData `json:"formatStreams"`
	AdaptiveFormats []FormatData `json:"adaptiveFormats"`
}

VideoResult stores the video data.

Jump to

Keyboard shortcuts

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