function getTranscodeSessions() { global $plex_instances; foreach ($plex_instances as $instance) { $plex_port = $instance[1]; $network = getNetwork($instance[3]); $plexSessionXML = simplexml_load_file($network . ':' . $plex_port . '/status/sessions'); if (count($plexSessionXML->Video) > 0) { $i = 0; // i is the variable that gets iterated each pass through the array $t = 0; // t is the total amount of sessions $transcodeSessions = 0; // this is the number of active transcodes foreach ($plexSessionXML->Video as $sessionInfo) { $t++; } foreach ($plexSessionXML->Video as $sessionInfo) { if ($sessionInfo->TranscodeSession['videoDecision'] == 'transcode') { $transcodeSessions++; } $i++; // Increment i every pass through the array } return $transcodeSessions; } return 0; } }
<?php include 'init.php'; include ROOT_DIR . '/assets/php/functions.php'; $image_url = $_GET['img']; $network = getNetwork(); $plexAddress = $network . ':' . $plex_port; $addressPosition = strpos($image_url, $plexAddress); if ($addressPosition !== false && $addressPosition == 0) { $image_src = $image_url . '?X-Plex-Token=' . $plexToken; header('Content-type: image/jpeg'); //header("Content-Length: " . filesize($image_src)); readfile($image_src); } else { echo "Bad Plex Image Url"; }
function makeNowPlaying() { $plexToken = 'pastPlextokenhere'; // You can get your Plex token using the getPlexToken() function. This will be automated once I find out how often the token has to be updated. $network = getNetwork(); $plexSessionXML = simplexml_load_file('http://10.0.1.3:32400/status/sessions'); if (count($plexSessionXML->Video) == 0) { makeRecenlyReleased(); } else { $i = 0; // Initiate and assign a value to i & t $t = 0; echo '<div class="col-md-10 col-sm-offset-1">'; foreach ($plexSessionXML->Video as $sessionInfo) { $t++; } foreach ($plexSessionXML->Video as $sessionInfo) { $mediaKey = $sessionInfo['key']; $playerTitle = $sessionInfo->Player['title']; $mediaXML = simplexml_load_file('http://10.0.1.3:32400' . $mediaKey); $type = $mediaXML->Video['type']; echo '<div class="thumbnail">'; $i++; // Increment i every pass through the array if ($type == "movie") { // Build information for a movie $movieArt = $mediaXML->Video['thumb']; echo '<img src="' . $network . ':32400' . $movieArt . '?X-Plex-Token=' . $plexToken . '" alt="thumbnail">'; echo '<div class="caption">'; $movieTitle = $mediaXML->Video['title']; //echo '<h2 class="exoextralight">'.$movieTitle.'</h2>'; if (strlen($mediaXML->Video['summary']) < 800) { $movieSummary = $mediaXML->Video['summary']; } else { $movieSummary = substr_replace($mediaXML->Video['summary'], '...', 800); } echo '<p class="exolight" style="margin-top:5px;">' . $movieSummary . '</p>'; } else { // Build information for a tv show $tvArt = $mediaXML->Video['grandparentThumb']; echo '<img src="' . $network . ':32400' . $tvArt . '?X-Plex-Token=' . $plexToken . '" alt="thumbnail">'; echo '<div class="caption">'; $showTitle = $mediaXML->Video['grandparentTitle']; $episodeTitle = $mediaXML->Video['title']; $episodeSummary = $mediaXML->Video['summary']; $episodeSeason = $mediaXML->Video['parentIndex']; $episodeNumber = $mediaXML->Video['index']; //echo '<h2 class="exoextralight">'.$showTitle.'</h2>'; echo '<h3 class="exoextralight" style="margin-top:5px;">Season ' . $episodeSeason . '</h3>'; echo '<h4 class="exoextralight" style="margin-top:5px;">E' . $episodeNumber . ' - ' . $episodeTitle . '</h4>'; echo '<p class="exolight">' . $episodeSummary . '</p>'; } // Action buttons if we ever want to do something //echo '<p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn btn-default">Action</a></p>'; echo "</div>"; echo "</div>"; // Should we make <hr>? Only if there is more than one video and it's not the last thumbnail created. if ($i > 0 && $i < $t) { echo '<hr>'; } else { // Do nothing } } echo '</div>'; } }
<?php Ini_Set('display_errors', true); include '../../init.php'; include 'functions.php'; global $plex_instances; foreach ($plex_instances as $instance) { $plex_port = $instance[1]; //echo " array value ".$instance[3]; $network = getNetwork($instance[3]); //echo " returned network ".$network; $plexSessionXML = simplexml_load_file($network . ':' . $plex_port . '/status/sessions'); $plexcheckfile1 = ROOT_DIR . '/assets/caches/plexcheckfile1.txt'; $plexcheckfile2 = ROOT_DIR . '/assets/caches/plexcheckfile2.txt'; $plexcheckfile1_md5 = md5_file($plexcheckfile1); $plexcheckfile2_md5 = md5_file($plexcheckfile2); $viewers = 0; // See if Plex Media Server is online and how many people are watching. if (!$plexSessionXML) { // If Plex Media Server is offline. $plexStatus = 'offline'; } else { // If Plex Media Server is online. $plexStatus = 'online'; // Count how many people are watching. if (count($plexSessionXML->Video) > 0) { $viewers = count($plexSessionXML->Video); } } // Build an array to hold the values $array = ['status' => $plexStatus, 'viewers' => $viewers];