Documentation
¶
Index ¶
- Constants
- Variables
- func ClientIdentifier(cfg *config.Instance) string
- func Launchers() []platforms.Launcher
- func NewPlexAlbumLauncher() platforms.Launcher
- func NewPlexArtistLauncher() platforms.Launcher
- func NewPlexMovieLauncher() platforms.Launcher
- func NewPlexSongLauncher() platforms.Launcher
- func NewPlexTVLauncher() platforms.Launcher
- func NewPlexTVShowLauncher() platforms.Launcher
- func NormalizeURL(raw string) string
- type Client
- func (c *Client) AccountToken() string
- func (c *Client) ClientIdentifier() string
- func (c *Client) Clients(ctx context.Context) ([]ServerClient, error)
- func (c *Client) CreatePlayQueue(ctx context.Context, machineID, ratingKey, queueType string) (*PlayQueue, error)
- func (c *Client) Identity(ctx context.Context) (*Identity, error)
- func (c *Client) Items(ctx context.Context, sectionKey string, plexType int, filter url.Values, ...) error
- func (c *Client) Leaves(ctx context.Context, ratingKey string, fn func([]Metadata) error) error
- func (c *Client) Metadata(ctx context.Context, ratingKey string) (*Metadata, error)
- func (c *Client) PlayerName() string
- func (c *Client) PlayerResources(ctx context.Context) ([]Resource, error)
- func (c *Client) Sections(ctx context.Context) ([]Section, error)
- func (c *Client) ServerToken() string
- func (c *Client) ServerURL() string
- type Connection
- type FlexInt
- type GUID
- type Identity
- type Metadata
- type Pin
- type PlayQueue
- type PlexClient
- type Resource
- type Section
- type ServerClient
- type TVClient
Constants ¶
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 ¶
var ErrNotFound = errors.New("plex: not found")
ErrNotFound reports a library item, PIN or endpoint the server says does not exist.
var ErrPinExpired = errors.New("plex link code expired")
ErrPinExpired reports a link PIN plex.tv no longer knows.
Functions ¶
func ClientIdentifier ¶
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 NewPlexAlbumLauncher ¶
NewPlexAlbumLauncher plays a Plex album in track order.
func NewPlexArtistLauncher ¶
NewPlexArtistLauncher plays every track by a Plex artist.
func NewPlexMovieLauncher ¶
NewPlexMovieLauncher plays movies from a Plex library.
func NewPlexSongLauncher ¶
NewPlexSongLauncher plays songs from a Plex music library.
func NewPlexTVLauncher ¶
NewPlexTVLauncher plays TV episodes from a Plex library.
func NewPlexTVShowLauncher ¶
NewPlexTVShowLauncher plays every episode of a Plex TV show in order.
func NormalizeURL ¶
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 ¶
NewClient builds a client for a server URL. A nil httpClient uses Core's default transport.
func (*Client) AccountToken ¶
func (*Client) ClientIdentifier ¶
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) 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) PlayerName ¶
func (*Client) PlayerResources ¶
PlayerResources lists the account's registered players. Without an account token there is nothing to ask for.
func (*Client) ServerToken ¶
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 ¶
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 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 ¶
PlayQueue is a queue the server built for a player to play.
func (*PlayQueue) SelectedItem ¶
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 ¶
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 ¶
NewTVClient builds a plex.tv client. Empty URLs use plex.tv itself; a nil httpClient uses Core's default transport.
func (*TVClient) CheckPin ¶
CheckPin returns the PIN's current state. A PIN plex.tv has dropped is ErrPinExpired.
func (*TVClient) ClientsURL ¶
ClientsURL is the plex.tv host an account token is stored against.