class Plex_Server_Library extends Plex_Server

Class that represents a Plex library and allows interaction with its sections and items.

Constants

DEFAULT_ADDRESS

The default address on which a Plex server listens.

DEFAULT_PORT

The default port on which a Plex server listens.

ENDPOINT_CLIENT

The Plex HTTP API endpoint for client listing.

ENDPOINT_LIBRARY

URL endpoint for Plex server library.

ENDPOINT_SECTION

URL endpoint for library sections.

ENDPOINT_RECENTLY_ADDED

URL endpoint for a library's recently added items.

ENDPOINT_ON_DECK

URL endpoint for a library's on deck items.

ENDPOINT_METADATA

URL endpoint for single library items.

TYPE_MOVIE

String that identifies a Plex library movie item type.

TYPE_ARTIST

String that identifies a Plex library artist item type.

TYPE_ALBUM

String that identifies a Plex library album item type.

TYPE_TRACK

String that identifies a Plex library track item type.

TYPE_PHOTO

String that identifies a Plex library photo item type.

TYPE_SHOW

String that identifies a Plex library TV show item type.

TYPE_SEASON

String that identifies a Plex library TV season item type.

TYPE_EPISODE

String that identifies a Plex library episode item type.

Properties

protected string $name The name of the Plex machine on the network. from Plex_MachineAbstract
protected string $address The IP address of the Plex machine on the network. from Plex_MachineAbstract
protected integer $port The port on which the Plex machine is listening. Typically 32400 for servers and 3000 for clients. from Plex_MachineAbstract
protected string $token The token of the Plex machine on the network. from Plex_MachineAbstract

Methods

string
getBaseUrl()

Returns the base URL, which will be standard for all requests made to the Plex machine.

array
xmlAttributesToArray(SimpleXMLElement $xml, integer $pass = 0)

Typically the useful data returned by a Plex machine will containted in XML attributes. This allows a set of XML nodes to be passed and all the attribues extracted and returned as an associated array.

array
makeCall(string $url)

Utilizes php-curl to send a request to the passed URL and returns an XML document reprentation of the returned content.

string
getCallingFunction(integer $depth = 2)

Universal function so any method belonging to a child class of a Plex machine can discover which function called it. This is used mainly for some of our polymorphic requests as the calling function can tell us what type of item is being requested.

void
__construct(string $name, string $address, integer $port, string $token)

Sets up our Plex server using the minimum amount of data required to interact.

getClients()

Returns all the available clients to which the Plex server has access indexed by the Plex client name.

getLibrary()

Returns the Plex library belonging to the instantiated Plex server.

string
getName()

Returns the Plex server's name.

string
getAddress()

Returns the Plex server's IP address.

integer
getPort()

Returns the port on which the Plex server listens.

string
getToken()

Returns the token on which the Plex machine listens.

string
buildUrl(string $endpoint)

Generic way of building a url agains the Plex library.

mixed[]
getItems(string $endpoint)

Generic way of requesting Plex library items.

string
functionToType($function)

Given a function name, uses that name to decide what Plex library item item type with which the function is associated. This is useful when trying to polymorphically request items because we can use the calling function to abstractly identify what type of item with which we are dealing.

mixed[]
getSections()

Returns an array of user defined Plex library sections that can be used to interact with the items contained within.

mixed
getSectionByKey(integer $key) deprecated

Returns a Plex library section by its given key. Here we simply run self::getSections() because the endpoint /library/sections/ID does not return full section data, it returns the categories below the section.

mixed
getSection(integer|string $polymorphicData)

Returns a Plex library section by its given key or by a exact match on title. Here we simply run self::getSections() because the endpoint /library/sections/ID does not return full section data, it returns the categories below the section.

mixed[]
getRecentlyAddedItems()

Returns the recently added items at the library level.

mixed[]
getOnDeckItems()

Returns the on deck items at the library level.

Details

in Plex_MachineAbstract at line 78
protected string getBaseUrl()

Returns the base URL, which will be standard for all requests made to the Plex machine.

Return Value

string The base URL, which will be standard for all requests made to the Plex machine.

in Plex_MachineAbstract at line 102
protected array xmlAttributesToArray(SimpleXMLElement $xml, integer $pass = 0)

Typically the useful data returned by a Plex machine will containted in XML attributes. This allows a set of XML nodes to be passed and all the attribues extracted and returned as an associated array.

Parameters

