| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667 |
- <?php
- function homepageConnect($array){
- switch ($array['data']['action']) {
- case 'getPlexStreams':
- return plexConnect('streams');
- break;
- case 'getPlexRecent':
- return plexConnect('recent');
- break;
- case 'getPlexMetadata':
- return plexConnect('metadata',$array['data']['key']);
- break;
- case 'getEmbyStreams':
- return embyConnect('streams');
- break;
- case 'getEmbyRecent':
- return embyConnect('recent');
- break;
- case 'getEmbyMetadata':
- return embyConnect('metadata',$array['data']['key'],true);
- break;
- case 'getSabnzbd':
- return sabnzbdConnect();
- break;
- case 'getNzbget':
- return nzbgetConnect();
- break;
- case 'getTransmission':
- return transmissionConnect();
- break;
- case 'getqBittorrent':
- return qBittorrentConnect();
- break;
- default:
- # code...
- break;
- }
- }
- function streamType($value){
- if($value == "transcode" || $value == "Transcode"){
- return "Transcode";
- }elseif($value == "copy" || $value == "DirectStream"){
- return "Direct Stream";
- }elseif($value == "directplay" || $value == "DirectPlay"){
- return "Direct Play";
- }else{
- return "Direct Play";
- }
- }
- function resolveEmbyItem($itemDetails) {
- // Grab Each item info from Emby (extra call)
- $id = isset($itemDetails['NowPlayingItem']['Id']) ? $itemDetails['NowPlayingItem']['Id'] : $itemDetails['Id'];
- $url = qualifyURL($GLOBALS['embyURL']);
- $url = $url.'/Items?Ids='.$id.'&api_key='.$GLOBALS['embyToken'].'&Fields=Overview,People,Genres,CriticRating,Studios,Taglines';
- try{
- $options = (localURL($url)) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->success){
- $item = json_decode($response->body,true)['Items'][0];
- }
- }catch( Requests_Exception $e ) {
- return false;
- };
- // Static Height & Width
- $height = 300;
- $width = 200;
- $nowPlayingHeight = 675;
- $nowPlayingWidth = 1200;
- $actorHeight = 450;
- $actorWidth = 300;
- $widthOverride = 100;
- // Cache Directories
- $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
- $cacheDirectoryWeb = 'plugins/images/cache/';
- // Types
- $embyItem['array-item'] = $item;
- $embyItem['array-itemdetails'] = $itemDetails;
- switch (@$item['Type']) {
- case 'Series':
- $embyItem['type'] = 'tv';
- $embyItem['title'] = $item['Name'];
- $embyItem['summary'] = '';
- $embyItem['ratingKey'] = $item['Id'];
- $embyItem['thumb'] = $item['Id'];
- $embyItem['key'] = $item['Id'] . "-list";
- $embyItem['nowPlayingThumb'] = $item['Id'];
- $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
- $embyItem['metadataKey'] = $item['Id'];
- $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['BackdropImageTags'][0]) ? 'Backdrop' : '');
- break;
- case 'Episode':
- $embyItem['type'] = 'tv';
- $embyItem['title'] = $item['SeriesName'];
- $embyItem['summary'] = '';
- $embyItem['ratingKey'] = $item['Id'];
- $embyItem['thumb'] = (isset($item['SeriesId'])?$item['SeriesId']:$item['Id']);
- $embyItem['key'] = (isset($item['SeriesId'])?$item['SeriesId']:$item['Id']) . "-list";
- $embyItem['nowPlayingThumb'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'] : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'] : false);
- $embyItem['nowPlayingKey'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'].'-np' : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'].'-np' : false);
- $embyItem['metadataKey'] = $item['Id'];
- $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['ParentBackdropImageTags'][0]) ? 'Backdrop' : '');
- $embyItem['nowPlayingTitle'] = @$item['SeriesName'].' - '.@$item['Name'];
- $embyItem['nowPlayingBottom'] = 'S'.@$item['ParentIndexNumber'].' · E'.@$item['IndexNumber'];
- break;
- case 'MusicAlbum':
- case 'Audio':
- $embyItem['type'] = 'music';
- $embyItem['title'] = $item['Name'];
- $embyItem['summary'] = '';
- $embyItem['ratingKey'] = $item['Id'];
- $embyItem['thumb'] = $item['Id'];
- $embyItem['key'] = $item['Id'] . "-list";
- $embyItem['nowPlayingThumb'] = (isset($item['AlbumId']) ? $item['AlbumId'] : @$item['ParentBackdropItemId']);
- $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
- $embyItem['metadataKey'] = isset($item['AlbumId']) ? $item['AlbumId'] : $item['Id'];
- $embyItem['nowPlayingImageType'] = (isset($item['ParentBackdropItemId']) ? "Primary" : "Backdrop");
- $embyItem['nowPlayingTitle'] = @$item['AlbumArtist'].' - '.@$item['Name'];
- $embyItem['nowPlayingBottom'] = @$item['Album'];
- break;
- case 'Movie':
- $embyItem['type'] = 'movie';
- $embyItem['title'] = $item['Name'];
- $embyItem['summary'] = '';
- $embyItem['ratingKey'] = $item['Id'];
- $embyItem['thumb'] = $item['Id'];
- $embyItem['key'] = $item['Id'] . "-list";
- $embyItem['nowPlayingThumb'] = $item['Id'];
- $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
- $embyItem['metadataKey'] = $item['Id'];
- $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
- $embyItem['nowPlayingTitle'] = @$item['Name'];
- $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
- break;
- case 'Video':
- $embyItem['type'] = 'video';
- $embyItem['title'] = $item['Name'];
- $embyItem['summary'] = '';
- $embyItem['ratingKey'] = $item['Id'];
- $embyItem['thumb'] = $item['Id'];
- $embyItem['key'] = $item['Id'] . "-list";
- $embyItem['nowPlayingThumb'] = $item['Id'];
- $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
- $embyItem['metadataKey'] = $item['Id'];
- $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
- $embyItem['nowPlayingTitle'] = @$item['Name'];
- $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
- break;
- default:
- return false;
- }
- $embyItem['uid'] = $item['Id'];
- $embyItem['imageType'] = (isset($item['ImageTags']['Primary']) ? "Primary" : false);
- $embyItem['elapsed'] = isset($itemDetails['PlayState']['PositionTicks']) && $itemDetails['PlayState']['PositionTicks'] !== '0' ? (int)$itemDetails['PlayState']['PositionTicks'] : null;
- $embyItem['duration'] = isset($itemDetails['NowPlayingItem']['RunTimeTicks']) ? (int)$itemDetails['NowPlayingItem']['RunTimeTicks'] : (int)$item['RunTimeTicks'];
- $embyItem['watched'] = ($embyItem['elapsed'] && $embyItem['duration'] ? floor(($embyItem['elapsed'] / $embyItem['duration']) * 100) : 0);
- $embyItem['transcoded'] = isset($itemDetails['TranscodingInfo']['CompletionPercentage']) ? floor((int)$itemDetails['TranscodingInfo']['CompletionPercentage']) : 100;
- $embyItem['stream'] = @$itemDetails['PlayState']['PlayMethod'];
- $embyItem['id'] = $item['ServerId'];
- $embyItem['session'] = @$itemDetails['DeviceId'];
- $embyItem['bandwidth'] = isset($itemDetails['TranscodingInfo']['Bitrate']) ? $itemDetails['TranscodingInfo']['Bitrate'] / 1000 : '';
- $embyItem['bandwidthType'] = 'wan';
- $embyItem['sessionType'] = (@$itemDetails['PlayState']['PlayMethod'] == 'Transcode') ? 'Transcoding' : 'Direct Playing';
- $embyItem['state'] = ((@(string)$itemDetails['PlayState']['IsPaused'] == '1') ? "pause" : "play");
- $embyItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? @(string)$itemDetails['UserName'] : "";
- $embyItem['userThumb'] = '';
- $embyItem['userAddress'] = "x.x.x.x";
- $embyItem['address'] = $GLOBALS['embyTabURL'] ? '' : '';
- $embyItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=emby&type='.$embyItem['nowPlayingImageType'].'&img='.$embyItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$embyItem['nowPlayingKey'].'$'.randString();
- $embyItem['originalImage'] = 'api/?v1/image&source=emby&type='.$embyItem['imageType'].'&img='.$embyItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$embyItem['key'].'$'.randString();
- $embyItem['openTab'] = $GLOBALS['embyTabURL'] && $GLOBALS['embyTabName'] ? true : false;
- $embyItem['tabName'] = $GLOBALS['embyTabName'] ? $GLOBALS['embyTabName'] : '';
- // Stream info
- $embyItem['userStream'] = array(
- 'platform' => @(string)$itemDetails['Client'],
- 'product' => @(string)$itemDetails['Client'],
- 'device' => @(string)$itemDetails['DeviceName'],
- 'stream' => @$itemDetails['PlayState']['PlayMethod'],
- 'videoResolution' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]['Width']) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Width'] : '',
- 'throttled' => false,
- 'sourceVideoCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : '',
- 'videoCodec' => @$itemDetails['TranscodingInfo']['VideoCodec'],
- 'audioCodec' => @$itemDetails['TranscodingInfo']['AudioCodec'],
- 'sourceAudioCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][1]) ? $itemDetails['NowPlayingItem']['MediaStreams'][1]['Codec'] : (isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : ''),
- 'videoDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
- 'audioDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
- 'container' => isset($itemDetails['NowPlayingItem']['Container']) ? $itemDetails['NowPlayingItem']['Container'] : '',
- 'audioChannels' => @$itemDetails['TranscodingInfo']['AudioChannels']
- );
- // Genre catch all
- if($item['Genres']){
- $genres = array();
- foreach ($item['Genres'] as $genre) {
- $genres[] = $genre;
- }
- }
- // Actor catch all
- if($item['People'] ){
- $actors = array();
- foreach ($item['People'] as $key => $value) {
- if(@$value['PrimaryImageTag'] && @$value['Role']){
- if (file_exists($cacheDirectory.(string)$value['Id'].'-cast.jpg')){ $actorImage = $cacheDirectoryWeb.(string)$value['Id'].'-cast.jpg'; }
- if (file_exists($cacheDirectory.(string)$value['Id'].'-cast.jpg') && (time() - 604800) > filemtime($cacheDirectory.(string)$value['Id'].'-cast.jpg') || !file_exists($cacheDirectory.(string)$value['Id'].'-cast.jpg')) {
- $actorImage = 'api/?v1/image&source=emby&type=Primary&img='.(string)$value['Id'].'&height='.$actorHeight.'&width='.$actorWidth.'&key='.(string)$value['Id'].'-cast';
- }
- $actors[] = array(
- 'name' => (string)$value['Name'],
- 'role' => (string)$value['Role'],
- 'thumb' => $actorImage
- );
- }
- }
- }
- // Metadata information
- $embyItem['metadata'] = array(
- 'guid' => $item['Id'],
- 'summary' => @(string)$item['Overview'],
- 'rating' => @(string)$item['CommunityRating'],
- 'duration' => @(string)$item['RunTimeTicks'],
- 'originallyAvailableAt' => @(string)$item['PremiereDate'],
- 'year' => (string)$item['ProductionYear'],
- //'studio' => (string)$item['studio'],
- 'tagline' => @(string)$item['Taglines'][0],
- 'genres' => ($item['Genres']) ? $genres : '',
- 'actors' => ($item['People']) ? $actors : ''
- );
- if (file_exists($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg')){ $embyItem['nowPlayingImageURL'] = $cacheDirectoryWeb.$embyItem['nowPlayingKey'].'.jpg'; }
- if (file_exists($cacheDirectory.$embyItem['key'].'.jpg')){ $embyItem['imageURL'] = $cacheDirectoryWeb.$embyItem['key'].'.jpg'; }
- if (file_exists($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg') || !file_exists($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg')) {
- $embyItem['nowPlayingImageURL'] = 'api/?v1/image&source=emby&type='.$embyItem['nowPlayingImageType'].'&img='.$embyItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$embyItem['nowPlayingKey'].'';
- }
- if (file_exists($cacheDirectory.$embyItem['key'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$embyItem['key'].'.jpg') || !file_exists($cacheDirectory.$embyItem['key'].'.jpg')) {
- $embyItem['imageURL'] = 'api/?v1/image&source=emby&type='.$embyItem['imageType'].'&img='.$embyItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$embyItem['key'].'';
- }
- if(!$embyItem['nowPlayingThumb'] ){ $embyItem['nowPlayingOriginalImage'] = $embyItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png"; $embyItem['nowPlayingKey'] = "no-np"; }
- if(!$embyItem['thumb'] ){ $embyItem['originalImage'] = $embyItem['imageURL'] = "plugins/images/cache/no-list.png"; $embyItem['key'] = "no-list"; }
- if(isset($useImage)){ $embyItem['useImage'] = $useImage; }
- return $embyItem;
- }
- function resolvePlexItem($item) {
- // Static Height & Width
- $height = 300;
- $width = 200;
- $nowPlayingHeight = 675;
- $nowPlayingWidth = 1200;
- $widthOverride = 100;
- // Cache Directories
- $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
- $cacheDirectoryWeb = 'plugins/images/cache/';
- // Types
- switch ($item['type']) {
- case 'season':
- $plexItem['type'] = 'tv';
- $plexItem['title'] = (string)$item['parentTitle'];
- $plexItem['summary'] = (string)$item['parentSummary'];
- $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
- $plexItem['thumb'] = (string)$item['thumb'];
- $plexItem['key'] = (string)$item['ratingKey'] . "-list";
- $plexItem['nowPlayingThumb'] = (string)$item['art'];
- $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
- $plexItem['metadataKey'] = (string)$item['parentRatingKey'];
- break;
- case 'episode':
- $plexItem['type'] = 'tv';
- $plexItem['title'] = (string)$item['grandparentTitle'];
- $plexItem['summary'] = (string)$item['title'];
- $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
- $plexItem['thumb'] = ($item['parentThumb'] ? (string)$item['parentThumb'] : (string)$item['grandparentThumb']);
- $plexItem['key'] = (string)$item['ratingKey'] . "-list";
- $plexItem['nowPlayingThumb'] = (string)$item['art'];
- $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
- $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'].' - '.(string)$item['title'];
- $plexItem['nowPlayingBottom'] = 'S'.(string)$item['parentIndex'].' · E'.(string)$item['index'];
- $plexItem['metadataKey'] = (string)$item['grandparentRatingKey'];
- break;
- case 'clip':
- $useImage = (isset($item['live']) ? "plugins/images/cache/livetv.png" : null);
- $plexItem['type'] = 'clip';
- $plexItem['title'] = (string)$item['title'];
- $plexItem['summary'] = (string)$item['summary'];
- $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
- $plexItem['thumb'] = (string)$item['thumb'];
- $plexItem['key'] = (string)$item['ratingKey'] . "-list";
- $plexItem['nowPlayingThumb'] = (string)$item['art'];
- $plexItem['nowPlayingKey'] = isset($item['ratingKey']) ? (string)$item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
- $plexItem['nowPlayingTitle'] = $plexItem['title'];
- $plexItem['nowPlayingBottom'] = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
- break;
- case 'album':
- case 'track':
- $plexItem['type'] = 'music';
- $plexItem['title'] = (string)$item['parentTitle'];
- $plexItem['summary'] = (string)$item['title'];
- $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
- $plexItem['thumb'] = (string)$item['thumb'];
- $plexItem['key'] = (string)$item['ratingKey'] . "-list";
- $plexItem['nowPlayingThumb'] = ($item['parentThumb']) ? (string)$item['parentThumb'] : (string)$item['art'];
- $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
- $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'].' - '.(string)$item['title'];
- $plexItem['nowPlayingBottom'] = (string)$item['parentTitle'];
- $plexItem['metadataKey'] = isset($item['grandparentRatingKey']) ? (string)$item['grandparentRatingKey'] : (string)$item['parentRatingKey'];
- break;
- default:
- $plexItem['type'] = 'movie';
- $plexItem['title'] = (string)$item['title'];
- $plexItem['summary'] = (string)$item['summary'];
- $plexItem['ratingKey'] = (string)$item['ratingKey'];
- $plexItem['thumb'] = (string)$item['thumb'];
- $plexItem['key'] = (string)$item['ratingKey'] . "-list";
- $plexItem['nowPlayingThumb'] = (string)$item['art'];
- $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
- $plexItem['nowPlayingTitle'] = (string)$item['title'];
- $plexItem['nowPlayingBottom'] = (string)$item['year'];
- $plexItem['metadataKey'] = (string)$item['ratingKey'];
- }
- $plexItem['uid'] = (string)$item['ratingKey'];
- $plexItem['elapsed'] = isset($item['viewOffset']) && $item['viewOffset'] !== '0' ? (int)$item['viewOffset'] : null;
- $plexItem['duration'] = isset($item['duration']) ? (int)$item['duration'] : (int)$item->Media['duration'];
- $plexItem['watched'] = ($plexItem['elapsed'] && $plexItem['duration'] ? floor(($plexItem['elapsed'] / $plexItem['duration']) * 100) : 0);
- $plexItem['transcoded'] = isset($item->TranscodeSession['progress']) ? floor((int)$item->TranscodeSession['progress']- $plexItem['watched']) : '';
- $plexItem['stream'] = isset($item->Media->Part->Stream['decision']) ? (string)$item->Media->Part->Stream['decision']: '';
- $plexItem['id'] = str_replace('"', '', (string)$item->Player['machineIdentifier']);
- $plexItem['session'] = (string)$item->Session['id'];
- $plexItem['bandwidth'] = (string)$item->Session['bandwidth'];
- $plexItem['bandwidthType'] = (string)$item->Session['location'];
- $plexItem['sessionType'] = isset($item->TranscodeSession['progress']) ? 'Transcoding' : 'Direct Playing';
- $plexItem['state'] = (((string)$item->Player['state'] == "paused") ? "pause" : "play");
- $plexItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? (string)$item->User['title'] : "";
- $plexItem['userThumb'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? (string)$item->User['thumb'] : "";
- $plexItem['userAddress'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? (string)$item->Player['address'] : "x.x.x.x";
- $plexItem['address'] = $GLOBALS['plexTabURL'] ? $GLOBALS['plexTabURL']."/web/index.html#!/server/".$GLOBALS['plexID']."/details?key=/library/metadata/".$item['ratingKey'] : "https://app.plex.tv/web/app#!/server/".$GLOBALS['plexID']."/details?key=/library/metadata/".$item['ratingKey'];
- $plexItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=plex&img='.$plexItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$plexItem['nowPlayingKey'].'$'.randString();
- $plexItem['originalImage'] = 'api/?v1/image&source=plex&img='.$plexItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$plexItem['key'].'$'.randString();
- $plexItem['openTab'] = $GLOBALS['plexTabURL'] && $GLOBALS['plexTabName'] ? true : false;
- $plexItem['tabName'] = $GLOBALS['plexTabName'] ? $GLOBALS['plexTabName'] : '';
- // Stream info
- $plexItem['userStream'] = array(
- 'platform' => (string)$item->Player['platform'],
- 'product' => (string)$item->Player['product'],
- 'device' => (string)$item->Player['device'],
- 'stream' => (string)$item->Media->Part['decision'].($item->TranscodeSession['throttled'] == '1' ? ' (Throttled)': ''),
- 'videoResolution' => (string)$item->Media['videoResolution'],
- 'throttled' => ($item->TranscodeSession['throttled'] == 1) ? true : false,
- 'sourceVideoCodec' => (string)$item->TranscodeSession['sourceVideoCodec'],
- 'videoCodec' => (string)$item->TranscodeSession['videoCodec'],
- 'audioCodec' => (string)$item->TranscodeSession['audioCodec'],
- 'sourceAudioCodec' => (string)$item->TranscodeSession['sourceAudioCodec'],
- 'videoDecision' => streamType((string)$item->TranscodeSession['videoDecision']),
- 'audioDecision' => streamType((string)$item->TranscodeSession['audioDecision']),
- 'container' => (string)$item->TranscodeSession['container'],
- 'audioChannels' => (string)$item->TranscodeSession['audioChannels']
- );
- // Genre catch all
- if($item->Genre){
- $genres = array();
- foreach ($item->Genre as $key => $value) {
- $genres[] = (string)$value['tag'];
- }
- }
- // Actor catch all
- if($item->Role ){
- $actors = array();
- foreach ($item->Role as $key => $value) {
- if($value['thumb']){
- $actors[] = array(
- 'name' => (string)$value['tag'],
- 'role' => (string)$value['role'],
- 'thumb' => (string)$value['thumb']
- );
- }
- }
- }
- // Metadata information
- $plexItem['metadata'] = array(
- 'guid' => (string)$item['guid'],
- 'summary' => (string)$item['summary'],
- 'rating' => (string)$item['rating'],
- 'duration' => (string)$item['duration'],
- 'originallyAvailableAt' => (string)$item['originallyAvailableAt'],
- 'year' => (string)$item['year'],
- 'studio' => (string)$item['studio'],
- 'tagline' => (string)$item['tagline'],
- 'genres' => ($item->Genre) ? $genres : '',
- 'actors' => ($item->Role) ? $actors : ''
- );
- if (file_exists($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg')){ $plexItem['nowPlayingImageURL'] = $cacheDirectoryWeb.$plexItem['nowPlayingKey'].'.jpg'; }
- if (file_exists($cacheDirectory.$plexItem['key'].'.jpg')){ $plexItem['imageURL'] = $cacheDirectoryWeb.$plexItem['key'].'.jpg'; }
- if (file_exists($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg') || !file_exists($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg')) {
- $plexItem['nowPlayingImageURL'] = 'api/?v1/image&source=plex&img='.$plexItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$plexItem['nowPlayingKey'].'';
- }
- if (file_exists($cacheDirectory.$plexItem['key'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$plexItem['key'].'.jpg') || !file_exists($cacheDirectory.$plexItem['key'].'.jpg')) {
- $plexItem['imageURL'] = 'api/?v1/image&source=plex&img='.$plexItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$plexItem['key'].'';
- }
- if(!$plexItem['nowPlayingThumb'] ){ $plexItem['nowPlayingOriginalImage'] = $plexItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png"; $plexItem['nowPlayingKey'] = "no-np"; }
- if(!$plexItem['thumb'] ){ $plexItem['originalImage'] = $plexItem['imageURL'] = "plugins/images/cache/no-list.png"; $plexItem['key'] = "no-list"; }
- if(isset($useImage)){ $plexItem['useImage'] = $useImage; }
- return $plexItem;
- }
- function plexConnect($action,$key=null){
- if($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']))){
- $url = qualifyURL($GLOBALS['plexURL']);
- switch ($action) {
- case 'streams':
- $url = $url."/status/sessions?X-Plex-Token=".$GLOBALS['plexToken'];
- break;
- case 'recent':
- $url = $url."/library/recentlyAdded?X-Plex-Token=".$GLOBALS['plexToken'];
- break;
- case 'metadata':
- $url = $url."/library/metadata/".$key."?X-Plex-Token=".$GLOBALS['plexToken'];
- break;
- default:
- # code...
- break;
- }
- 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) {
- $items[] = resolvePlexItem($child);
- }
- $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']);
- switch ($action) {
- case 'streams':
- $url = $url.'/Sessions?api_key='.$GLOBALS['embyToken'];
- break;
- case 'recent':
- $username = false;
- if (isset($GLOBALS['organizrUser']['username'])) {
- $username = strtolower($GLOBALS['organizrUser']['username']);
- }
- // Get A User
- $userIds = $url."/Users?api_key=".$GLOBALS['embyToken'];
- $showPlayed = true;
- try{
- $options = (localURL($userIds)) ? array('verify' => false ) : array();
- $response = Requests::get($userIds, array(), $options);
- if($response->success){
- $emby = json_decode($response->body, true);
- foreach ($emby as $value) { // Scan for admin user
- if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
- $userId = $value['Id'];
- }
- if ($username && strtolower($value['Name']) == $username) {
- $userId = $value['Id'];
- $showPlayed = false;
- break;
- }
- }
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $url = $url.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit=100&api_key='.$GLOBALS['embyToken'].($showPlayed?'':'&IsPlayed=false');
- break;
- case 'metadata':
- $skip = true;
- break;
- default:
- # code...
- break;
- }
- if($skip && $key){
- $items[] = resolveEmbyItem(array('Id'=>$key));
- $api['content'] = $items;
- return $api;
- }
- try{
- $options = (localURL($url)) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->success){
- $items = array();
- $emby = json_decode($response->body, true);
- foreach($emby AS $child) {
- if (isset($child['NowPlayingItem']) || isset($child['Name'])) {
- $items[] = resolveEmbyItem($child);
- }
- }
- $api['content'] = array_filter($items);
- return $api;
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- }
- return false;
- }
- function sabnzbdConnect() {
- if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
- $url = qualifyURL($GLOBALS['sabnzbdURL']);
- $url = $url.'/api?mode=queue&output=json&apikey='.$GLOBALS['sabnzbdToken'];
- try{
- $options = (localURL($url)) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->success){
- $api['content']['queueItems'] = json_decode($response->body, true);
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $url = qualifyURL($GLOBALS['sabnzbdURL']);
- $url = $url.'/api?mode=history&output=json&apikey='.$GLOBALS['sabnzbdToken'];
- try{
- $options = (localURL($url)) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->success){
- $api['content']['historyItems']= json_decode($response->body, true);
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- }
- function nzbgetConnect() {
- if($GLOBALS['homepageNzbgetEnabled'] && !empty($GLOBALS['nzbgetURL']) && qualifyRequest($GLOBALS['homepageNzbgetAuth'])){
- $url = qualifyURL($GLOBALS['nzbgetURL']);
- $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/listgroups';
- try{
- $options = (localURL($url)) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->success){
- $api['content']['queueItems'] = json_decode($response->body, true);
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $url = qualifyURL($GLOBALS['nzbgetURL']);
- $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/history';
- try{
- $options = (localURL($url)) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->success){
- $api['content']['historyItems']= json_decode($response->body, true);
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- }
- function transmissionConnect() {
- if($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])){
- $digest = qualifyURL($GLOBALS['transmissionURL'], true);
- $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'].':'.decrypt($GLOBALS['transmissionPassword'])."@" : '';
- $url = $digest['scheme'].'://'.$passwordInclude.$digest['host'].$digest['port'].$digest['path'].'/rpc';
- try{
- $options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false ) : array();
- $response = Requests::get($url, array(), $options);
- if($response->headers['x-transmission-session-id']){
- $headers = array(
- 'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
- 'Content-Type' => 'application/json'
- );
- $data = array(
- 'method' => 'torrent-get',
- 'arguments' => array(
- 'fields' => array(
- "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir","errorString"
- ),
- ),
- 'tags' => ''
- );
- $response = Requests::post($url, $headers, json_encode($data), $options);
- if($response->success){
- $torrentList = json_decode($response->body, true)['arguments']['torrents'];
- if($GLOBALS['transmissionHideSeeding'] || $GLOBALS['transmissionHideCompleted']){
- $filter = array();
- $torrents['arguments']['torrents'] = array();
- if($GLOBALS['transmissionHideSeeding']){ array_push($filter, 6, 5); }
- if($GLOBALS['transmissionHideCompleted']){ array_push($filter, 0); }
- foreach ($torrentList as $key => $value) {
- if(!in_array($value['status'], $filter)){
- $torrents['arguments']['torrents'][] = $value;
- }
- }
- }else{
- $torrents = json_decode($response->body, true);
- }
- $api['content']['queueItems'] = $torrents;
- $api['content']['historyItems'] = false;
- }
- }else{
- writeLog('error', 'Transmission Connect Function - Error: Could not get session ID', 'SYSTEM');
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'Transmission Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- }
- function qBittorrentConnect() {
- if($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])){
- $digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
- $passwordInclude = ($GLOBALS['qBittorrentUsername'] != '' && $GLOBALS['qBittorrentPassword'] != '') ? 'username='.$GLOBALS['qBittorrentUsername'].'&password='.decrypt($GLOBALS['qBittorrentPassword'])."@" : '';
- $data = array('username'=>$GLOBALS['qBittorrentUsername'], 'password'=> decrypt($GLOBALS['qBittorrentPassword']));
- $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/login';
- try{
- $options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false ) : array();
- $response = Requests::post($url, array(), $data, $options);
- $reflection = new ReflectionClass($response->cookies);
- $cookie = $reflection->getProperty("cookies");
- $cookie->setAccessible(true);
- $cookie = $cookie->getValue($response->cookies);
- if($cookie){
- $headers = array(
- 'Cookie' => 'SID=' . $cookie['SID']->value
- );
- $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/query/torrents?sort=eta';
- $response = Requests::get($url, $headers, $options);
- if($response){
- $torrentList = json_decode($response->body, true);
- if($GLOBALS['qBittorrentHideSeeding'] || $GLOBALS['qBittorrentHideCompleted']){
- $filter = array();
- $torrents['arguments']['torrents'] = array();
- if($GLOBALS['qBittorrentHideSeeding']){ array_push($filter, 'uploading', 'stalledUP', 'queuedUP'); }
- if($GLOBALS['qBittorrentHideCompleted']){ array_push($filter, 'pausedUP'); }
- foreach ($torrentList as $key => $value) {
- if(!in_array($value['state'], $filter)){
- $torrents['arguments']['torrents'][] = $value;
- }
- }
- }else{
- $torrents['arguments']['torrents'] = json_decode($response->body, true);
- }
- $api['content']['queueItems'] = $torrents;
- $api['content']['historyItems'] = false;
- }
- }else{
- writeLog('error', 'qBittorrent Connect Function - Error: Could not get session ID', 'SYSTEM');
- }
- }catch( Requests_Exception $e ) {
- writeLog('error', 'qBittorrent Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
- };
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- }
- function accessProtected($obj, $prop) {
- $reflection = new ReflectionClass($obj);
- $property = $reflection->getProperty($prop);
- $property->setAccessible(true);
- return $property->getValue($obj);
- }
|