Browse Source

Merge pull request #1 from causefx/v2-develop

V2 develop
Henry Whitaker 6 years ago
parent
commit
934850800a

+ 3 - 4
api/config/default.php

@@ -98,7 +98,7 @@ return array(
 	'rTorrentReverseSorting' => false,
 	'rTorrentCombine' => false,
 	'rTorrentDisableCertCheck' => false,
-	'homepageCalendarEnabled' => 'true',
+	'homepageCalendarEnabled' => false,
 	'homepageCalendarAuth' => '4',
 	'calendariCal' => '',
 	'homepagCustomHTMLoneEnabled' => false,
@@ -255,7 +255,7 @@ return array(
 	'unifiPassword' => '',
 	'unifiSiteName' => '',
 	'unifiCookie' => '',
-	'homepageUnifiEnabled' => 'false',
+	'homepageUnifiEnabled' => false,
 	'homepageUnifiAuth' => '1',
 	'homepageUnifiRefresh' => '600000',
 	'youtubeAPI' => '',
@@ -271,7 +271,6 @@ return array(
 	'homepageTautulliViewsAuth' => '1',
 	'homepageTautulliMiscAuth' => '1',
 	'homepageTautulliRefresh' => '60000',
-	'tautulliURL' => '',
 	'tautulliApikey' => '',
 	'tautulliLibraries' => true,
 	'tautulliTopMovies' => true,
@@ -280,7 +279,7 @@ return array(
 	'tautulliTopPlatforms' => true,
 	'tautulliPopularMovies' => true,
 	'tautulliPopularTV' => true,
-	'homepagePiholeEnabled' => 'false',
+	'homepagePiholeEnabled' => false,
 	'homepagePiholeAuth' => '1',
 	'homepagePiholeRefresh' => '10000',
 	'homepagePiholeCombine' => false,

+ 22 - 1
api/functions/homepage-connect-functions.php

@@ -2432,19 +2432,40 @@ function getTautulli()
 {
 	if ($GLOBALS['homepageTautulliEnabled'] && !empty($GLOBALS['tautulliURL']) && !empty($GLOBALS['tautulliApikey']) && qualifyRequest($GLOBALS['homepageTautulliAuth'])) {
 		$api = [];
-		$url = $GLOBALS['tautulliURL'] . '/api/v2?apikey=' . $GLOBALS['tautulliApikey'];
+		$url = qualifyURL($GLOBALS['tautulliURL']);
+		$url = $url . '/api/v2?apikey=' . $GLOBALS['tautulliApikey'];
 		try {
 			$homestatsUrl = $url . '&cmd=get_home_stats';
 			$homestats = Requests::get($homestatsUrl, [], []);
 			if ($homestats->success) {
 				$homestats = json_decode($homestats->body, true);
 				$api['homestats'] = $homestats['response'];
+				// Cache art & thumb for first result in each tautulli API result
+				$categories = [ 'top_movies', 'top_tv', 'popular_movies', 'popular_tv' ];
+				foreach($categories as $cat) {
+					$key = array_search($cat, array_column($api['homestats']['data'], 'stat_id'));
+					$img = $api['homestats']['data'][$key]['rows'][0];
+					cacheImage($GLOBALS['tautulliURL'] . 'pms_image_proxy?img=' . $img['art'], $img['title'] . '-art');
+					cacheImage($GLOBALS['tautulliURL'] . 'pms_image_proxy?img=' . $img['thumb'], $img['title'] . '-thumb');
+					$img['art'] = '/plugins/images/cache/' . $img['title'] . '-art.jpg';
+					$img['thumb'] = '/plugins/images/cache/' . $img['title'] . '-thumb.jpg';
+					$api['homestats']['data'][$key]['rows'][0] = $img;
+				}
+				// Cache the platform icon
+				$key = array_search('top_platforms', array_column($api['homestats']['data'], 'stat_id'));
+				$platform = $api['homestats']['data'][$key]['rows'][0]['platform_name'];
+				cacheImage($GLOBALS['tautulliURL'] . 'images/platforms/' . $platform . '.svg', 'tautulli-' . $platform, 'svg');
 			}
 			$libstatsUrl = $url . '&cmd=get_libraries';
 			$libstats = Requests::get($libstatsUrl, [], []);
 			if ($libstats->success) {
 				$libstats = json_decode($libstats->body, true);
 				$api['libstats'] = $libstats['response'];
+				$categories = [ 'movie.svg', 'show.svg', 'artist.png' ];
+				foreach($categories as $cat) {
+					$parts = explode('.', $cat);
+					cacheImage($GLOBALS['tautulliURL'] . 'images/libraries/' . $cat, 'tautulli-' . $parts[0], $parts[1]);
+				}
 			}
 			$api['options'] = [
 				'url' => $GLOBALS['tautulliURL'],

+ 11 - 4
api/functions/homepage-functions.php

@@ -2514,8 +2514,8 @@ function getHomepageList()
 				)
 			)
 		),
-    array(
-      'name' => 'Pi-hole',
+		array(
+			'name' => 'Pi-hole',
 			'enabled' => true,
 			'image' => 'plugins/images/tabs/pihole.png',
 			'category' => 'Monitor',
@@ -2555,7 +2555,7 @@ function getHomepageList()
 					),
 				),
 			)
-    ),
+		),
 		array(
 			'name' => 'Tautulli',
 			'enabled' => true,
@@ -2591,7 +2591,14 @@ function getHomepageList()
 						'name' => 'tautulliApikey',
 						'label' => 'API Key',
 						'value' => $GLOBALS['tautulliApikey']
-					)
+					),
+					array(
+						'type' => 'select',
+						'name' => 'homepageTautulliRefresh',
+						'label' => 'Refresh Seconds',
+						'value' => $GLOBALS['homepageTautulliRefresh'],
+						'options' => optionTime()
+					),
 				),
 				'Library Stats' => array(
 					array(

+ 7 - 7
api/functions/organizr-functions.php

@@ -2060,14 +2060,14 @@ function getImage()
 	}
 }
 
