plex

package
v2.23.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: GPL-3.0 Imports: 33 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultServerURL is the server a launcher uses with no server_url set.
	DefaultServerURL = "http://localhost:32400"
	// TVBaseURL is plex.tv, where PINs are created and checked.
	TVBaseURL = "https://plex.tv"
	// ClientsBaseURL is the plex.tv host that lists an account's devices.
	ClientsBaseURL = "https://clients.plex.tv"
)

Variables

View Source
var ErrNotFound = errors.New("plex: not found")

ErrNotFound reports a library item, PIN or endpoint the server says does not exist.

View Source
var ErrPinExpired = errors.New("plex link code expired")

ErrPinExpired reports a link PIN plex.tv no longer knows.

Functions

func ClientIdentifier

func ClientIdentifier(cfg *config.Instance) string

ClientIdentifier is the X-Plex-Client-Identifier Core sends. Plex ties tokens and devices to it, so it is derived from Core's persisted device ID and stays the same across restarts.

func Launchers

func Launchers() []platforms.Launcher

Launchers returns every Plex launcher.

func NewPlexAlbumLauncher

func NewPlexAlbumLauncher() platforms.Launcher

NewPlexAlbumLauncher plays a Plex album in track order.

func NewPlexArtistLauncher

func NewPlexArtistLauncher() platforms.Launcher

NewPlexArtistLauncher plays every track by a Plex artist.

func NewPlexMovieLauncher

func NewPlexMovieLauncher() platforms.Launcher

NewPlexMovieLauncher plays movies from a Plex library.

func NewPlexSongLauncher

func NewPlexSongLauncher() platforms.Launcher

NewPlexSongLauncher plays songs from a Plex music library.

func NewPlexTVLauncher

func NewPlexTVLauncher() platforms.Launcher

NewPlexTVLauncher plays TV episodes from a Plex library.

func NewPlexTVShowLauncher

func NewPlexTVShowLauncher() platforms.Launcher

NewPlexTVShowLauncher plays every episode of a Plex TV show in order.

func NormalizeURL

func NormalizeURL(raw string) string

NormalizeURL adds a missing http scheme and drops a trailing slash.

Types

type Client

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

Client talks to one Plex server and, for player discovery, plex.tv.

func NewClient

func NewClient(serverURL, clientsURL, clientID, playerName string, httpClient *http.Client) *Client

NewClient builds a client for a server URL. A nil httpClient uses Core's default transport.

func (*Client) AccountToken

func (c *Client) AccountToken() string

func (*Client) ClientIdentifier

func (c *Client) ClientIdentifier() string

func (*Client) Clients

func (c *Client) Clients(ctx context.Context) ([]ServerClient, error)

Clients lists the Companion players the server currently sees.

func (*Client) CreatePlayQueue

func (c *Client) CreatePlayQueue(ctx context.Context, machineID, ratingKey, queueType string) (*PlayQueue, error)

CreatePlayQueue asks the server for a queue holding the item, or the item's episodes or tracks for a show, album or artist.

func (*Client) Identity

func (c *Client) Identity(ctx context.Context) (*Identity, error)

Identity returns the server's machine identifier and version.

func (*Client) Items

func (c *Client) Items(
	ctx context.Context, sectionKey string, plexType int, filter url.Values,
	fn func([]Metadata) error,
) error

Items lists a section's items of one type, page by page.

func (*Client) Leaves

func (c *Client) Leaves(ctx context.Context, ratingKey string, fn func([]Metadata) error) error

Leaves lists every playable item under a show, album or artist.

func (*Client) Metadata

func (c *Client) Metadata(ctx context.Context, ratingKey string) (*Metadata, error)

Metadata returns one library item by rating key.

func (*Client) PlayerName

func (c *Client) PlayerName() string

func (*Client) PlayerResources

func (c *Client) PlayerResources(ctx context.Context) ([]Resource, error)

PlayerResources lists the account's registered players. Without an account token there is nothing to ask for.

func (*Client) Sections

func (c *Client) Sections(ctx context.Context) ([]Section, error)

Sections lists the server's library sections.

func (*Client) ServerToken

func (c *Client) ServerToken() string

func (*Client) ServerURL

func (c *Client) ServerURL() string

type Connection

type Connection struct {
	Protocol string  `json:"protocol"`
	Address  string  `json:"address"`
	URI      string  `json:"uri"`
	Port     FlexInt `json:"port"`
	Local    bool    `json:"local"`
	Relay    bool    `json:"relay"`
}

Connection is one way to reach a device plex.tv lists.

type FlexInt

type FlexInt int64

FlexInt decodes a JSON number that Plex sends as either a number or a string, depending on the server version and endpoint.

func (*FlexInt) UnmarshalJSON

func (f *FlexInt) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts a number, a numeric string, an empty string or null.

type GUID

type GUID struct {
	ID string `json:"id"`
}

GUID is one external identity Plex holds for an item, such as tmdb://603.

type Identity

type Identity struct {
	MachineIdentifier string
	Version           string
}

Identity is the server's own identity.

type Metadata

