-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hjone72
authored and
hjone72
committed
Oct 17, 2016
1 parent
3bc9ce8
commit 36ffc84
Showing
1 changed file
with
28 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
<?php | ||
function plexpyAPI($command){ | ||
//Get Plex Library stats from PlexPy | ||
function plexpyAPI($command, $cached = false){ | ||
//Get API cmd from PlexPy | ||
if ($cached != false) { | ||
if (array_key_exists('plexpy', $_SESSION)) { | ||
if (array_key_exists($cached, $_SESSION['plexpy'])) { | ||
return $_SESSION['plexpy'][$cached]; | ||
} | ||
} | ||
} | ||
|
||
//Load module config | ||
$module_config = parse_ini_file("config.module.ini.php"); //Config file that has configurations for site. | ||
|
||
//Get the users friendly name from PlexPy | ||
$pyapi = $module_config['pp_api']; | ||
$pyurl = $module_config['pp_url']; | ||
$return = json_decode(file_get_contents($pyurl . "/plexpy/api/v2?apikey=". $pyapi . "&cmd=" . $command)); | ||
return $return; | ||
|
||
$host = "https://localhost:8181/plexpy/api/v2?apikey=". $pyapi . "&cmd=" . $command; | ||
$process = curl_init($host); | ||
curl_setopt($process, CURLOPT_HEADER, 0); | ||
curl_setopt($process, CURLOPT_TIMEOUT, 30); | ||
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, 0); | ||
curl_setopt($process, CURLOPT_RETURNTRANSFER, true); | ||
$data = curl_exec($process); | ||
$curlError = curl_error($process); | ||
curl_close($process); | ||
$json = json_decode($data, true); | ||
|
||
if ($cached != false){ | ||
$_SESSION['plexpy'][$cached] = $json; | ||
} | ||
|
||
return $json; | ||
} | ||
?> | ||
?> |