Skip to content

Commit 9837816

Browse files
authored
Merge pull request #12 from godsgood33/master
Couple updates
2 parents 53666cf + 4c84e3c commit 9837816

30 files changed

+2195
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
vendor
44
composer.lock
5+
.env

LICENSE

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
The MIT License (MIT)
1+
1-clause BSD License (BSD-1-Clause)
22

33
Copyright (c) 2015 jc21
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
116

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
7+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
228

9+
THIS SOFTWARE IS PROVIDED BY jc21 “AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL jc21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ $client->setAuth('username', 'password');
3838
$result = $client->getOnDeck();
3939
print_r($result);
4040
```
41-

composer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"name": "jc21/plex-api",
33
"description": "PHP Api for Plex",
4-
"keywords": ["plex", "api", "media"],
4+
"keywords": [
5+
"plex",
6+
"api",
7+
"media"
8+
],
59
"homepage": "https://github.com/jc21/plex-api",
610
"license": "BSD-1-Clause",
711
"authors": [
@@ -12,14 +16,16 @@
1216
],
1317
"minimum-stability": "dev",
1418
"require": {
15-
"php": ">=5.3.0"
19+
"php": ">=7.4",
20+
"ext-curl": "*"
1621
},
1722
"require-dev": {
18-
"victorjonsson/markdowndocs": "dev-master"
23+
"victorjonsson/markdowndocs": "dev-master",
24+
"symfony/dotenv": "6.2.x-dev"
1925
},
2026
"autoload": {
2127
"psr-0": {
2228
"jc21": "src"
2329
}
2430
}
25-
}
31+
}

docs/Documentation.md

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,67 @@
1-
## Table of contents
1+
# Documentation
22

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)
428

529
<hr />
6-
### Class: \jc21\PlexApi
30+
31+
## PlexApi
732

833
> Plex API Class - Communicate with your Plex Media Server.
934
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
1138
```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();
1642
```
1743
If you wish to store the authentication token for later usage:
1844
```php
19-
<?php
20-
$client = new jc21\PlexApi('192.168.0.10');
45+
$client = new jc21\PlexApi('{Plex server IP}');
2146
$client->setAuth('username', 'password');
2247
$token = $client->getToken();
2348
//Store the $token for later
2449
```
2550
The token can be reused on new requests later:
2651
```php
27-
<?php
2852
$token = FakeModel::get('token');
29-
$client = new jc21\PlexApi('192.168.0.10');
53+
$client = new jc21\PlexApi('{Plex server IP}');
3054
$client->setToken($token);
3155
//Now able to make requests just as if you started with a username / password
3256
$sections = $client->getLibrarySections();
3357
```
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.
3558

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+
```

docs/Duration.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Duration
2+
3+
The object is created to represent the duration of a media file. The duration can then be output in `H:i:s` format
4+
5+
## Property List
6+
7+
| Data type | Property | Description |
8+
|:----------|:---------|:------------|
9+
| int | duration | The duration in milliseconds |
10+
11+
## Function List
12+
13+
| Visibility | Function (parameters,...): return |
14+
|:-----------|:---------|
15+
| public | <strong>__construct(</strong><em>int</em> <strong>$duration)</strong>: <em>void</em><br /> |
16+
| public | <strong>minutes()</strong>: <em>string</em><br />The duration represented in minutes |
17+
| public | <strong>seconds()</strong>: <em>string</em><br />The duration represented in seconds |
18+
| public | <strong>__toString()</strong>: <em>string</em><br />Auto convert the object to a string and output in `H:i:s` format |
19+
|
20+
21+
## Examples
22+
23+
```php
24+
$dur = new Duration(20152000);
25+
print $dur->seconds().PHP_EOL; // 20152
26+
print $dur->minutes().PHP_EOL; // 335
27+
print (string) $dur; // 05:35:52
28+
```