type Metadata struct {
	RatingKey        string  `json:"ratingKey"`
	Key              string  `json:"key"`
	Type             string  `json:"type"`
	Title            string  `json:"title"`
	ParentTitle      string  `json:"parentTitle"`
	GrandparentTitle string  `json:"grandparentTitle"`
	ParentRatingKey  string  `json:"parentRatingKey"`
	GUID             string  `json:"guid"`
	GUIDs            []GUID  `json:"Guid"`
	Year             FlexInt `json:"year"`
	Index            FlexInt `json:"index"`
	ParentIndex      FlexInt `json:"parentIndex"`
	PlayQueueItemID  FlexInt `json:"playQueueItemID"`
	LibrarySectionID FlexInt `json:"librarySectionID"`
}

Metadata is a library item as Plex lists it.

type Pin

type Pin struct {
	ExpiresAt time.Time `json:"expiresAt"`
	Code      string    `json:"code"`
	AuthToken string    `json:"authToken"`
	ID        FlexInt   `json:"id"`
	ExpiresIn FlexInt   `json:"expiresIn"`
}

Pin is a plex.tv link PIN. AuthToken is empty until the user enters Code at plex.tv/link.

type PlayQueue

type PlayQueue struct {
	Items          []Metadata
	ID             int64
	SelectedItemID int64
}

PlayQueue is a queue the server built for a player to play.

func (*PlayQueue) SelectedItem

func (q *PlayQueue) SelectedItem() *Metadata

SelectedItem is the item the queue starts on: the selected one, or the first when the server named none.

type PlexClient

type PlexClient interface {
	// ServerURL is the server's base URL, without a trailing slash.
	ServerURL() string
	// PlayerName is the configured player name; empty means any one player.
	PlayerName() string
	// ClientIdentifier is the stable identity Core uses with Plex.
	ClientIdentifier() string
	// ServerToken is the access token stored for the server.
	ServerToken() string
	// AccountToken is the plex.tv account token, if Core has one.
	AccountToken() string
	Sections(ctx context.Context) ([]Section, error)
	// Items lists a section's items of one type page by page.
	Items(ctx context.Context, sectionKey string, plexType int, filter url.Values,
		fn func([]Metadata) error) error
	// Metadata returns one item; a missing item is ErrNotFound.
	Metadata(ctx context.Context, ratingKey string) (*Metadata, error)
	// Leaves lists the playable items under a show, album or artist.
	Leaves(ctx context.Context, ratingKey string, fn func([]Metadata) error) error
	Identity(ctx context.Context) (*Identity, error)
	CreatePlayQueue(ctx context.Context, machineID, ratingKey, queueType string) (*PlayQueue, error)
	// Clients lists the Companion players the server knows.
	Clients(ctx context.Context) ([]ServerClient, error)
	// PlayerResources lists the players registered to the Plex account.
	PlayerResources(ctx context.Context) ([]Resource, error)
}

PlexClient is the part of a Plex server client the launchers use.

func NewClientWithLauncherID

func NewClientWithLauncherID(cfg *config.Instance, launcherID string, groups []string) PlexClient

NewClientWithLauncherID builds a client from the server_url and client settings that apply to a launcher and its groups.

type Resource

type Resource struct {
	Name             string       `json:"name"`
	Product          string       `json:"product"`
	ClientIdentifier string       `json:"clientIdentifier"`
	Provides         string       `json:"provides"`
	AccessToken      string       `json:"accessToken"`
	Connections      []Connection `json:"connections"`
	Owned            bool         `json:"owned"`
}

Resource is a server or player registered to a Plex account.

func (*Resource) ProvidesRole

func (r *Resource) ProvidesRole(role string) bool

ProvidesRole reports whether the resource lists a role, such as server or player, in its comma separated provides field.

type Section

type Section struct {
	Key   string `json:"key"`
	Type  string `json:"type"`
	Title string `json:"title"`
}

Section is one library section of a Plex server.

type ServerClient

type ServerClient struct {
	Name                 string  `json:"name"`
	Host                 string  `json:"host"`
	Address              string  `json:"address"`
	MachineIdentifier    string  `json:"machineIdentifier"`
	Product              string  `json:"product"`
	ProtocolCapabilities string  `json:"protocolCapabilities"`
	Port                 FlexInt `json:"port"`
}

ServerClient is a player the server knows through the Companion protocol.

type TVClient

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

TVClient talks to plex.tv for account linking.

func NewTVClient

func NewTVClient(baseURL, clientsURL, clientID string, httpClient *http.Client) *TVClient

NewTVClient builds a plex.tv client. Empty URLs use plex.tv itself; a nil httpClient uses Core's default transport.

func (*TVClient) CheckPin

func (c *TVClient) CheckPin(ctx context.Context, id int64) (*Pin, error)

CheckPin returns the PIN's current state. A PIN plex.tv has dropped is ErrPinExpired.

func (*TVClient) ClientsURL

func (c *TVClient) ClientsURL() string

ClientsURL is the plex.tv host an account token is stored against.

func (*TVClient) CreatePin

func (c *TVClient) CreatePin(ctx context.Context) (*Pin, error)

CreatePin asks plex.tv for a short code the user enters at plex.tv/link.

func (*TVClient) Resources

func (c *TVClient) Resources(ctx context.Context, token string) ([]Resource, error)

Resources lists every server and player on the account, relays included.

Jump to

Keyboard shortcuts

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