node-plex-client, a promise based Plex API¶
Classes¶
PlexClient¶
-
class
PlexClient
(options)¶ PlexClient is the first class that any API callers must instantiate. It is responsible for holding details about the sort of device that is using the API. Different settings will cause Plex to respond differently, for example only certain product names will work for syncing.
An optional options argument can be passed to override various defaults for the settings which have the following defaults:
- product
- “plex-client”.
- version
- plex-client’s version.
- platform
- The current OS.
- platformVersion
- The current OS version.
- device
- The current OS.
- name
- The current hostname.
- uuid
- A unique identified for the client, generated from the hostname.
- provides
- An array of services the client provides.
- screenResolution
- “1920x1080”.
- screenDensity
- undefined.
Arguments: - options (Object) – override the default options.
-
PlexClient.
Android
(options)¶ Creates a new PlexClient but uses a set of defaults that makes it look like an Android client.
Arguments: - options (Object) – override options as described in the constructor.
-
PlexClient.
WebBrowser
(options)¶ Creates a new PlexClient but uses a set of defaults that makes it look like a web browser client.
Arguments: - options (Object) – override options as described in the constructor.
PlexAccount¶
-
class
PlexAccount
(client, data)¶ Represents a user’s plex.tv account information. Used for listing associated devices, see getResource, getResources or getServer.
This is an internal class and should not be instantiated directly. Instead use PlexAccount.login to create an instance.
Arguments: - client (PlexClient) – the connection info to use for API calls.
- data (*) – the parsed data for the account.
-
PlexAccount.
login
(client, username, password)¶ Logs in to a plex.tv account and returns a PlexAccount instance.
Arguments: - client (PlexClient) – the client data to use to request login.
- username (String) – the user’s username.
- password (String) – the user’s password.
Returns: Promise.<PlexAccount> – the account instance on success.
-
PlexAccount.
getResource
(name)¶ Retrieves a PlexDevice for a recently used resource. This generally means API clients that can be controlled or accessed in some way.
Arguments: - name (String) – the name of the device
Returns: Promise.<PlexDevice> – the device on success.
-
PlexAccount.
getResources
(provides)¶ Retrieves a list of PlexDevice’s that support the passed features.
Arguments: - provides (Array.<String>) – a list of features the resource should support.
Returns: Promise.<Array.<PlexDevice>> – a list of devices.
-
PlexAccount.
getServers
()¶ A shortcut for getting the server resources.
Returns: Promise.<Array.<PlexDevice>> – a list of servers.
PlexDevice¶
-
class
PlexDevice
(client, baseuri, token, data)¶ Represents a connected device. You can retrieve information and send commands to the device. PlexDevice is an instance of PlexContainer which allows browsing the device’s contents.
Creates a new PlexDevice. Generally you wouldn’t use this directly, instead get a device from PlexAccount.getResource or call PlexDevice.connect.
Arguments: - client (PlexClient) – the client used to access the device.
- baseuri (URL) – the URI to connect to the device.
- token (String) – the authentication used to access this device.
- data (Object) – data about the device.
-
PlexDevice.
connect
(client, baseuri, token)¶ Attempts to connect to a Plex device.
Arguments: - client – the PlexClient to use to connect.
- baseuri (URL) – the URI to connect to.
- token (String) – the authentication token to use.
Returns: Promise.<PlexDevice> – the connected device on success.
-
PlexDevice.
id
¶ Returns the device ID.
PlexItem¶
-
class
PlexItem
(device, path, data)¶ The basic building block for the Plex API. This class allows retrieving information about the item.
Do not construct this manually, instead get a PlexDevice which is an instance of PlexItem and then use it to browse the device’s contents.
Arguments: - device (PlexDevice) – the device that owns this item or null if this is the device.
- path (String) – the path to this item.
- data (Object) – the item’s data.
-
PlexItem.
device
¶ Gets the device owning this item.
-
PlexItem.
path
¶ Gets the path identifying this item.
-
PlexItem.
name
¶ Gets the item’s name.
-
PlexItem.
art
¶ Gets a banner picture to represent the item.
-
PlexItem.
thumb
¶ Gets a thumbnail to represent the item.
-
PlexItem.
thumbAspectRatio
¶ Gets the expected thumbnail aspect ratio.
PlexContainer¶
PlexMetadata¶
-
class
PlexMetadata
()¶ Most media is represented by the Metadata object. We split it out into different types as necessary.
-
PlexMetadata.
width
¶ Gets the width of this media item.
-
PlexMetadata.
height
¶ Gets the height of this media item.
-
PlexMetadata.
aspectRatio
¶ Gets the aspect ratio of this media item.
-
PlexMetadata.
container
¶ Gets the container of this media item.
-
This is a promise based Node API for interacting with Plex Media Servers and Plex accounts. The goal is to include basic browsing and sync functionality but it is in its early stages. Do not be surprised by large API changes in the near term.