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 ¶
- func FormatDuration(ms int) string
- func GenerateIPCPath() string
- type MPVClient
- func (c *MPVClient) Close() error
- func (c *MPVClient) Connect() error
- func (c *MPVClient) ConnectWithContext(ctx context.Context) error
- func (c *MPVClient) GetDuration() (float64, error)
- func (c *MPVClient) GetFilename() (string, error)
- func (c *MPVClient) GetPaused() (bool, error)
- func (c *MPVClient) GetPlaybackState() (*PlaybackState, error)
- func (c *MPVClient) GetPlaylistPos() (int, error)
- func (c *MPVClient) GetTimePos() (float64, error)
- func (c *MPVClient) IsConnected() bool
- type PlaybackState
- type Tracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
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 ¶
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) Connect ¶
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 ¶
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 ¶
GetDuration returns the total duration of the current media in seconds.
func (*MPVClient) GetFilename ¶
GetFilename returns the filename of the currently playing media.
func (*MPVClient) GetPlaybackState ¶
func (c *MPVClient) GetPlaybackState() (*PlaybackState, error)
GetPlaybackState returns the current playback state.
func (*MPVClient) GetPlaylistPos ¶
GetPlaylistPos returns the current playlist position (0-indexed).
func (*MPVClient) GetTimePos ¶
GetTimePos returns the current playback position in seconds.
func (*MPVClient) IsConnected ¶
IsConnected returns true if the client has an active connection.
type PlaybackState ¶
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 ¶
NewTracker creates a new progress tracker.
func (*Tracker) CurrentIndex ¶
CurrentIndex returns the current playlist index.
func (*Tracker) CurrentMedia ¶
CurrentMedia returns the currently playing media item.
func (*Tracker) Progress ¶ added in v0.2.4
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.