plexclient

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout           = 120 * time.Second
	DefaultMaxRetries        = 3
	DefaultPageSize          = 100
	DefaultConcurrentWorkers = 4
	DefaultHistoryLimit      = 50
	DefaultSearchLimit       = 50
	RetryExponent            = 2.0
	MaxBackoffDuration       = 30 * time.Second
	DefaultClientID          = "plexcli"
	DefaultLibraryPathPrefix = "/library/sections/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Account represents a Plex user account

type ActiveSession

type ActiveSession struct {
	User     string `json:"user"`
	Title    string `json:"title"`
	Type     string `json:"type"`
	Show     string `json:"show,omitempty"`
	Progress string `json:"progress"`
	Device   string `json:"device"`
	State    string `json:"state"`
}

ActiveSession represents a currently playing session

type Client

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

Client provides access to a Plex server.

func NewClient

func NewClient(serverURL, token string, opts ...ClientOption) (*Client, error)

func (*Client) AddToPlaylist

func (c *Client) AddToPlaylist(ctx context.Context, playlistID string, ratingKeys []string) error

AddToPlaylist adds items to an existing playlist

func (*Client) ApplyMatch

func (c *Client) ApplyMatch(ctx context.Context, ratingKey string, guid string, name string) error

ApplyMatch applies a metadata match to an item (like selecting a match in Plex's "Fix Match")

func (*Client) CreatePlaylist

func (c *Client) CreatePlaylist(ctx context.Context, title string, playlistType string, ratingKeys []string) (*PlaylistInfo, error)

CreatePlaylist creates a new playlist with the given name and optional initial items ratingKeys should be a slice of rating keys to add to the playlist

func (*Client) CreateSmartPlaylist

func (c *Client) CreateSmartPlaylist(ctx context.Context, title string, playlistType string, sectionID string, filterType string, filterValue string) (*PlaylistInfo, error)

CreateSmartPlaylist creates a smart playlist based on a filter (e.g., by director) sectionID is the library section, filterType is the filter category (e.g., "director"), filterValue is the filter ID (e.g., director ID from GetDirectors)

func (*Client) DeletePlaylist

func (c *Client) DeletePlaylist(ctx context.Context, playlistID string) error

DeletePlaylist deletes a playlist by ID

func (*Client) FindShow

func (c *Client) FindShow(ctx context.Context, showName string) (string, string, error)

FindShow searches for a show by name and returns its rating key

func (*Client) GetAccounts

func (c *Client) GetAccounts(ctx context.Context) ([]Account, error)

GetAccounts returns all user accounts on the server

func (*Client) GetActiveSessions

func (c *Client) GetActiveSessions(ctx context.Context) ([]ActiveSession, error)

GetActiveSessions returns currently active playback sessions

func (*Client) GetAllLibraryItems

func (c *Client) GetAllLibraryItems(ctx context.Context, sectionID string) ([]*components.Metadata, error)

func (*Client) GetDirectorID

func (c *Client) GetDirectorID(ctx context.Context, sectionID string, directorName string) (string, error)

GetDirectorID looks up a director by name and returns their ID

func (*Client) GetDirectors

func (c *Client) GetDirectors(ctx context.Context, sectionID string) ([]DirectorInfo, error)

GetDirectors returns all directors in a library section

func (*Client) GetHistory

func (c *Client) GetHistory(ctx context.Context, limit int) ([]HistoryItem, error)

func (*Client) GetItemMetadata

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

GetItemMetadata fetches detailed metadata for a single item including streams

func (*Client) GetLibraryItemsConcurrent

func (c *Client) GetLibraryItemsConcurrent(ctx context.Context, sectionIDs []string, maxConcurrent int) ([]*components.Metadata, error)

func (*Client) GetMaxRetries

func (c *Client) GetMaxRetries() int

func (*Client) GetMoviesByDirector

func (c *Client) GetMoviesByDirector(ctx context.Context, sectionID string, directorName string) ([]MovieInfo, error)

GetMoviesByDirector returns all movies by a given director from a library section The director name matching is case-insensitive and supports partial matches

func (*Client) GetPlaylistItems

func (c *Client) GetPlaylistItems(ctx context.Context, playlistID string) ([]SearchResult, error)

GetPlaylistItems returns the items in a playlist

func (*Client) GetSeasonEpisodes

func (c *Client) GetSeasonEpisodes(ctx context.Context, showRatingKey string, seasonNum int) ([]EpisodeInfo, error)

GetSeasonEpisodes returns all episodes for a specific season of a show

func (*Client) GetSections

func (c *Client) GetSections(ctx context.Context) ([]Library, error)

func (*Client) GetServerURL

func (c *Client) GetServerURL() string

func (*Client) GetServerUUID

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

GetServerUUID returns the server's machine identifier (UUID)

func (*Client) GetShowEpisodes

func (c *Client) GetShowEpisodes(ctx context.Context, showRatingKey string) ([]Episode, error)

GetShowEpisodes returns all episodes for a show given its rating key

func (*Client) GetStreams

func (c *Client) GetStreams(ctx context.Context, ratingKey string) ([]StreamInfo, error)

GetStreams returns all streams (video, audio, subtitle) for an item

func (*Client) GetTimeout

func (c *Client) GetTimeout() time.Duration

func (*Client) GetWatchHistory

func (c *Client) GetWatchHistory(ctx context.Context) ([]HistoryEntry, error)

GetWatchHistory returns the watch history

func (*Client) ListPlaylists

func (c *Client) ListPlaylists(ctx context.Context) ([]PlaylistInfo, error)

ListPlaylists returns all playlists

func (*Client) SearchLibrary

func (c *Client) SearchLibrary(ctx context.Context, query string, sectionID *string, limit int) ([]SearchResult, error)

SearchLibrary searches the Plex library for items matching the query

func (*Client) SearchMatches

func (c *Client) SearchMatches(ctx context.Context, ratingKey string, title string, year int) ([]MatchResult, error)

SearchMatches searches for metadata matches for an item (like Plex's "Fix Match" feature)

func (*Client) SetStreams

func (c *Client) SetStreams(ctx context.Context, partID string, audioStreamID, subtitleStreamID int) error

SetStreams sets the default audio and/or subtitle stream for a part

type ClientOption

type ClientOption func(*Client)

func WithMaxRetries

func WithMaxRetries(maxRetries int) ClientOption

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

type DirectorInfo

type DirectorInfo struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Count int    `json:"count"` // Number of movies by this director
}

DirectorInfo represents a director in the library

type Episode

type Episode struct {
	RatingKey   string `json:"ratingKey"`
	Title       string `json:"title"`
	ShowTitle   string `json:"showTitle"`
	SeasonNum   int    `json:"season"`
	EpisodeNum  int    `json:"episode"`
	SeasonTitle string `json:"seasonTitle,omitempty"`
}

Episode represents a TV episode with season/episode info

type EpisodeInfo

type EpisodeInfo struct {
	RatingKey string
	PartID    string
	Title     string
	Season    int
	Episode   int
}

EpisodeInfo represents basic episode information

type HistoryEntry

type HistoryEntry struct {
	Title            string    `json:"title"`
	Type             string    `json:"type"`
	GrandparentTitle string    `json:"grandparent_title,omitempty"`
	ParentIndex      int       `json:"parent_index,omitempty"`
	Index            int       `json:"index,omitempty"`
	AccountID        int       `json:"account_id"`
	DeviceID         int       `json:"device_id"`
	ViewedAt         time.Time `json:"viewed_at"`
}

HistoryEntry represents a watch history entry

type HistoryItem

type HistoryItem struct {
	Title            string
	GrandparentTitle string
	Type             string
	RatingKey        *string
	LibrarySectionID *string
	ViewedAt         int64
	Thumb            *string
}

type Library

type Library struct {
	ID       string
	Title    *string
	Type     string
	Key      *string
	UUID     string
	Location []string
}

Library represents a Plex library section.

type MatchResult

type MatchResult struct {
	GUID    string `json:"guid"`
	Name    string `json:"name"`
	Year    int    `json:"year,omitempty"`
	Summary string `json:"summary,omitempty"`
}

MatchResult represents a potential metadata match for an item

type MovieInfo

type MovieInfo struct {
	RatingKey string   `json:"ratingKey"`
	Title     string   `json:"title"`
	Year      int      `json:"year"`
	Directors []string `json:"directors"`
}

MovieInfo represents a movie with director info

type PlaylistInfo

type PlaylistInfo struct {
	RatingKey    string `json:"ratingKey"`
	Key          string `json:"key"`
	Title        string `json:"title"`
	Type         string `json:"type"`
	PlaylistType string `json:"playlistType"`
	LeafCount    int    `json:"leafCount"`
	Smart        bool   `json:"smart"`
	Duration     int64  `json:"duration"`
}

PlaylistInfo represents a playlist

type PlexError

type PlexError struct {
	Op      string
	Section string
	Err     error
}

PlexError provides structured error information for Plex API operations.

func (*PlexError) Error

func (e *PlexError) Error() string

func (*PlexError) Unwrap

func (e *PlexError) Unwrap() error

type SearchResult

type SearchResult struct {
	RatingKey        string  `json:"ratingKey"`
	Key              string  `json:"key"`
	Title            string  `json:"title"`
	Type             string  `json:"type"`
	Year             *int    `json:"year"`
	GrandparentTitle *string `json:"grandparentTitle"`
	ParentTitle      *string `json:"parentTitle"`
	ParentIndex      *int    `json:"parentIndex"`
	Index            *int    `json:"index"`
	Thumb            *string `json:"thumb"`
}

SearchResult represents a single search result item

type StreamInfo

type StreamInfo struct {
	ID           int    `json:"id"`
	StreamType   int    `json:"stream_type"`
	Language     string `json:"language"`
	LanguageCode string `json:"language_code"`
	Codec        string `json:"codec"`
	Title        string `json:"title,omitempty"`
	Channels     int    `json:"channels,omitempty"`
	Selected     bool   `json:"selected"`
	Default      bool   `json:"default"`
}

StreamInfo represents an audio or subtitle stream

Jump to

Keyboard shortcuts

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