causefx vor 8 Jahren
Ursprung
Commit
9c477813e4

+ 2 - 0
api/config/default.php

@@ -114,6 +114,8 @@ return array(
     'homepagePlexStreamsAuth' => '1',
     'homepagePlexRecent' => false,
     'homepagePlexRecentAuth' => '1',
+	'homepagePlexPlaylist' => false,
+    'homepagePlexPlaylistAuth' => '1',
     'homepageEmbyStreams' => false,
     'homepageEmbyStreamsAuth' => '1',
     'homepageEmbyRecent' => false,

+ 46 - 0
api/functions/homepage-connect-functions.php

@@ -11,6 +11,9 @@ function homepageConnect($array){
         case 'getPlexMetadata':
             return plexConnect('metadata',$array['data']['key']);
             break;
+        case 'getPlexPlaylists':
+            return getPlexPlaylists();
+            break;
         case 'getEmbyStreams':
             return embyConnect('streams');
             break;
@@ -416,6 +419,9 @@ function plexConnect($action,$key=null){
                 break;
             case 'metadata':
                 $url = $url."/library/metadata/".$key."?X-Plex-Token=".$GLOBALS['plexToken'];
+                break;
+			case 'playlists':
+                $url = $url."/playlists?X-Plex-Token=".$GLOBALS['plexToken'];
                 break;
             default:
                 # code...
@@ -443,6 +449,46 @@ function plexConnect($action,$key=null){
     }
     return false;
 }
+function getPlexPlaylists(){
+    if($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']) && qualifyRequest($GLOBALS['homepagePlexPlaylistAuth']) && $GLOBALS['homepagePlexPlaylist'])){
+        $url = qualifyURL($GLOBALS['plexURL']);
+        $url = $url."/playlists?X-Plex-Token=".$GLOBALS['plexToken'];
+        try{
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            libxml_use_internal_errors(true);
+            if($response->success){
+                $items = array();
+                $plex = simplexml_load_string($response->body);
+                foreach($plex AS $child) {
+    				if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
+                        $playlistTitleClean = preg_replace("/(\W)+/", "", (string)$child['title']);
+                        $playlistURL = qualifyURL($GLOBALS['plexURL']);
+                        $playlistURL = $playlistURL.$child['key']."?X-Plex-Token=".$GLOBALS['plexToken'];
+                        $options = (localURL($url)) ? array('verify' => false ) : array();
+                        $playlistResponse = Requests::get($playlistURL, array(), $options);
+						if($playlistResponse->success){
+			                $playlistResponse = simplexml_load_string($playlistResponse->body);
+                            $items[$playlistTitleClean]['title'] = (string)$child['title'];
+							foreach($playlistResponse->Video AS $playlistItem){
+								$items[$playlistTitleClean][] = resolvePlexItem($playlistItem);
+							}
+						}
+
+                    }
+                }
+                $api['content'] = $items;
+                $api['plexID'] = $GLOBALS['plexID'];
+                $api['showNames'] = true;
+                $api['group'] = '1';
+                return $api;
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'Plex Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
+    }
+    return false;
+}
 function embyConnect($action,$key=null,$skip=false){
     if($GLOBALS['homepageEmbyEnabled'] && !empty($GLOBALS['embyURL']) && !empty($GLOBALS['embyToken']) && qualifyRequest($GLOBALS['homepageEmbyAuth'])){
         $url = qualifyURL($GLOBALS['embyURL']);

+ 24 - 1
api/functions/homepage-functions.php

@@ -135,7 +135,15 @@ function buildHomepageItem($homepageItem){
 			}
 			break;
 		case 'homepageOrderplexplaylist':
-
+			if($GLOBALS['homepagePlexPlaylist']){
+				$item .= '
+				<script>
+				// Plex Playlist
+				homepagePlaylist("plex");
+				// End Plex Playlist
+				</script>
+				';
+			}
 			break;
 		case 'homepageOrderembynowplaying':
 			if($GLOBALS['homepageEmbyStreams']){
@@ -483,6 +491,21 @@ function getHomepageList(){
 						'value' => $GLOBALS['homepageRecentRefresh'],
 						'options' => $time
 					),
+                ),
+				'Playlists' => array(
+					array(
+            			'type' => 'switch',
+            			'name' => 'homepagePlexPlaylist',
+            			'label' => 'Enable',
+            			'value' => $GLOBALS['homepagePlexPlaylist']
+            		),
+                    array(
+    					'type' => 'select',
+    					'name' => 'homepagePlexPlaylistAuth',
+                        'label' => 'Minimum Authorization',
+    					'value' => $GLOBALS['homepagePlexPlaylistAuth'],
+    					'options' => $groups
+    				),
                 ),
                 'Misc Options' => array(
 					array(

+ 11 - 0
js/custom.js

@@ -1452,6 +1452,17 @@ $(document).on("click", ".recent-filter li>a", function () {
         $('.'+type+'-recent').find('.recent-item:not(.'+ filter + ')').parent().addClass('hidden');
     }
 
+});
+//playlist filter
+$(document).on("click", ".playlist-filter li>a", function () {
+    var filter = $(this).attr('data-filter');
+    var title = decodeURI($(this).attr('data-title'));
+    var type = $(this).attr('server-filter'); //plex or emby
+    $('.'+type+'-playlistTitle').html(title);
+    $('.'+type+'-playlist').addClass('hidden');
+    $('.'+filter+'-playlist').removeClass('hidden');
+
+
 });
 // refresh cache image
 $(document).on("click", ".refreshImage", function(e) {

+ 153 - 0
js/functions.js

@@ -2063,6 +2063,31 @@ function buildRecentItem(array, type, extra=null){
 			`;
 		}
 
+	});
+	return items;
+}
+function buildPlaylistItem(array, type, extra=null){
+	var items = '';
+	$.each(array, function(i,v) {
+		if(i !== 'title'){
+			if(extra == null){
+				items += `
+				<div class="item lazyload recent-poster metadata-get mouse" data-source="`+type+`" data-key="`+v.metadataKey+`" data-uid="`+v.uid+`" data-src="`+v.imageURL+`">
+					<span class="elip recent-title">`+v.title+`</span>
+					<div id="`+v.uid+`-metadata-div" class="white-popup mfp-with-anim mfp-hide">
+				        <div class="col-md-8 col-md-offset-2 `+v.uid+`-metadata-info"></div>
+				    </div>
+				</div>
+				`;
+			}else{
+				items += `
+				<a class="inline-popups `+v.uid+` hidden" href="#`+v.uid+`-metadata-div" data-effect="mfp-zoom-out"></a>
+				`;
+			}
+		}
+
+
+
 	});
 	return items;
 }
@@ -2124,6 +2149,63 @@ function buildRecent(array, type){
     </div>
 	` : '';
 }
+function buildPlaylist(array, type){
+	var playlist = (typeof array.content !== 'undefined') ? true : false;
+	var dropdown = '';
+	var first = '';
+	var hidden = '';
+	var count = 0;
+	var items = '';
+	if(playlist){
+		$.each(array.content, function(i,v) {
+
+
+
+			count ++;
+			first = (count == 1) ? v.title : first;
+			hidden = (count == 1) ? '' : ' hidden';
+			dropdown += `<li><a data-filter="`+i+`" server-filter="`+type+`" data-title="`+encodeURI(v.title)+`" href="javascript:void(0);">`+v.title+`</a></li>`;
+
+			items += `
+			<div class="owl-carousel owl-theme playlist-items `+type+`-playlist `+hidden+` `+i+`-playlist">
+				`+buildPlaylistItem(v, type)+`
+			</div>
+			`+buildPlaylistItem(v, type, true)+`
+			`;
+
+
+
+
+		});
+		var builtDropdown = `
+		<button aria-expanded="false" data-toggle="dropdown" class="btn btn-info dropdown-toggle waves-effect waves-light" type="button">
+			<i class="fa fa-filter m-r-5"></i><span lang="en">Choose Playlist</span>
+		</button>
+		<ul role="menu" class="dropdown-menu playlist-filter">
+			`+dropdown+`
+		</ul>
+		`;
+	}
+
+	return (playlist) ? `
+	<div id="`+type+`Playlist" class="row">
+        <div class="col-lg-12">
+            <div class="panel panel-default">
+                <div class="panel-heading bg-info p-t-10 p-b-10">
+					<span class="pull-left m-t-5"><img class="lazyload homepageImageTitle" data-src="plugins/images/tabs/`+type+`.png"> &nbsp; <span class="`+type+`-playlistTitle">`+first+`</span></span>
+					<div class="btn-group pull-right">
+							`+builtDropdown+`
+	                </div>
+					<div class="clearfix"></div>
+				</div>
+                <div class="panel-wrapper p-b-0 collapse in">
+                    `+items+`
+                </div>
+            </div>
+        </div>
+    </div>
+	` : '';
+}
 function buildDownloaderItem(array, source, type='none'){
 	var items = '';
 	switch (source) {
@@ -2692,6 +2774,77 @@ function homepageRecent(type, timeout=30000){
 		homepageRecent(type, timeout);
 	}, timeout)
 }
+function homepagePlaylist(type, timeout=30000){
+	//if(isHidden()){ return; }
+	switch (type) {
+		case 'plex':
+			var action = 'getPlexPlaylists';
+			break;
+		default:
+
+	}
+	ajaxloader(".content-wrap","in");
+	organizrAPI('POST','api/?v1/homepage/connect',{action:action}).success(function(data) {
+		var response = JSON.parse(data);
+		document.getElementById('homepageOrder'+type+'playlist').innerHTML = '';
+		$('#homepageOrder'+type+'playlist').html(buildPlaylist(response.data, type));
+		$('.playlist-items').owlCarousel({
+    	    margin:40,
+    	    nav:false,
+    		autoplay:false,
+            dots:false,
+    	    responsive:{
+    	        0:{
+    	            items:2
+    	        },
+    	        500:{
+    	            items:3
+    	        },
+    	        650:{
+    	            items:4
+    	        },
+    	        800:{
+    	            items:5
+    	        },
+    	        950:{
+    	            items:6
+    	        },
+    	        1100:{
+    	            items:7
+    	        },
+    	        1250:{
+    	            items:8
+    	        },
+    	        1400:{
+    	            items:9
+    	        },
+    	        1550:{
+    	            items:10
+    	        },
+    	        1700:{
+    	            items:11
+    	        },
+    	        1850:{
+    	            items:12
+    	        },
+    	        2000:{
+    	            items:13
+    	        },
+    	        2150:{
+    	            items:14
+    	        },
+    	        2300:{
+    	            items:15
+    	        },
+    	        2450:{
+    	            items:16
+    	        }
+    	    }
+    	})
+	}).fail(function(xhr) {
+		console.error("Organizr Function: API Connection Failed");
+	});
+}
 function homepageCalendar(timeout=30000){
 	//if(isHidden()){ return; }
 	ajaxloader(".content-wrap","in");