-function cacheImage($url, $name)
+function cacheImage($url, $name, $extension = 'jpg')
 {
-	$cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
-	if (!file_exists($cacheDirectory)) {
-		mkdir($cacheDirectory, 0777, true);
-	}
-	$cachefile = $cacheDirectory . $name . '.jpg';
-	@copy($url, $cachefile);
+    $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
+    if (!file_exists($cacheDirectory)) {
+        mkdir($cacheDirectory, 0777, true);
+    }
+    $cachefile = $cacheDirectory . $name . '.' . $extension;
+    @copy($url, $cachefile);
 }
 
 function downloader($array)

+ 57 - 21
js/functions.js

@@ -5688,7 +5688,7 @@ function buildPihole(array){
 		        <hr class="hidden-xs ml-2">
 		    </div>
 			<div class="clearfix"></div>
-		    <div class="piholeCards col-sm-12">
+		    <div class="piholeCards col-sm-12 my-3">
 			    `+buildPiholeItem(array)+`
 			</div>
 		</div>
@@ -6382,8 +6382,17 @@ function homepageCalendar(timeout){
 	timeouts['calendar-Homepage'] = setTimeout(function(){ homepageCalendar(timeout); }, timeout);
 }
 function buildTautulliItem(array){
+    console.log(array);
     var cards = `
     <style>
+    .homepage-tautulli-card {
+        height: 242px;
+    }
+
+    .library-card {
+        height: 137px;
+    }
+
     .homepage-tautulli-card .poster {
         max-width: 100%;
         max-height: 15em;
@@ -6402,9 +6411,38 @@ function buildTautulliItem(array){
         text-align: center;
     }
 
-    .homepage-tautulli-card ol.pl-2 li p {
-        font-weight: 700;
+    .library-card ol {
+        overflow: auto;
+    }
+
+    .homepage-tautulli-card ol.pl-2 li p,
+    .library-card ol li p {
+        font-weight: 400;
         font-size: 16px;
+        margin-bottom: 0;
+    }
+
+    .homepage-tautulli-card ol.pl-2 li,
+    .library-card ol li {
+        margin-top: 2px;
+    }
+
+    .library-card ol::-webkit-scrollbar-track {
+        -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
+        border-radius: 10px;
+        background-color: #7b7b7b2e;
+        margin: 0 30px;
+    }
+
+    .library-card ol::-webkit-scrollbar {
+        width: 12px;
+        background-color: #7b7b7b2e;
+    }
+
+    .library-card ol::-webkit-scrollbar-thumb {
+        border-radius: 10px;
+        -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
+        background-color: #555;
     }
 
     .one-line {
@@ -6426,7 +6464,7 @@ function buildTautulliItem(array){
         height: 100%;
         top: 0;
         left: 0;
-        filter: blur(7px) brightness(50%);
+        filter: blur(7px) brightness(30%);
     }
 
     .lib-stats-row::before {
@@ -6499,21 +6537,19 @@ function buildTautulliItem(array){
         var buildCard = function(type, data) {
             var card = `
             <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
-                <div class="card text-white mb-3 homepage-tautulli-card card-bg-colour">
-                    <div class="card-body">
-                        <div class="row" style="display: flex;">
-                            <div class="col-lg-4 col-md-4 col-sm-4 hidden-xs align-self-center">
-                                <img src="`+options['url']+`images/libraries/`+type;
-                                if(type == 'artist') {
-                                    card += `.png`;
-                                } else {
-                                    card += '.svg';
-                                }
+                <div class="card text-white mb-3 homepage-tautulli-card library-card card-bg-colour">
+                    <div class="card-body h-100">
+                        <div class="row h-100" style="display: flex;">
+                            <div class="col-lg-4 col-md-4 col-sm-4 hidden-xs align-self-center">`;
+                            if(type == 'artist') {
+                                card += `<img src="/plugins/images/cache/tautulli-`+type+`.jpg" class="lib-icon" alt="library icon">`;
+                            } else {
+                                card += `<img src="/plugins/images/cache/tautulli-`+type+`.svg" class="lib-icon" alt="library icon">`;
+                            }
             card += `
-                                " class="lib-icon" alt="library icon">
                             </div>
                             <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
-                                <ol class="pl-2">`;
+                                <ol class="h-100">`;
                                 data.forEach(e => {
                                     card += `<li class="w-100">
                                                 <p class="one-line d-inline">`+e['section_name']+`</p>`;
@@ -6557,7 +6593,7 @@ function buildTautulliItem(array){
                         if(stat !== 'top_users' && stat !== 'top_platforms') {
                             card += `
                             <div class="bg-img-cont">
-                                <img class="bg-img" src="`+options['url']+`pms_image_proxy?img=`+e['rows'][0]['art']+`" alt="background art">
+                                <img class="bg-img" src="`+e['rows'][0]['art']+`" alt="background art">
                             </div>
                             `;
                         }
@@ -6568,9 +6604,9 @@ function buildTautulliItem(array){
                                 if(stat == 'top_users') {
                                     card += `<img src="`+e['rows'][0]['user_thumb']+`" class="poster avatar" alt="user avatar">`;
                                 } else if(stat == 'top_platforms') {
-                                    card += `<img src="`+options['url']+`images/platforms/`+e['rows'][0]['platform_name']+`.svg" class="poster" alt="platform icon">`;
+                                    card += `<img src="/plugins/images/cache/tautulli-`+e['rows'][0]['platform_name']+`.svg" class="poster" alt="platform icon">`;
                                 } else {
-                                    card += `<img src="`+options['url']+`pms_image_proxy?img=`+e['rows'][0]['thumb']+`" class="poster" alt="movie poster">`;
+                                    card += `<img src="`+e['rows'][0]['thumb']+`" class="poster" alt="movie poster">`;
                                 }
                 card += `
                                 </div>
@@ -6618,14 +6654,14 @@ function buildTautulliItem(array){
 function buildTautulli(array){
     if(array === false){ return ''; }
     return (array) ? `
-    <div id="allPihole">
+    <div id="allTautulli">
 		<div class="el-element-overlay row">
 		    <div class="col-md-12">
 		        <h4 class="pull-left homepage-element-title"><span lang="en">Tautulli</span></h4>
 		        <hr class="hidden-xs ml-2">
 		    </div>
 			<div class="clearfix"></div>
-            <div class="piholeCards col-sm-12">
+            <div class="tautulliCards col-sm-12 my-3">
                 `+buildTautulliItem(array)+`
 			</div>
 		</div>