progress

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package progress provides playback progress tracking for media players. It includes an IPC client for communicating with MPV media player to track playback position and state, which is then used to report progress to Plex.

The IPC connection uses Unix domain sockets on macOS/Linux and named pipes on Windows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(ms int) string

FormatDuration formats milliseconds as HH:MM:SS or MM:SS.

func GenerateIPCPath

func GenerateIPCPath() string

GenerateIPCPath creates a unique IPC socket/pipe path for MPV communication. On macOS/Linux, returns a Unix socket path in the temp directory. On Windows, returns a named pipe path.

Types

type MPVClient

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

MPVClient provides communication with MPV via its JSON IPC protocol. It connects to MPV over a Unix socket (macOS/Linux) or named pipe (Windows).

func NewMPVClient

func NewMPVClient(socketPath string) *MPVClient

NewMPVClient creates a new MPV IPC client for the given socket path. On macOS/Linux, this should be a Unix socket path (e.g., /tmp/mpv-12345.sock). On Windows, this should be a named pipe path (e.g., \\.\pipe\mpv-12345). The client is not connected until Connect is called.

func (*MPVClient) Close

func (c *MPVClient) Close() error

Close closes the connection to MPV.

func (*MPVClient) Connect

func (c *MPVClient) Connect() error

Connect establishes a connection to the MPV IPC server. It retries with a short delay to allow MPV time to start the IPC server. Use ConnectWithContext for cancellation support.

func (*MPVClient) ConnectWithContext

func (c *MPVClient) ConnectWithContext(ctx context.Context) error

ConnectWithContext establishes a connection to the MPV IPC server with context support. It retries with a short delay to allow MPV time to start the IPC server. The context can be used to cancel connection attempts (e.g., if MPV exits early).

func (*MPVClient) GetDuration

func (c *MPVClient) GetDuration() (float64, error)

GetDuration returns the total duration of the current media in seconds.

func (*MPVClient) GetFilename

func (c *MPVClient) GetFilename() (string, error)

GetFilename returns the filename of the currently playing media.

func (*MPVClient) GetPaused

func (c *MPVClient) GetPaused() (bool, error)

GetPaused returns true if playback is paused.

func (*MPVClient) GetPlaybackState

func (c *MPVClient) GetPlaybackState() (*PlaybackState, error)

GetPlaybackState returns the current playback state.

func (*MPVClient) GetPlaylistPos

func (c *MPVClient) GetPlaylistPos() (int, error)

GetPlaylistPos returns the current playlist position (0-indexed).

func (*MPVClient) GetTimePos

func (c *MPVClient) GetTimePos() (float64, error)

GetTimePos returns the current playback position in seconds.

func (*MPVClient) IsConnected

func (c *MPVClient) IsConnected() bool

IsConnected returns true if the client has an active connection.

type PlaybackState

type PlaybackState struct {
	TimePos     float64
	Duration    float64
	Paused      bool
	PlaylistPos int
}

GetPlaybackState returns the current playback state information. This is a convenience method that combines multiple property queries.

type Tracker

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

Tracker monitors MPV playback and reports progress to Plex.

func NewTracker

func NewTracker(items []*plex.MediaItem, mpv *MPVClient, plexClient *plex.Client) *Tracker

NewTracker creates a new progress tracker.

func (*Tracker) CurrentIndex

func (t *Tracker) CurrentIndex() int

CurrentIndex returns the current playlist index.

func (*Tracker) CurrentMedia

func (t *Tracker) CurrentMedia() *plex.MediaItem

CurrentMedia returns the currently playing media item.

func (*Tracker) Progress added in v0.2.4

func (t *Tracker) Progress() map[string]int

Progress returns the last reported playback position (milliseconds) for each played item, keyed by the item's Plex media key. Call after Stop so the tracking goroutine has finished recording the final position.

func (*Tracker) SetIndex

func (t *Tracker) SetIndex(idx int)

SetIndex sets the current playlist index.

func (*Tracker) Start

func (t *Tracker) Start(ctx context.Context, interval time.Duration)

Start begins tracking playback progress. It polls MPV every interval and reports to Plex.

func (*Tracker) Stop

func (t *Tracker) Stop()

Stop stops the progress tracker. It is safe to call multiple times.

Jump to

Keyboard shortcuts

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