Documentation
¶
Overview ¶
Package plex is the wire client for Plex Media Server: identity, sections and their folders, partial, section and item refreshes, items with their files, sessions and the notification socket. Every type here is the wire's, and the Plex kind translates. It asks for JSON on every call. Written against Plex Media Server 1.43.4.10903 (#71, #101) and 1.43.5.11029 (recorded run 2026-11-14), checked against python-plexapi.
Index ¶
- Constants
- Variables
- func NotFound(err error) bool
- func Refused(err error) bool
- type Activity
- type ActivityEntry
- type Client
- func (c *Client) Identity(ctx context.Context) (Identity, error)
- func (c *Client) Item(ctx context.Context, ratingKey ID) (Metadata, bool, error)
- func (c *Client) Notifications(ctx context.Context, opened func(), on func(Notification)) error
- func (c *Client) Playing(ctx context.Context) ([]Session, []Transcode, error)
- func (c *Client) RefreshItem(ctx context.Context, ratingKey ID) error
- func (c *Client) RefreshPath(ctx context.Context, section ID, folder string) error
- func (c *Client) RefreshSection(ctx context.Context, section ID) error
- func (c *Client) Section(ctx context.Context, key ID) (Section, bool, error)
- func (c *Client) SectionPage(ctx context.Context, section ID, typ ItemType, start, size int) (Page, error)
- func (c *Client) Sections(ctx context.Context) ([]Section, error)
- func (c *Client) Server(ctx context.Context) (Server, error)
- func (c *Client) Sessions(ctx context.Context) ([]Session, error)
- func (c *Client) SetCollections(ctx context.Context, ratingKey ID, typ ItemType, titles []string) error
- func (c *Client) Transcodes(ctx context.Context) ([]Transcode, error)
- type Error
- type Headers
- type ID
- type Identity
- type ItemType
- type Location
- type Media
- type Metadata
- type Notification
- type Page
- type Part
- type PlaySession
- type Player
- type Section
- type Server
- type Session
- type SessionInfo
- type Stream
- type Tag
- type TimelineEntry
- type Transcode
- type User
Constants ¶
const ( TimelineCreated = 0 TimelineDone = 5 TimelineDeleted = 9 )
Timeline states Plex sends for library items.
const StreamSubtitle = 3
StreamSubtitle is a subtitle stream's streamType.
Variables ¶
var ItemTypes = []ItemType{TypeMovie, TypeEpisode}
ItemTypes are the listings that between them hold every file of a section.
Functions ¶
Types ¶
type ActivityEntry ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one Plex Media Server at base, with the server's own token.
func (*Client) Item ¶
Item is one item by its ratingKey, false on 404: a moved file's old item answers 404 with an HTML body (recorded run 2026-11-14).
func (*Client) Notifications ¶
func (c *Client) Notifications(ctx context.Context, opened func(), on func(Notification)) error
Notifications reads /:/websockets/notifications until ctx ends or the server closes it, calling opened once the socket is open and on for each message. It needs no subscription message.
func (*Client) Playing ¶
Playing is Sessions and every transcode, which lists those of sessions /status/sessions doesn't list yet.
func (*Client) RefreshItem ¶
RefreshItem reads one item's media and Sidecars again.
func (*Client) RefreshPath ¶
RefreshPath is a partial scan of folder, as Plex stores it, inside one of section's Locations. Plex documents POST and every client sends GET, which Plex answers 200.
func (*Client) RefreshSection ¶
RefreshSection is a scan of the whole section.
func (*Client) SectionPage ¶
func (c *Client) SectionPage(ctx context.Context, section ID, typ ItemType, start, size int) (Page, error)
SectionPage lists size items of typ from start, with their files in Media[].Part[].file. Plex has no lookup by path.
func (*Client) Sessions ¶
Sessions are /status/sessions joined with /transcode/sessions. A session is listed in /status/sessions only once its client reported a timeline, and /transcode/sessions always lists a transcode (#71).
type Headers ¶
type Headers struct {
ClientID string
Product string
Version string
Platform string
PlatformVersion string
Device string
DeviceName string
}
Headers are the X-Plex-* headers that name SlipStream on every call.
type ID ¶
type ID string
ID is a key Plex sends as a number on some routes and versions and as a string on others.
func (*ID) UnmarshalJSON ¶
type Identity ¶
type Identity struct {
MachineIdentifier string `json:"machineIdentifier"`
Version string `json:"version"`
Claimed bool `json:"claimed"`
}
Identity is GET /identity, which needs no token (recorded run 2026-11-14: 200 while the token was revoked).
type Metadata ¶
type Metadata struct {
RatingKey ID `json:"ratingKey"`
Key string `json:"key"`
GUID string `json:"guid"`
Type string `json:"type"`
Title string `json:"title"`
Year int `json:"year"`
LibrarySectionID ID `json:"librarySectionID"`
GrandparentRatingKey ID `json:"grandparentRatingKey"`
GrandparentTitle string `json:"grandparentTitle"`
ParentIndex int `json:"parentIndex"`
Index int `json:"index"`
ViewCount int `json:"viewCount"`
ViewOffset int64 `json:"viewOffset"`
LastViewedAt int64 `json:"lastViewedAt"`
UserRating float64 `json:"userRating"`
EditionTitle string `json:"editionTitle"`
Collections []Tag `json:"Collection"`
Media []Media `json:"Media"`
User *User `json:"User"`
Player *Player `json:"Player"`
Session *SessionInfo `json:"Session"`
SessionKey ID `json:"sessionKey"`
TranscodeSession *Transcode `json:"TranscodeSession"`
}
Metadata is one item.
type Notification ¶
type Notification struct {
Type string `json:"type"`
Timeline []TimelineEntry `json:"TimelineEntry"`
Playing []PlaySession `json:"PlaySessionStateNotification"`
Activity []ActivityEntry `json:"ActivityNotification"`
}
Notification is one message on the notification socket.
type Part ¶
type Part struct {
ID ID `json:"id"`
File string `json:"file"`
Size int64 `json:"size"`
Decision string `json:"decision"`
Streams []Stream `json:"Stream"`
}
Part is one file of a version.
type PlaySession ¶
type Section ¶
type Section struct {
Key ID `json:"key"`
Type string `json:"type"`
Title string `json:"title"`
UUID string `json:"uuid"`
Refreshing bool `json:"refreshing"`
ScannedAt int64 `json:"scannedAt"`
Locations []Location `json:"Location"`
}
Section is one library section and its folders.
type Server ¶
type Server struct {
FriendlyName string `json:"friendlyName"`
MachineIdentifier string `json:"machineIdentifier"`
Version string `json:"version"`
MyPlexSubscription bool `json:"myPlexSubscription"`
}
Server is GET /, which needs the token.
type Session ¶
type Session struct {
Metadata
// Transcode is the session's entry in /transcode/sessions, nil for
// direct play.
Transcode *Transcode
}
Session is one playback with its transcode, if any.
type SessionInfo ¶
type SessionInfo struct {
ID string `json:"id"`
}
type Stream ¶
type Stream struct {
ID ID `json:"id"`
StreamType int `json:"streamType"`
Codec string `json:"codec"`
Key string `json:"key"`
}
Stream is one stream of a part. An external Sidecar has a key.
type TimelineEntry ¶
type Transcode ¶
type Transcode struct {
Key string `json:"key"`
VideoDecision string `json:"videoDecision"`
AudioDecision string `json:"audioDecision"`
TranscodeHwRequested bool `json:"transcodeHwRequested"`
TranscodeHwDecoding string `json:"transcodeHwDecoding"`
TranscodeHwEncoding string `json:"transcodeHwEncoding"`
TranscodeHwFullPipeline bool `json:"transcodeHwFullPipeline"`
}
Transcode is a transcode session. VideoDecision is "transcode" when the video is re-encoded and "copy" for a remux. Direct play has none.