plex

package
v1.60.0 Latest Latest
Warning

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

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

Documentation

Overview

Package plex implements a playlist.Provider for Plex Media Server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStreamURL

func IsStreamURL(urlStr string) bool

IsStreamURL reports whether the given URL looks like a Plex library part endpoint. Used by the player to route these URLs through the buffered navBuffer + ffmpeg pipeline instead of native HTTP streaming.

Types

type Album

type Album struct {
	RatingKey  string // unique album ID (Plex ratingKey)
	Title      string
	ArtistName string // parentTitle in the Plex API
	Year       int
	TrackCount int // leafCount
}

Album represents a Plex album with its artist and track count.

type Client

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

Client speaks to a Plex Media Server over its HTTP API.

func NewClient

func NewClient(baseURL, token string, libraries ...string) *Client

NewClient returns a Client for the given server URL and authentication token. libraries is an optional list of music library names to restrict MusicSections to. When not provided, all music libraries will be loaded

func (*Client) Albums

func (c *Client) Albums(sectionKey string) ([]Album, error)

Albums returns all albums in the given music section (identified by its key). It requests type=9 (album) directly rather than walking artists, and paginates through the full result set using X-Plex-Container-Start / Size.

func (*Client) MusicSections

func (c *Client) MusicSections() ([]Section, error)

MusicSections returns library sections of type "artist" (music libraries). When the client was constructed with a library filter, only sections whose title matches one of the allowed names (case-insensitive) are returned.

func (*Client) Ping

func (c *Client) Ping() error

Ping checks that the server is reachable and the token is valid. Returns a descriptive error on failure.

func (*Client) Search

func (c *Client) Search(query string) ([]Track, error)

Search searches the music library for tracks matching query. Returns nil without making an HTTP call when query is empty.

func (*Client) StreamURL

func (c *Client) StreamURL(partKey string) string

StreamURL returns the authenticated HTTP URL for streaming a track part. partKey is the relative path from the Part element, e.g. "/library/parts/…/file.flac". The token is appended as a query parameter; Plex accepts it in either header or query form.

func (*Client) Tracks

func (c *Client) Tracks(albumRatingKey string) ([]Track, error)

Tracks returns all tracks in the given album (identified by its ratingKey).

type Provider

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

Provider implements playlist.Provider for a Plex Media Server. Playlists() returns all albums across all music library sections. Tracks() returns the tracks for a given album ratingKey.

func NewFromConfig

func NewFromConfig(cfg config.PlexConfig) *Provider

NewFromConfig returns a Provider from a PlexConfig, or nil if URL or Token is missing.

func (*Provider) AlbumTracks

func (p *Provider) AlbumTracks(albumID string) ([]playlist.Track, error)

AlbumTracks returns the tracks for the given album (ratingKey). Implements provider.AlbumTrackLoader.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the display name used in the provider selector.

func (*Provider) Playlists

func (p *Provider) Playlists() ([]playlist.PlaylistInfo, error)

Playlists returns all albums across all Plex music library sections. Each album is a PlaylistInfo whose ID is the album's Plex ratingKey. Results are cached after the first successful call.

func (*Provider) Refresh

func (p *Provider) Refresh()

Refresh clears cached playlist and track data so the next call re-fetches from the server. Implements playlist.Refresher.

func (*Provider) SearchTracks

func (p *Provider) SearchTracks(_ context.Context, query string, limit int) ([]playlist.Track, error)

SearchTracks searches the Plex music library for tracks matching query. Implements provider.Searcher.

func (*Provider) Tracks

func (p *Provider) Tracks(albumRatingKey string) ([]playlist.Track, error)

Tracks returns the tracks for the album identified by albumRatingKey. Each track's Path is a complete authenticated HTTP URL ready for the player. Tracks with no streamable part (missing Media/Part data) are silently skipped. Results are cached per albumRatingKey.

type Section

type Section struct {
	Key   string // numeric section ID, e.g. "3"
	Title string // display name
	Type  string // "artist" for music libraries
}

Section represents a Plex library section (e.g. a music library).

type Track

type Track struct {
	RatingKey   string
	Title       string
	ArtistName  string // grandparentTitle
	AlbumName   string // parentTitle
	Year        int
	TrackNumber int    // index field in Plex API
	Duration    int    // milliseconds
	PartKey     string // relative path, e.g. "/library/parts/67890/1234567890/file.flac"
}

Track represents a Plex track with metadata and its first streamable Part.

Jump to

Keyboard shortcuts

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