Overview
PlexClient extends MediaClient to provide integration with Plex Media Server. It supports library browsing, video streaming (direct play and transcoding), and playlist-based favorites.
Constructor
Server configuration with Plex server details
Authentication
authenticate
Authenticates with a Plex server using an X-Plex-Token.Username (can be any value, used for display)
X-Plex-Token from Plex account settings
Server URL
Username or ‘Plex User’ if not provided
Server’s MachineIdentifier (used for playlist URIs)
X-Plex-Token for API requests
Always returns ‘plex’
Example
To get your X-Plex-Token, visit your Plex account settings or check the Plex documentation.
Library Management
getLibraries
Fetches all library sections from the Plex server.Array of library objects with Id (section key), Name (title), and CollectionType (type)
Example
Video Retrieval
getVideos
Fetches videos from a Plex library with filtering and pagination.Library section key (required for standard feeds, undefined for favorites)
Name of the library for playlist lookups
'latest': Sorted by addedAt descending'random': Random shuffle'favorites': Items from Tok playlist
Starting index for pagination
Not directly used (batch size: 50 for latest, 80 for random)
'vertical': Only videos with height >= width * 0.8'horizontal': Only videos with width > height'both': No filtering
Array of video items mapped from Plex format
Index for the next page
Total number of items in the library
Example
Media URLs
getVideoUrl
Generates streaming URL for a video with fallback to transcoding.Video item (with Plex-specific
_PlexKey field for direct play)Direct play URL if available, otherwise HLS transcode URL
getImageUrl
Generates URL for video thumbnail using Plex’s photo transcoder.Plex ratingKey
Not used for Plex (included for interface compatibility)
Not used for Plex (always fetches thumb)
Transcoded thumbnail URL at 800x1200
Example
Favorites Management
PlexClient uses playlists namedTok-{LibraryName} to store favorites.
getFavorites
Retrieves all favorited item IDs for a library.Name of the library
Set of ratingKeys in the Tok playlist (empty set if playlist doesn’t exist)
toggleFavorite
Adds or removes an item from the favorites playlist.Plex ratingKey of the video
Current status: true = currently favorited (will remove), false = not favorited (will add)
Library name for playlist lookup/creation
Example
Complete Usage Example
Implementation Details
Headers
All requests include:Accept: application/jsonX-Plex-Token: {token}
Plex Item Mapping
Plex metadata is mapped to EmbyItem format:ratingKey→Idtitle→Nametype→Typesummary→Overviewyear→ProductionYearMedia[0].width→WidthMedia[0].height→Heightduration→RunTimeTicks(converted: duration * 10000)thumb→ Stored in_PlexThumb(internal)Media[0].Part[0].key→ Stored in_PlexKey(internal)
Playlist URIs
When managing favorites, items are referenced using:Orientation Filtering
Same as EmbyClient:- Vertical:
height >= width * 0.8 - Horizontal:
width > height - Both: No filtering
See Also
- MediaClient - Base class reference
- EmbyClient - Emby/Jellyfin implementation
- LocalClient - Local file system implementation
- Types - Type definitions