|
1 | | -## Table of contents |
| 1 | +# Documentation |
2 | 2 |
|
3 | | -- [\jc21\PlexApi](#class-jc21plexapi) |
| 3 | +### Main Class |
| 4 | + |
| 5 | +[PlexApi](PlexApi.md)<br /> |
| 6 | + |
| 7 | +### Collection Classes |
| 8 | + |
| 9 | +`ItemCollection` - enables collection functionality and implements the `\IteratorAggregate` interface<br /> |
| 10 | +`ItemIterator` - enables iterator functionality and implements the `\Iterator` interface |
| 11 | + |
| 12 | +### Media Classes |
| 13 | + |
| 14 | +[Movie](Movie.md)<br /> |
| 15 | +[Show](Show.md)<br /> |
| 16 | +[Season](Season.md)<br /> |
| 17 | +[Episode](Episode.md)<br /> |
| 18 | + |
| 19 | +### Utility Classes |
| 20 | + |
| 21 | +[Duration](Duration.md)<br /> |
| 22 | +[Filter](Filter.md)<br /> |
| 23 | +Item - only present for inheritance and `ItemCollection`<br /> |
| 24 | +[Location](Location.md)<br /> |
| 25 | +[Media](Media.md)<br /> |
| 26 | +[Size](Size.md)<br /> |
| 27 | +[Section](Section.md) |
4 | 28 |
|
5 | 29 | <hr /> |
6 | | -### Class: \jc21\PlexApi |
| 30 | + |
| 31 | +## PlexApi |
7 | 32 |
|
8 | 33 | > Plex API Class - Communicate with your Plex Media Server. |
9 | 34 |
|
10 | | -###### Example |
| 35 | +**Note**: There is no formal documentation referencing the lifespan of a token. These appear to have a long shelf-life, but it is possible they rotate occasionally. |
| 36 | + |
| 37 | +### Example |
11 | 38 | ```php |
12 | | -<?php |
13 | | - $client = new jc21\PlexApi('192.168.0.10'); |
14 | | - $client->setAuth('username', 'password'); |
15 | | - $sections = $client->getLibrarySections(); |
| 39 | +$client = new jc21\PlexApi('{Plex server IP}'); |
| 40 | +$client->setAuth('username', 'password'); |
| 41 | +$sections = $client->getLibrarySections(); |
16 | 42 | ``` |
17 | 43 | If you wish to store the authentication token for later usage: |
18 | 44 | ```php |
19 | | -<?php |
20 | | -$client = new jc21\PlexApi('192.168.0.10'); |
| 45 | +$client = new jc21\PlexApi('{Plex server IP}'); |
21 | 46 | $client->setAuth('username', 'password'); |
22 | 47 | $token = $client->getToken(); |
23 | 48 | //Store the $token for later |
24 | 49 | ``` |
25 | 50 | The token can be reused on new requests later: |
26 | 51 | ```php |
27 | | -<?php |
28 | 52 | $token = FakeModel::get('token'); |
29 | | -$client = new jc21\PlexApi('192.168.0.10'); |
| 53 | +$client = new jc21\PlexApi('{Plex server IP}'); |
30 | 54 | $client->setToken($token); |
31 | 55 | //Now able to make requests just as if you started with a username / password |
32 | 56 | $sections = $client->getLibrarySections(); |
33 | 57 | ``` |
34 | | -**Note**: There is no formal documentation referencing the lifespan of a token. These appear to have a long shelf-life, but it is possible they rotate occasionally. |
35 | 58 |
|
36 | | -| Visibility | Function | |
37 | | -|:-----------|:---------| |
38 | | -| public | <strong>__construct(</strong><em>string</em> <strong>$host=`'127.0.0.1'`</strong>, <em>mixed/int</em> <strong>$port=32400</strong>, <em>bool</em> <strong>$ssl=false</strong>)</strong> : <em>void</em><br /><em>Instantiate the class with your Host/Port</em> | |
39 | | -| public | <strong>getBaseInfo()</strong> : <em>array/bool</em><br /><em>Get Plex Server basic info</em> | |
40 | | -| public | <strong>getLastCallStats()</strong> : <em>array</em><br /><em>Get last curl stats, for debugging purposes</em> | |
41 | | -| public | <strong>getLibrarySections()</strong> : <em>array/bool</em><br /><em>Get Library Sections ie Movies, TV Shows etc</em> | |
42 | | -| public | <strong>getLibrarySectionContents(</strong><em>int</em> <strong>$sectionKey</strong>)</strong> : <em>array/bool</em><br /><em>Get Library Section contents</em> | |
43 | | -| public | <strong>getMetadata(</strong><em>int</em> <strong>$item</strong>)</strong> : <em>array/bool</em><br /><em>Get Metadata for an Item</em> | |
44 | | -| public | <strong>getOnDeck()</strong> : <em>array/bool</em><br /><em>Get On Deck Info</em> | |
45 | | -| public | <strong>getRecentlyAdded()</strong> : <em>array/bool</em><br /><em>Get Recently Added</em> | |
46 | | -| public | <strong>getServers()</strong> : <em>array/bool</em><br /><em>Get Servers</em> | |
47 | | -| public | <strong>getSessions()</strong> : <em>array/bool</em><br /><em>Get Sessions from Plex</em> | |
48 | | -| public | <strong>getToken()</strong> : <em>string/bool</em><br /><em>Tests the set username and password and returns the auth token</em> | |
49 | | -| public | <strong>getTranscodeSessions()</strong> : <em>array/bool</em><br /><em>Get Transcode Sessions from Plex</em> | |
50 | | -| public | <strong>refreshLibrarySection(</strong><em>int</em> <strong>$sectionKey</strong>, <em>bool</em> <strong>$force=false</strong>)</strong> : <em>null/bool</em><br /><em>Refresh a Library Section. This makes Plex search for new and removed items from the Library paths. Doesn't return anything when successful.</em> | |
51 | | -| public | <strong>refreshMetadata(</strong><em>int</em> <strong>$item</strong>, <em>bool</em> <strong>$force=false</strong>)</strong> : <em>null/bool</em><br /><em>Refresh a specific item. Doesn't return anything when successful.</em> | |
52 | | -| public | <strong>search(</strong><em>string</em> <strong>$query</strong>)</strong> : <em>array/bool</em><br /><em>Search for Items</em> | |
53 | | -| public | <strong>setAuth(</strong><em>string</em> <strong>$username</strong>, <em>string</em> <strong>$password</strong>)</strong> : <em>void</em><br /><em>Credentials for logging into Plex.tv. Username can also be an email address.</em> | |
54 | | -| public | <strong>setToken(</strong><em>string</em> <strong>$token</strong>)</strong> : <em>void</em><br /><em>A valid token for a logged in device, obtainable using setAuth().</em> | |
55 | | -| public | <strong>setClientIdentifier(</strong><em>string</em> <strong>$identifier</strong>)</strong> : <em>void</em><br /><em>setClientIdentifier</em> | |
56 | | -| public | <strong>setDevice(</strong><em>string</em> <strong>$name</strong>)</strong> : <em>void</em><br /><em>setDevice</em> | |
57 | | -| public | <strong>setDeviceName(</strong><em>string</em> <strong>$name</strong>)</strong> : <em>void</em><br /><em>setDeviceName</em> | |
58 | | -| public | <strong>setProductName(</strong><em>string</em> <strong>$name</strong>)</strong> : <em>void</em><br /><em>setProductName</em> | |
59 | | -| public | <strong>setTimeout(</strong><em>int</em> <strong>$timeout</strong>)</strong> : <em>void</em><br /><em>setTimeout</em> | |
60 | | -| protected | <strong>call(</strong><em>string</em> <strong>$path</strong>, <em>array</em> <strong>$params=array()</strong>, <em>string</em> <strong>$method=`'GET'`</strong>, <em>bool</em> <strong>$isLoginCall=false</strong>)</strong> : <em>array/bool</em><br /><em>Make an API Call or Login Call</em> | |
61 | | -| protected static | <strong>normalizeSimpleXML(</strong><em>mixed</em> <strong>$obj</strong>, <em>mixed</em> <strong>$result</strong>)</strong> : <em>void</em><br /><em>normalizeSimpleXML</em> | |
62 | | -| protected static | <strong>xml2array(</strong><em>mixed</em> <strong>$xml</strong>)</strong> : <em>mixed</em><br /><em>xml2array</em> | |
| 59 | +If you know which library section contains the data content you want (e.g. all your public movies). The following will return an `ItemCollection` of all items in library section 1. I can then loop through that collection to output each item in JSON. |
| 60 | + |
| 61 | +```php |
| 62 | +$client = new jc21\PlexApi('{Plex server IP}'); |
| 63 | +$movieLibrary = $client->getLibrarySectionContents(1, true); |
| 64 | +foreach($movieLibrary as $movie) { |
| 65 | + print json_encode($movie).PHP_EOL; |
| 66 | +} |
| 67 | +``` |
0 commit comments