Browse Source

Emby Fixes and Plex Search

causefx 9 years ago
parent
commit
23144f2128
11 changed files with 140 additions and 18 deletions
  1. 3 0
      ajax.php
  2. 69 8
      functions.php
  3. 25 3
      homepage.php
  4. 3 1
      lang/de.ini
  5. 3 1
      lang/en.ini
  6. 3 1
      lang/es.ini
  7. 3 1
      lang/fr.ini
  8. 3 1
      lang/it.ini
  9. 3 1
      lang/nl.ini
  10. 3 1
      lang/pl.ini
  11. 22 0
      settings.php

+ 3 - 0
ajax.php

@@ -75,6 +75,9 @@ switch ($_SERVER['REQUEST_METHOD']) {
 		// Check if the user is an admin and is allowed to commit values
 		qualifyUser('admin', true);
 		switch ($action) {
+   case 'search-plex':
+    $response = searchPlex($_POST['searchtitle']);
+    break;
    case 'check-url':
 				sendResult(frameTest($_POST['checkurl']), "flask", $_POST['checkurl'], "IFRAME_CAN_BE_FRAMED", "IFRAME_CANNOT_BE_FRAMED");
 				break;

+ 69 - 8
functions.php

@@ -459,7 +459,7 @@ function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showName
 	
 	// Get Item Details
 	$itemDetails = json_decode(file_get_contents($address.'/Items?Ids='.$item['Id'].'&api_key='.$token),true)['Items'][0];
-	
+	$URL = "http://app.emby.media/itemdetails.html?id=".$itemDetails['Id'];
 	switch ($itemDetails['Type']) {
     case 'Episode':
         $title = (isset($itemDetails['SeriesName'])?$itemDetails['SeriesName']:"");
@@ -473,9 +473,9 @@ function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showName
         }else{
             $height = 281;
             $width = 500;
-            $imageId = $itemDetails['ParentThumbItemId'];
+            $imageId = isset($itemDetails['ParentThumbItemId']) ?	$itemDetails['ParentThumbItemId'] : (isset($itemDetails['ParentBackdropItemId']) ? $itemDetails['ParentBackdropItemId'] : false);
             $imageType = isset($itemDetails['ParentThumbItemId']) ?	"Thumb" : (isset($itemDetails['ParentBackdropItemId']) ? "Backdrop" : false);
-            $key = $itemDetails['ParentThumbItemId'] . "-np";
+            $key = (isset($itemDetails['ParentThumbItemId']) ? $itemDetails['ParentThumbItemId']."-np" : "none-np");
             $elapsed = $moreInfo['PlayState']['PositionTicks'];
             $duration = $moreInfo['NowPlayingItem']['RunTimeTicks'];
             $watched = floor(($elapsed / $duration) * 100);
@@ -620,9 +620,9 @@ if (file_exists('images/cache/'.$key.'.jpg')){ $image_url = 'images/cache/'.$key
 	// Assemble Item And Cache Into Array     
 if($nowPlaying){
     //prettyPrint($itemDetails);
-    return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$address.'" target="_blank"><img style="width: 500px; display:inherit;" src="'.$image_url.'" alt="'.$itemDetails['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: 0%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
+    return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a href="'.$URL.'" target="_blank"><img style="width: 500px; display:inherit;" src="'.$image_url.'" alt="'.$itemDetails['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: 0%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
     }else{
- return '<div class="item-'.$itemDetails['Type'].'"><a href="'.$address.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
+ return '<div class="item-'.$itemDetails['Type'].'"><a href="'.$URL.'" target="_blank"><img alt="'.$itemDetails['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
 }
 }
 
@@ -934,7 +934,7 @@ function getEmbyRecent($array) {
     }
 
     // Get the latest Items
-    $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&&Limit=100&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
+    $latest = json_decode(file_get_contents($address.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit='.EMBYRECENTITEMS.'&api_key='.EMBYTOKEN.($showPlayed?'':'&IsPlayed=false')),true);
 	
     // For Each Item In Category
     $items = array();
@@ -962,7 +962,7 @@ function getPlexRecent($array){
 			 $header = translate('RECENT_CONTENT');
 	
 	// Perform Requests
-    $api = @curl_get($address."/library/recentlyAdded?limit=100&X-Plex-Token=".PLEXTOKEN);
+    $api = @curl_get($address."/library/recentlyAdded?limit=".PLEXRECENTITEMS."&X-Plex-Token=".PLEXTOKEN);
     $api = simplexml_load_string($api);
     $getServer = simplexml_load_string(@curl_get($address."/?X-Plex-Token=".PLEXTOKEN));
 	if (!$getServer) { return 'Could not load!'; }
@@ -984,7 +984,10 @@ function getPlexRecent($array){
 // Get Image From Emby
 function getEmbyImage() {
 	$embyAddress = qualifyURL(EMBYURL);
-	
+    if (!file_exists('images/cache')) {
+        mkdir('images/cache', 0777, true);
+    }
+
 	$itemId = $_GET['img'];
  $key = $_GET['key'];
 	$itemType = $_GET['type'];
@@ -2986,5 +2989,63 @@ function embyArray($array, $type) {
     }
 }
 
+// Get Now Playing Streams From Plex
+function searchPlex($query){
+    $address = qualifyURL(PLEXURL);
+
+    // Perform API requests
+    $api = @curl_get($address."/search?query=".rawurlencode($query)."&X-Plex-Token=".PLEXTOKEN);
+    $api = simplexml_load_string($api);
+    $pre = "<table  class=\"table table-hover table-stripped\"><thead><tr><th>Cover</th><th>Title</th><th>Genre</th><th>Year</th><th>Type</th><th>Added</th></tr></thead><tbody>";
+    $items = "";
+    $albums = $movies = $shows = 0;
+    
+    $style = 'style="vertical-align: middle"';
+    foreach($api AS $child) {
+        if($child['type'] != "artist" && $child['type'] != "episode" && isset($child['librarySectionID'])){
+            $time = (string)$child['addedAt'];
+            $time = new DateTime("@$time");
+            $results = array(
+                "title" => (string)$child['title'],
+                "image" => (string)$child['thumb'],
+                "type" => (string)ucwords($child['type']),
+                "year" => (string)$child['year'],
+                "key" => (string)$child['key'],
+                "genre" => (string)$child->Genre['tag'],
+                "added" => $time->format('Y-m-d'),
+            );
+            switch ($child['type']){
+                case "album":
+                    $push = array(
+                        "title" => (string)$child['parentTitle']." - ".(string)$child['title'],
+                    );  
+                    $results = array_replace($results,$push);
+                    $albums++;
+                    break;
+                case "movie":
+                    $movies++;
+                    break;
+                case "show":
+                    $shows++;
+                    break;
+            }
+            $items .= '<tr>
+            <th scope="row"><img src="ajax.php?a=plex-image&img='.$results['image'].'&height=100&width=50&key='.$results['key'].'"></th>
+            <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['title'].'</td>
+            <td class="col-xs-3 nzbtable nzbtable-row"'.$style.'>'.$results['genre'].'</td>
+            <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['year'].'</td>
+            <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['type'].'</td>
+            <td class="col-xs-2 nzbtable nzbtable-row"'.$style.'>'.$results['added'].'</td>
+            </tr>';
+        }
+    }
+    $totals = '<div style="margin: 10px;" class="sort-todo pull-right">
+              Movies <span class="badge green-bg">'.$movies.'</span>
+              Shows <span class="badge blue-bg">'.$shows.'</span>
+              Albums <span class="badge gray-bg">'.$albums.'</span>
+            </div>';
+    return (!empty($items) ? $totals.$pre.$items."</div></table>" : "<h2 class='text-center'>No Results for $query</h2>" );
+}
+
 // Always run this
 dependCheck();

+ 25 - 3
homepage.php

@@ -397,6 +397,25 @@ endif; ?>
                     </div>
                 </div>
                 <?php } ?>
+                <?php if((PLEXSEARCH == "true" && qualifyUser(PLEXHOMEAUTH))) { ?>
+                <div id="searchPlexRow" class="row">
+                    <div class="col-lg-12">
+                        <div class="content-box box-shadow big-box todo-list">                        
+                            <form id="plexSearchForm" onsubmit="return false;" autocomplete="off">
+                                <div class="">
+                                    <div class="input-group">
+                                        <div class="input-group-addon"><i class="fa fa-search gray"></i></div>
+                                        <input type="text" autocomplete="off" name="search-title" class="form-control name-of-todo" placeholder="Media Search">
+                                        <button style="display:none" id="plexSearchForm_submit" class="btn btn-primary waves"></button>
+                                    </div>
+                                </div>
+                            </form>
+                            <div id="resultshere" class="table-responsive"></div>
+                        </div>
+                    </div>
+                </div>
+                <?php } ?>
+                
                 <?php if((NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)) || (SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH))) { ?>
                 <div id="downloadClientRow" class="row">
                     <div class="col-xs-12 col-md-12">
@@ -538,6 +557,12 @@ endif; ?>
         }
 		
         $( document ).ready(function() {
+            $('#plexSearchForm_submit').on('click', function () {
+                ajax_request('POST', 'search-plex', {
+                    searchtitle: $('#plexSearchForm [name=search-title]').val(),
+                }).done(function(data){ $('#resultshere').html(data); console.log("done"); });;
+
+            });
             $('.repeat-btn').click(function(){
                 var refreshBox = $(this).closest('div.content-box');
                 $("<div class='refresh-preloader'><div class='la-timer la-dark'><div></div></div></div>").appendTo(refreshBox).fadeIn(300);
@@ -549,11 +574,8 @@ endif; ?>
                 },1500);
             });
             $(document).on('click', '.w-refresh', function(){
-                //Your code
                 var id = $(this).attr("link");
                 $("div[np^='"+id+"']").toggle();
-                    console.log(id);
-                    //console.log(moreInfo);
             });
      
             $('.recentItems').slick({

+ 3 - 1
lang/de.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 3 - 1
lang/en.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 3 - 1
lang/es.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 3 - 1
lang/fr.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 3 - 1
lang/it.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 3 - 1
lang/nl.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 3 - 1
lang/pl.ini

@@ -256,4 +256,6 @@ NOTICE_COLOR = "Notice Color"
 NOTICE_TITLE = "Notice Title"
 NOTICE_MESSAGE = "Notice Message"
 SHOW_NAMES = "Show Names"
-NOTICE_LAYOUT = "Notice Layout"
+NOTICE_LAYOUT = "Notice Layout"
+RECENT_ITEMS_LIMIT = "Recent Items Limit"
+ALLOW_SEARCH = "Allow Search"

+ 22 - 0
settings.php

@@ -695,11 +695,25 @@ echo buildSettings(
 						'pattern' => '[a-zA-Z0-9]{20}',
 						'value' => PLEXTOKEN,
 					),
+     array(
+						'type' => 'text',
+						'placeholder' => "",
+						'labelTranslate' => 'RECENT_ITEMS_LIMIT',
+						'name' => 'plexRecentItems',
+						'pattern' => '[0-9]+',
+						'value' => PLEXRECENTITEMS,
+					),
 					array(
 						'type' => 'custom',
 						'html' => '<a href="https://support.plex.tv/hc/en-us/articles/204059436-Finding-an-authentication-token-X-Plex-Token">Plex Token Wiki Article</a>',
 					),
 					array(
+      array(
+							'type' => 'checkbox',
+							'labelTranslate' => 'ALLOW_SEARCH',
+							'name' => 'plexSearch',
+							'value' => PLEXSEARCH,
+						),
 						array(
 							'type' => 'checkbox',
 							'labelTranslate' => 'RECENT_MOVIES',
@@ -762,6 +776,14 @@ echo buildSettings(
 						'pattern' => '[a-zA-Z0-9]{32}',
 						'value' => EMBYTOKEN,
 					),
+     array(
+						'type' => 'text',
+						'placeholder' => "",
+						'labelTranslate' => 'RECENT_ITEMS_LIMIT',
+						'name' => 'embyRecentItems',
+						'pattern' => '[0-9]+',
+						'value' => EMBYRECENTITEMS,
+					),
 					array(
 						array(
 							'type' => 'checkbox',