docs/Episode.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Episode
2+
3+
This class stores TV Episode data
4+
5+
## Property List
6+
7+
| Data type | Property | Description |
8+
|:----------|:---------|:------------|
9+
| int | ratingKey | An index |
10+
| int | parentRatingKey | The index for the parent season |
11+
| int | grandparentRatingKey | The index for the grandparent show |
12+
| string | key | A string that can be used to query the object directly |
13+
| string | parentKey | A string that can be used to query the parent season |
14+
| string | grandparentKey | A string to query the grandparent show |
15+
| string | guid | The GUID |
16+
| string | parentGuid | The parent season GUID |
17+
| string | grandparentGuid | The grandparent show GUID |
18+
| string | type | What type of media is this (`episode`) |
19+
| string | title | The title of the episode |
20+
| string | parentTitle | The title of the season |
21+
| string | grandparentTitle | The title of the show |
22+
| string | contentRating | The content rating of the episode (e.g. TV-G, TV-PG, etc) |
23+
| string | summary | The summary of the episode |
24+
| int | index | |
25+
| int | parentIndex | |
26+
| string | audienceRating | The audience rating |
27+
| string | audienceRatingImage | |
28+
| int | viewCount | The number of times this episode has been viewed |
29+
| string | thumb | The thumbnail image |
30+
| string | parentThumb | The parent season thumbnail image |
31+
| string | grandparentThumb | The grandparent show thumbnail image |
32+
| string | art | The background artwork |
33+
| string | grandparentArt | The shows artwork |
34+
| [Duration](Duration.md) | duration | The duration |
35+
| `DateTime` | lastViewedAt | The last date and time the episode was viewed |
36+
| `DateTime` | originallyAvailableAt | The original air date of the episode |
37+
| `DateTime` | addedAt | The date the episode was added to the library |
38+
| `DateTime` | updatedAt | The date the episode's entry in the library was updated |
39+
| [Media](Media.md) | media | The details of the media |
40+
41+
## Function List
42+
43+
| Visibility | Function (parameters,...): return |
44+
|:-----------|:---------|
45+
| public | <strong>__construct()</strong>: <em>void</em> |
46+
| public | <strong>__get(</strong><em>string</em> <strong>$var)</strong>: <em>mixed</em><br />Magic getter |
47+
| public | <strong>__set(</strong><em>string</em> <strong>$var</strong>, <em>mixed</em> <strong>$val)</strong>: <em>void</em><br />Magic setter |
48+
| public static | <strong>fromLibrary(</strong><em>array</em> <strong>$lib)</strong>: <em>Episode</em><br />Create an object from the array data from the PlexApi |

docs/Filter.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Filter
2+
3+
This class is specifically intended to filter a library section, but could be used for other purposes. Objects are `immutable` as there are no publicly available properties or setter methods.
4+
5+
## Function List
6+
7+
| Visibility | Function (parameters,...): return |
8+
|:-----------|:---------|
9+
| public | <strong>__construct(</strong><em>string</em> <strong>$field</strong>, <em>string</em> <strong>$value</strong>, <em>string</em> <strong>$operator = `'='`)</strong>: <em>void</em> |
10+
| public | <strong>__toString()</strong>: <em>string</em><br />Convert the object to a string |
11+
12+
## Examples
13+
14+
The `field` parameter in the constructor can accept, `title`, `studio`, `year`, `rating`, `contentRating`. Any other value will throw an `Exception`
15+
16+
Searching for *George of the Jungle*
17+
18+
```php
19+
$filter1 = new Filter('title', 'George');
20+
$filter2 = new Filter('year', 1997, ">=");
21+
$res = $api->filter(1, [$filter1, $filter2], true);
22+
// Returns any movie with George in the title and released in or after 1997
23+
```

docs/Location.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Location
2+
3+
Object to store library location info
4+
5+
## Property List
6+
7+
| Data type | Property | Description |
8+
|:----------|:---------|:------------|
9+
10+
11+
## Function List
12+
13+
| Visibility | Function (parameters,...): return |
14+
|:-----------|:---------|
15+
| public | <strong>__get(</strong><em>string</em> <strong>$var)</strong>: <em>mixed</em><br />Magic getter |
16+
| public static | <strong>fromLibrary(</strong><em>array</em> <strong>$location)</strong>: <em>Location</em><br />Create a library object from PlexApi call data |

docs/Media.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Media
2+
3+
This object is created for each media file
4+
5+
## Property List
6+
7+
| Data type | Property | Description |
8+
|:----------|:---------|:------------|
9+
| int | id | |
10+
| [Duration](Duration.md) | duration | The duration of the media |
11+
| int | bitrate | The total bitrate |
12+
| int | width | The pixel width of the video |
13+
| int | height | The pixel heigh of the video |
14+
| float | aspectRatio | The aspect ratio (1.6, 1.77, 2.35, etc) |
15+
| int | audioChannels | The number of audio channels |
16+
| string | audioCodec | The audio codec used (mp3, aac, etc) |
17+
| string | videoCodec | The video codec used (hvec, h264, etc) |
18+
| string | videoResolution | The resolution (720, 1080, 4k, etc) |
19+
| string | videoFrameRate | The frame rate |
20+
| bool | optomizedForStreaming | |
21+
| string | audioProfile | The audio profile info |
22+
| bool | has64bitOffsets | |
23+
| string | videoProfile | The video profile info |
24+
| string | title | The title of the media |
25+
| [Size](Size.md) | size | The size of the file |
26+
| string | path | The path of the file |
27+
28+
## Function List
29+
30+
| Visibility | Function (parameters,...): return |
31+
|:-----------|:---------|
32+
| public | <strong>__get(</strong><em>string</em> <strong>$var)</strong>: <em>mixed</em><br />Magic getter |
33+
| public | <strong>__set(</strong><em>string</em> <strong>$var</strong>, <em>mixed</em><strong>$val)</strong>: <em>void</em><br />Magic setter |
34+
| public static | <strong>fromLibrary(</strong><em>array</em> <strong>$lib)</strong>: <em>Media</em><br />Method to create Media object from Plex API call |

0 commit comments

Comments
 (0)