-
-
Notifications
You must be signed in to change notification settings - Fork 321
/
Plex.php
100 lines (85 loc) · 2.5 KB
/
Plex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace App\SupportedApps\Plex;
class Plex extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;
//protected $login_first = true; // Uncomment if api requests need to be authed first
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
public function __construct()
{
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
}
public function test()
{
$test = parent::appTest(
$this->url("/library/recentlyAdded"),
$this->attrs()
);
echo $test->status;
}
public function livestats()
{
$status = "inactive";
$res = parent::execute(
$this->url("/library/recentlyAdded"),
$this->attrs()
);
$body = $res->getBody();
$xml = simplexml_load_string(
$body,
"SimpleXMLElement",
LIBXML_NOCDATA | LIBXML_NOBLANKS
);
$data = [];
if ($xml) {
$data["recently_added"] = $xml["size"];
$status = "active";
}
$res = parent::execute($this->url("/library/onDeck"));
$res = parent::execute($this->url("/library/onDeck"), $this->attrs());
$body = $res->getBody();
$xml = simplexml_load_string(
$body,
"SimpleXMLElement",
LIBXML_NOCDATA | LIBXML_NOBLANKS
);
if ($xml) {
$data["on_deck"] = $xml["size"];
$status = "active";
}
return parent::getLiveStats($status, $data);
}
public function url($endpoint)
{
$url = parse_url(parent::normaliseurl($this->config->url));
$scheme = $url["scheme"];
$domain = $url["host"];
$port = isset($url["port"]) ? $url["port"] : "32400";
$api_url =
$scheme .
"://" .
$domain .
":" .
$port .
$endpoint .
"?X-Plex-Token=" .
$this->config->token;
return $api_url;
}
public function getConfigValue($key, $default = null)
{
return isset($this->config) && isset($this->config->$key)
? $this->config->$key
: $default;
}
public function attrs()
{
$ignoreTls = $this->getConfigValue("ignore_tls", false);
if ($ignoreTls) {
$attrs["verify"] = false;
} else {
$attrs = [];
}
return $attrs;
}
}