SimpleXMLElement $xml An XML node to have its attributes converted to a useful PHP array.
integer $pass The number of recursive levels down the method has run. This is mainly used for determining if we are on our first pass or not because the data is picked up slightly differently on the first pass.

Return Value

array An associated array of XML attributes.

in Plex_MachineAbstract at line 149
protected array makeCall(string $url)

Utilizes php-curl to send a request to the passed URL and returns an XML document reprentation of the returned content.

Parameters

string $url The URL to which the request is to be made.

Return Value

array An XML document from a Plex machine converted in array.

Exceptions

Plex_Exception_Machine

in Plex_MachineAbstract at line 196
protected string getCallingFunction(integer $depth = 2)

Universal function so any method belonging to a child class of a Plex machine can discover which function called it. This is used mainly for some of our polymorphic requests as the calling function can tell us what type of item is being requested.

Parameters

integer $depth Depth defaults to 2 because 0 is this function and 1 will be the function that asked for the calling function. This can be changed by the calling function in case a specific calling function needs to be identified. This can be handy if the original calling function goes through a number of hops on its way to identification.

Return Value

string The name of the function that called the function that issued the getCallingFunction request.

in Plex_Server at line 75
void __construct(string $name, string $address, integer $port, string $token)

Sets up our Plex server using the minimum amount of data required to interact.

Parameters

string $name The name of the Plex server.
string $address The IP address of the Plex server.
integer $port The port on which the Plex server is listening.
string $token The token of the Plex server.

Return Value

void

in Plex_Server at line 99
Plex_Client[] getClients()

Returns all the available clients to which the Plex server has access indexed by the Plex client name.

Return Value

Plex_Client[] An array of Plex clients indexed by the Plex client name.

in Plex_Server at line 138
Plex_Server_Library getLibrary()

Returns the Plex library belonging to the instantiated Plex server.

Return Value

Plex_Server_Library The Plex library belonging to the instantiated Plex server.

in Plex_Server at line 155
string getName()

Returns the Plex server's name.

Return Value

string The name of the Plex machine.

in Plex_Server at line 167
string getAddress()

Returns the Plex server's IP address.

Return Value

string The IP address of the Plex machine.

in Plex_Server at line 179
integer getPort()

Returns the port on which the Plex server listens.

Return Value

integer The port on which the Plex machine listens.

in Plex_Server at line 191
string getToken()

Returns the token on which the Plex machine listens.

Return Value

string The token on which the Plex machine listens.

at line 123
protected string buildUrl(string $endpoint)

Generic way of building a url agains the Plex library.

Parameters

string $endpoint A URL endpoint of a Plex service.

Return Value

string A Plex library URL based on the given endpoint.

at line 160
protected mixed[] getItems(string $endpoint)

Generic way of requesting Plex library items.

Parameters

string $endpoint A URL endpoint of a Plex service.

Return Value

mixed[] An array of plex library items.

at line 204
string functionToType($function)

Given a function name, uses that name to decide what Plex library item item type with which the function is associated. This is useful when trying to polymorphically request items because we can use the calling function to abstractly identify what type of item with which we are dealing.

Parameters

$function

Return Value

string The type of item with which the given function is associated.

at line 240
mixed[] getSections()

Returns an array of user defined Plex library sections that can be used to interact with the items contained within.

Return Value

mixed[] An array of user defined Plex library sections.

at line 280
mixed getSectionByKey(integer $key) deprecated

deprecated This method is deprecated in lieu of the new getSection() method.

Returns a Plex library section by its given key. Here we simply run self::getSections() because the endpoint /library/sections/ID does not return full section data, it returns the categories below the section.

Parameters

integer $key The key of the requested section.

Return Value

mixed The request library section.

Exceptions

Plex_Exception_Server_Library

at line 311
mixed getSection(integer|string $polymorphicData)

Returns a Plex library section by its given key or by a exact match on title. Here we simply run self::getSections() because the endpoint /library/sections/ID does not return full section data, it returns the categories below the section.

Parameters

integer|string $polymorphicData The key or title of the requested section.

Return Value

mixed The request library section.

Exceptions

Plex_Exception_Server_Library()

at line 343
mixed[] getRecentlyAddedItems()

Returns the recently added items at the library level.

Return Value

mixed[] An array of plex library items.

at line 356
mixed[] getOnDeckItems()

Returns the on deck items at the library level.

Return Value

mixed[] An array of plex library items.