plex

package
v0.0.0-...-831ccf3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 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

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

View Source
const (
	TimelineCreated = 0
	TimelineDone    = 5
	TimelineDeleted = 9
)

Timeline states Plex sends for library items.

View Source
const StreamSubtitle = 3

StreamSubtitle is a subtitle stream's streamType.

Variables

ItemTypes are the listings that between them hold every file of a section.

Functions

func NotFound

func NotFound(err error) bool

NotFound is whether err is a 404.

func Refused

func Refused(err error) bool

Refused is whether err is the server refusing the token, or its absence.

Types

type Activity

type Activity struct {
	UUID     string `json:"uuid"`
	Type     string `json:"type"`
	Title    string `json:"title"`
	Progress int    `json:"progress"`
	Context  struct {
		LibrarySectionID ID `json:"librarySectionID"`
	} `json:"Context"`
}

type ActivityEntry

type ActivityEntry struct {
	Event    string   `json:"event"`
	UUID     string   `json:"uuid"`
	Activity Activity `json:"Activity"`
}

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 New

func New(base *url.URL, token string, h Headers, c *http.Client) *Client

func (*Client) Identity

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

func (*Client) Item

func (c *Client) Item(ctx context.Context, ratingKey ID) (Metadata, bool, error)

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

func (c *Client) Playing(ctx context.Context) ([]Session, []Transcode, error)

Playing is Sessions and every transcode, which lists those of sessions /status/sessions doesn't list yet.

func (*Client) RefreshItem

func (c *Client) RefreshItem(ctx context.Context, ratingKey ID) error

RefreshItem reads one item's media and Sidecars again.

func (*Client) RefreshPath

func (c *Client) RefreshPath(ctx context.Context, section ID, folder string) error

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

func (c *Client) RefreshSection(ctx context.Context, section ID) error

RefreshSection is a scan of the whole section.

func (*Client) Section

func (c *Client) Section(ctx context.Context, key ID) (Section, bool, error)

Section is one section by its key, false when the server holds none.

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) Sections

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

func (*Client) Server

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

func (*Client) Sessions

func (c *Client) Sessions(ctx context.Context) ([]Session, error)

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).

func (*Client) SetCollections

func (c *Client) SetCollections(ctx context.Context, ratingKey ID, typ ItemType, titles []string) error

SetCollections sets the collections of the item at ratingKey, of type typ, to titles and locks them, so a later refresh keeps them.

func (*Client) Transcodes

func (c *Client) Transcodes(ctx context.Context) ([]Transcode, error)

Transcodes are /transcode/sessions.

type Error

type Error struct {
	Status int
	// Detail is the start of the response body.
	Detail string
}

Error is a response other than 2xx.

func (*Error) Error

func (e *Error) Error() string

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

func (id *ID) UnmarshalJSON(b []byte) error

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 ItemType

type ItemType int

ItemType is the type filter of a section listing.

const (
	TypeMovie   ItemType = 1
	TypeEpisode ItemType = 4
)

func TypeOf

func TypeOf(t string) ItemType

TypeOf is the listing that holds an item whose Metadata.Type is t.

type Location

type Location struct {
	ID   int    `json:"id"`
	Path string `json:"path"`
}

Location is a section folder as the server's OS names it.

type Media

type Media struct {
	ID    ID     `json:"id"`
	Parts []Part `json:"Part"`
}

Media is one version of an item.

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 Page

type Page struct {
	Items []Metadata
	Total int
}

Page is one page of a section's items.

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 PlaySession struct {
	SessionKey       ID     `json:"sessionKey"`
	ClientIdentifier string `json:"clientIdentifier"`
	RatingKey        ID     `json:"ratingKey"`
	Key              string `json:"key"`
	State            string `json:"state"`
	ViewOffset       int64  `json:"viewOffset"`
	TranscodeSession string `json:"transcodeSession"`
}

type Player

type Player struct {
	Title             string `json:"title"`
	Product           string `json:"product"`
	MachineIdentifier string `json:"machineIdentifier"`
	State             string `json:"state"`
}

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 Tag

type Tag struct {
	Tag string `json:"tag"`
}

type TimelineEntry

type TimelineEntry struct {
	SectionID     ID     `json:"sectionID"`
	ItemID        ID     `json:"itemID"`
	Type          int    `json:"type"`
	Title         string `json:"title"`
	State         int    `json:"state"`
	MetadataState string `json:"metadataState"`
}

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.

type User

type User struct {
	ID    ID     `json:"id"`
	Title string `json:"title"`
}

Jump to

Keyboard shortcuts

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