function makeNowPlaying() { global $plex_instances; foreach ($plex_instances as $instance) { $plex_port = $instance[1]; $network = getNetwork($instance[3]); $clientIP = get_client_ip(); $plexSessionXML = simplexml_load_file($network . ':' . $plex_port . '/status/sessions'); if (!$plexSessionXML) { makeRecenlyViewed(); } elseif (count($plexSessionXML->Video) == 0) { makeRecenlyReleased(); } else { $i = 0; // Initiate and assign a value to i & t $t = 0; // T is the total amount of sessions echo '<div class="col-md-10 col-sm-offset-1">'; //echo '<div class="col-md-12">'; foreach ($plexSessionXML->Video as $sessionInfo) { $t++; } foreach ($plexSessionXML->Video as $sessionInfo) { $mediaKey = $sessionInfo['key']; $playerTitle = $sessionInfo->Player['title']; $mediaXML = simplexml_load_file($network . ':' . $plex_port . $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']; $movieTitle = $mediaXML->Video['title']; $duration = $plexSessionXML->Video[$i - 1]['duration']; $viewOffset = $plexSessionXML->Video[$i - 1]['viewOffset']; $progress = sprintf('%.0f', $viewOffset / $duration * 100); $user = $plexSessionXML->Video[$i - 1]->User['title']; $device = $plexSessionXML->Video[$i - 1]->Player['title']; $state = $plexSessionXML->Video[$i - 1]->Player['state']; // Truncate movie summary if it's more than 50 words if (countWords($mediaXML->Video['summary']) < 51) { $movieSummary = $mediaXML->Video['summary']; } else { $movieSummary = limitWords($mediaXML->Video['summary'], 50); // Limit to 50 words $movieSummary .= "..."; // Add ellipsis } echo '<img src="plex.php?img=' . urlencode($network . ':' . $plex_port . $movieArt) . '" alt="' . $movieTitle . '">'; // Make now playing progress bar //echo 'div id="now-playing-progress-bar">'; echo '<div class="progress now-playing-progress-bar">'; echo '<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">'; echo '</div>'; echo '</div>'; echo '<div class="caption">'; //echo '<h2 class="exoextralight">'.$movieTitle.'</h2>'; echo '<p class="exolight" style="margin-top:5px;">' . $movieSummary . '</p>'; if ($state == "playing") { // Show the playing icon echo '<span class="glyphicon glyphicon-play"></span>'; } else { echo '<span class="glyphicon glyphicon-pause"></span>'; } if ($user == "") { echo '<p class="exolight">' . $device . '</p>'; } else { echo '<p class="exolight">' . $user . '</p>'; } } else { // Build information for a tv show $tvArt = $mediaXML->Video['grandparentThumb']; $showTitle = $mediaXML->Video['grandparentTitle']; $episodeTitle = $mediaXML->Video['title']; $episodeSummary = $mediaXML->Video['summary']; $episodeSeason = $mediaXML->Video['parentIndex']; $episodeNumber = $mediaXML->Video['index']; $duration = $plexSessionXML->Video[$i - 1]['duration']; $viewOffset = $plexSessionXML->Video[$i - 1]['viewOffset']; $progress = sprintf('%.0f', $viewOffset / $duration * 100); $user = $plexSessionXML->Video[$i - 1]->User['title']; $device = $plexSessionXML->Video[$i - 1]->Player['title']; $state = $plexSessionXML->Video[$i - 1]->Player['state']; //echo '<div class="img-overlay">'; echo '<img src="plex.php?img=' . urlencode($network . ':' . $plex_port . $tvArt) . '" alt="' . $showTitle . '">'; // Make now playing progress bar //echo 'div id="now-playing-progress-bar">'; echo '<div class="progress now-playing-progress-bar">'; echo '<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">'; echo '</div>'; echo '</div>'; //echo '</div>'; // Make description below thumbnail echo '<div class="caption">'; //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>'; // Truncate episode summary if it's more than 50 words if (countWords($mediaXML->Video['summary']) < 51) { $episodeSummary = $mediaXML->Video['summary']; } else { $episodeSummary = limitWords($mediaXML->Video['summary'], 50); // Limit to 50 words $episodeSummary .= "..."; // Add ellipsis } echo '<p class="exolight">' . $episodeSummary . '</p>'; if ($state == "playing") { // Show the playing icon echo '<span class="glyphicon glyphicon-play"></span>'; } else { echo '<span class="glyphicon glyphicon-pause"></span>'; } if ($user == "") { echo '<p class="exolight">' . $device . '</p>'; } else { echo '<p class="exolight">' . $user . '</p>'; } } // Action buttons if we ever want to do something with them. //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>'; } } }
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>'; } }