homepage-connect-functions.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. <?php
  2. function homepageConnect($array){
  3. switch ($array['data']['action']) {
  4. case 'getPlexStreams':
  5. return plexConnect('streams');
  6. break;
  7. case 'getPlexRecent':
  8. return plexConnect('recent');
  9. break;
  10. case 'getPlexMetadata':
  11. return plexConnect('metadata',$array['data']['key']);
  12. break;
  13. case 'getPlexPlaylists':
  14. return getPlexPlaylists();
  15. break;
  16. case 'getEmbyStreams':
  17. return embyConnect('streams');
  18. break;
  19. case 'getEmbyRecent':
  20. return embyConnect('recent');
  21. break;
  22. case 'getEmbyMetadata':
  23. return embyConnect('metadata',$array['data']['key'],true);
  24. break;
  25. case 'getSabnzbd':
  26. return sabnzbdConnect();
  27. break;
  28. case 'getNzbget':
  29. return nzbgetConnect();
  30. break;
  31. case 'getTransmission':
  32. return transmissionConnect();
  33. break;
  34. case 'getqBittorrent':
  35. return qBittorrentConnect();
  36. break;
  37. case 'getDeluge':
  38. return delugeConnect();
  39. break;
  40. case 'getCalendar':
  41. return getCalendar();
  42. break;
  43. case 'getRequests':
  44. return getOmbiRequests();
  45. break;
  46. default:
  47. # code...
  48. break;
  49. }
  50. }
  51. function streamType($value){
  52. if($value == "transcode" || $value == "Transcode"){
  53. return "Transcode";
  54. }elseif($value == "copy" || $value == "DirectStream"){
  55. return "Direct Stream";
  56. }elseif($value == "directplay" || $value == "DirectPlay"){
  57. return "Direct Play";
  58. }else{
  59. return "Direct Play";
  60. }
  61. }
  62. function resolveEmbyItem($itemDetails) {
  63. // Grab Each item info from Emby (extra call)
  64. $id = isset($itemDetails['NowPlayingItem']['Id']) ? $itemDetails['NowPlayingItem']['Id'] : $itemDetails['Id'];
  65. $url = qualifyURL($GLOBALS['embyURL']);
  66. $url = $url.'/Items?Ids='.$id.'&api_key='.$GLOBALS['embyToken'].'&Fields=Overview,People,Genres,CriticRating,Studios,Taglines';
  67. try{
  68. $options = (localURL($url)) ? array('verify' => false ) : array();
  69. $response = Requests::get($url, array(), $options);
  70. if($response->success){
  71. $item = json_decode($response->body,true)['Items'][0];
  72. }
  73. }catch( Requests_Exception $e ) {
  74. return false;
  75. };
  76. // Static Height & Width
  77. $height = 300;
  78. $width = 200;
  79. $nowPlayingHeight = 675;
  80. $nowPlayingWidth = 1200;
  81. $actorHeight = 450;
  82. $actorWidth = 300;
  83. $widthOverride = 100;
  84. // Cache Directories
  85. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  86. $cacheDirectoryWeb = 'plugins/images/cache/';
  87. // Types
  88. $embyItem['array-item'] = $item;
  89. $embyItem['array-itemdetails'] = $itemDetails;
  90. switch (@$item['Type']) {
  91. case 'Series':
  92. $embyItem['type'] = 'tv';
  93. $embyItem['title'] = $item['Name'];
  94. $embyItem['summary'] = '';
  95. $embyItem['ratingKey'] = $item['Id'];
  96. $embyItem['thumb'] = $item['Id'];
  97. $embyItem['key'] = $item['Id'] . "-list";
  98. $embyItem['nowPlayingThumb'] = $item['Id'];
  99. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  100. $embyItem['metadataKey'] = $item['Id'];
  101. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['BackdropImageTags'][0]) ? 'Backdrop' : '');
  102. break;
  103. case 'Episode':
  104. $embyItem['type'] = 'tv';
  105. $embyItem['title'] = $item['SeriesName'];
  106. $embyItem['summary'] = '';
  107. $embyItem['ratingKey'] = $item['Id'];
  108. $embyItem['thumb'] = (isset($item['SeriesId'])?$item['SeriesId']:$item['Id']);
  109. $embyItem['key'] = (isset($item['SeriesId'])?$item['SeriesId']:$item['Id']) . "-list";
  110. $embyItem['nowPlayingThumb'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'] : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'] : false);
  111. $embyItem['nowPlayingKey'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'].'-np' : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'].'-np' : false);
  112. $embyItem['metadataKey'] = $item['Id'];
  113. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['ParentBackdropImageTags'][0]) ? 'Backdrop' : '');
  114. $embyItem['nowPlayingTitle'] = @$item['SeriesName'].' - '.@$item['Name'];
  115. $embyItem['nowPlayingBottom'] = 'S'.@$item['ParentIndexNumber'].' · E'.@$item['IndexNumber'];
  116. break;
  117. case 'MusicAlbum':
  118. case 'Audio':
  119. $embyItem['type'] = 'music';
  120. $embyItem['title'] = $item['Name'];
  121. $embyItem['summary'] = '';
  122. $embyItem['ratingKey'] = $item['Id'];
  123. $embyItem['thumb'] = $item['Id'];
  124. $embyItem['key'] = $item['Id'] . "-list";
  125. $embyItem['nowPlayingThumb'] = (isset($item['AlbumId']) ? $item['AlbumId'] : @$item['ParentBackdropItemId']);
  126. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  127. $embyItem['metadataKey'] = isset($item['AlbumId']) ? $item['AlbumId'] : $item['Id'];
  128. $embyItem['nowPlayingImageType'] = (isset($item['ParentBackdropItemId']) ? "Primary" : "Backdrop");
  129. $embyItem['nowPlayingTitle'] = @$item['AlbumArtist'].' - '.@$item['Name'];
  130. $embyItem['nowPlayingBottom'] = @$item['Album'];
  131. break;
  132. case 'Movie':
  133. $embyItem['type'] = 'movie';
  134. $embyItem['title'] = $item['Name'];
  135. $embyItem['summary'] = '';
  136. $embyItem['ratingKey'] = $item['Id'];
  137. $embyItem['thumb'] = $item['Id'];
  138. $embyItem['key'] = $item['Id'] . "-list";
  139. $embyItem['nowPlayingThumb'] = $item['Id'];
  140. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  141. $embyItem['metadataKey'] = $item['Id'];
  142. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
  143. $embyItem['nowPlayingTitle'] = @$item['Name'];
  144. $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
  145. break;
  146. case 'Video':
  147. $embyItem['type'] = 'video';
  148. $embyItem['title'] = $item['Name'];
  149. $embyItem['summary'] = '';
  150. $embyItem['ratingKey'] = $item['Id'];
  151. $embyItem['thumb'] = $item['Id'];
  152. $embyItem['key'] = $item['Id'] . "-list";
  153. $embyItem['nowPlayingThumb'] = $item['Id'];
  154. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  155. $embyItem['metadataKey'] = $item['Id'];
  156. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
  157. $embyItem['nowPlayingTitle'] = @$item['Name'];
  158. $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
  159. break;
  160. default:
  161. return false;
  162. }
  163. $embyItem['uid'] = $item['Id'];
  164. $embyItem['imageType'] = (isset($item['ImageTags']['Primary']) ? "Primary" : false);
  165. $embyItem['elapsed'] = isset($itemDetails['PlayState']['PositionTicks']) && $itemDetails['PlayState']['PositionTicks'] !== '0' ? (int)$itemDetails['PlayState']['PositionTicks'] : null;
  166. $embyItem['duration'] = isset($itemDetails['NowPlayingItem']['RunTimeTicks']) ? (int)$itemDetails['NowPlayingItem']['RunTimeTicks'] : (int)$item['RunTimeTicks'];
  167. $embyItem['watched'] = ($embyItem['elapsed'] && $embyItem['duration'] ? floor(($embyItem['elapsed'] / $embyItem['duration']) * 100) : 0);
  168. $embyItem['transcoded'] = isset($itemDetails['TranscodingInfo']['CompletionPercentage']) ? floor((int)$itemDetails['TranscodingInfo']['CompletionPercentage']) : 100;
  169. $embyItem['stream'] = @$itemDetails['PlayState']['PlayMethod'];
  170. $embyItem['id'] = $item['ServerId'];
  171. $embyItem['session'] = @$itemDetails['DeviceId'];
  172. $embyItem['bandwidth'] = isset($itemDetails['TranscodingInfo']['Bitrate']) ? $itemDetails['TranscodingInfo']['Bitrate'] / 1000 : '';
  173. $embyItem['bandwidthType'] = 'wan';
  174. $embyItem['sessionType'] = (@$itemDetails['PlayState']['PlayMethod'] == 'Transcode') ? 'Transcoding' : 'Direct Playing';
  175. $embyItem['state'] = ((@(string)$itemDetails['PlayState']['IsPaused'] == '1') ? "pause" : "play");
  176. $embyItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? @(string)$itemDetails['UserName'] : "";
  177. $embyItem['userThumb'] = '';
  178. $embyItem['userAddress'] = (isset($itemDetails['RemoteEndPoint']) ? $itemDetails['RemoteEndPoint'] : "x.x.x.x");
  179. $embyItem['address'] = $GLOBALS['embyTabURL'] ? '' : '';
  180. $embyItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=emby&type='.$embyItem['nowPlayingImageType'].'&img='.$embyItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$embyItem['nowPlayingKey'].'$'.randString();
  181. $embyItem['originalImage'] = 'api/?v1/image&source=emby&type='.$embyItem['imageType'].'&img='.$embyItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$embyItem['key'].'$'.randString();
  182. $embyItem['openTab'] = $GLOBALS['embyTabURL'] && $GLOBALS['embyTabName'] ? true : false;
  183. $embyItem['tabName'] = $GLOBALS['embyTabName'] ? $GLOBALS['embyTabName'] : '';
  184. // Stream info
  185. $embyItem['userStream'] = array(
  186. 'platform' => @(string)$itemDetails['Client'],
  187. 'product' => @(string)$itemDetails['Client'],
  188. 'device' => @(string)$itemDetails['DeviceName'],
  189. 'stream' => @$itemDetails['PlayState']['PlayMethod'],
  190. 'videoResolution' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]['Width']) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Width'] : '',
  191. 'throttled' => false,
  192. 'sourceVideoCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : '',
  193. 'videoCodec' => @$itemDetails['TranscodingInfo']['VideoCodec'],
  194. 'audioCodec' => @$itemDetails['TranscodingInfo']['AudioCodec'],
  195. 'sourceAudioCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][1]) ? $itemDetails['NowPlayingItem']['MediaStreams'][1]['Codec'] : (isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : ''),
  196. 'videoDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
  197. 'audioDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
  198. 'container' => isset($itemDetails['NowPlayingItem']['Container']) ? $itemDetails['NowPlayingItem']['Container'] : '',
  199. 'audioChannels' => @$itemDetails['TranscodingInfo']['AudioChannels']
  200. );
  201. // Genre catch all
  202. if($item['Genres']){
  203. $genres = array();
  204. foreach ($item['Genres'] as $genre) {
  205. $genres[] = $genre;
  206. }
  207. }
  208. // Actor catch all
  209. if($item['People'] ){
  210. $actors = array();
  211. foreach ($item['People'] as $key => $value) {
  212. if(@$value['PrimaryImageTag'] && @$value['Role']){
  213. if (file_exists($cacheDirectory.(string)$value['Id'].'-cast.jpg')){ $actorImage = $cacheDirectoryWeb.(string)$value['Id'].'-cast.jpg'; }
  214. 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')) {
  215. $actorImage = 'api/?v1/image&source=emby&type=Primary&img='.(string)$value['Id'].'&height='.$actorHeight.'&width='.$actorWidth.'&key='.(string)$value['Id'].'-cast';
  216. }
  217. $actors[] = array(
  218. 'name' => (string)$value['Name'],
  219. 'role' => (string)$value['Role'],
  220. 'thumb' => $actorImage
  221. );
  222. }
  223. }
  224. }
  225. // Metadata information
  226. $embyItem['metadata'] = array(
  227. 'guid' => $item['Id'],
  228. 'summary' => @(string)$item['Overview'],
  229. 'rating' => @(string)$item['CommunityRating'],
  230. 'duration' => @(string)$item['RunTimeTicks'],
  231. 'originallyAvailableAt' => @(string)$item['PremiereDate'],
  232. 'year' => (string)$item['ProductionYear'],
  233. //'studio' => (string)$item['studio'],
  234. 'tagline' => @(string)$item['Taglines'][0],
  235. 'genres' => ($item['Genres']) ? $genres : '',
  236. 'actors' => ($item['People']) ? $actors : ''
  237. );
  238. if (file_exists($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg')){ $embyItem['nowPlayingImageURL'] = $cacheDirectoryWeb.$embyItem['nowPlayingKey'].'.jpg'; }
  239. if (file_exists($cacheDirectory.$embyItem['key'].'.jpg')){ $embyItem['imageURL'] = $cacheDirectoryWeb.$embyItem['key'].'.jpg'; }
  240. if (file_exists($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg') || !file_exists($cacheDirectory.$embyItem['nowPlayingKey'].'.jpg')) {
  241. $embyItem['nowPlayingImageURL'] = 'api/?v1/image&source=emby&type='.$embyItem['nowPlayingImageType'].'&img='.$embyItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$embyItem['nowPlayingKey'].'';
  242. }
  243. if (file_exists($cacheDirectory.$embyItem['key'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$embyItem['key'].'.jpg') || !file_exists($cacheDirectory.$embyItem['key'].'.jpg')) {
  244. $embyItem['imageURL'] = 'api/?v1/image&source=emby&type='.$embyItem['imageType'].'&img='.$embyItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$embyItem['key'].'';
  245. }
  246. if(!$embyItem['nowPlayingThumb'] ){ $embyItem['nowPlayingOriginalImage'] = $embyItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png"; $embyItem['nowPlayingKey'] = "no-np"; }
  247. if(!$embyItem['thumb'] ){ $embyItem['originalImage'] = $embyItem['imageURL'] = "plugins/images/cache/no-list.png"; $embyItem['key'] = "no-list"; }
  248. if(isset($useImage)){ $embyItem['useImage'] = $useImage; }
  249. return $embyItem;
  250. }
  251. function resolvePlexItem($item) {
  252. // Static Height & Width
  253. $height = 300;
  254. $width = 200;
  255. $nowPlayingHeight = 675;
  256. $nowPlayingWidth = 1200;
  257. $widthOverride = 100;
  258. // Cache Directories
  259. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  260. $cacheDirectoryWeb = 'plugins/images/cache/';
  261. // Types
  262. switch ($item['type']) {
  263. case 'season':
  264. $plexItem['type'] = 'tv';
  265. $plexItem['title'] = (string)$item['parentTitle'];
  266. $plexItem['summary'] = (string)$item['parentSummary'];
  267. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  268. $plexItem['thumb'] = (string)$item['thumb'];
  269. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  270. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  271. $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
  272. $plexItem['metadataKey'] = (string)$item['parentRatingKey'];
  273. break;
  274. case 'episode':
  275. $plexItem['type'] = 'tv';
  276. $plexItem['title'] = (string)$item['grandparentTitle'];
  277. $plexItem['summary'] = (string)$item['title'];
  278. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  279. $plexItem['thumb'] = ($item['parentThumb'] ? (string)$item['parentThumb'] : (string)$item['grandparentThumb']);
  280. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  281. $plexItem['nowPlayingThumb'] = (string)$item['grandparentArt'];
  282. $plexItem['nowPlayingKey'] = (string)$item['grandparentRatingKey'] . "-np";
  283. $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'].' - '.(string)$item['title'];
  284. $plexItem['nowPlayingBottom'] = 'S'.(string)$item['parentIndex'].' · E'.(string)$item['index'];
  285. $plexItem['metadataKey'] = (string)$item['grandparentRatingKey'];
  286. break;
  287. case 'clip':
  288. $useImage = (isset($item['live']) ? "plugins/images/cache/livetv.png" : null);
  289. $plexItem['type'] = 'clip';
  290. $plexItem['title'] = (string)$item['title'];
  291. $plexItem['summary'] = (string)$item['summary'];
  292. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  293. $plexItem['thumb'] = (string)$item['thumb'];
  294. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  295. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  296. $plexItem['nowPlayingKey'] = isset($item['ratingKey']) ? (string)$item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  297. $plexItem['nowPlayingTitle'] = $plexItem['title'];
  298. $plexItem['nowPlayingBottom'] = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  299. break;
  300. case 'album':
  301. case 'track':
  302. $plexItem['type'] = 'music';
  303. $plexItem['title'] = (string)$item['parentTitle'];
  304. $plexItem['summary'] = (string)$item['title'];
  305. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  306. $plexItem['thumb'] = (string)$item['thumb'];
  307. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  308. $plexItem['nowPlayingThumb'] = ($item['parentThumb']) ? (string)$item['parentThumb'] : (string)$item['art'];
  309. $plexItem['nowPlayingKey'] = (string)$item['parentRatingKey'] . "-np";
  310. $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'].' - '.(string)$item['title'];
  311. $plexItem['nowPlayingBottom'] = (string)$item['parentTitle'];
  312. $plexItem['metadataKey'] = isset($item['grandparentRatingKey']) ? (string)$item['grandparentRatingKey'] : (string)$item['parentRatingKey'];
  313. break;
  314. default:
  315. $plexItem['type'] = 'movie';
  316. $plexItem['title'] = (string)$item['title'];
  317. $plexItem['summary'] = (string)$item['summary'];
  318. $plexItem['ratingKey'] = (string)$item['ratingKey'];
  319. $plexItem['thumb'] = (string)$item['thumb'];
  320. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  321. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  322. $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
  323. $plexItem['nowPlayingTitle'] = (string)$item['title'];
  324. $plexItem['nowPlayingBottom'] = (string)$item['year'];
  325. $plexItem['metadataKey'] = (string)$item['ratingKey'];
  326. }
  327. $plexItem['uid'] = (string)$item['ratingKey'];
  328. $plexItem['elapsed'] = isset($item['viewOffset']) && $item['viewOffset'] !== '0' ? (int)$item['viewOffset'] : null;
  329. $plexItem['duration'] = isset($item['duration']) ? (int)$item['duration'] : (int)$item->Media['duration'];
  330. $plexItem['watched'] = ($plexItem['elapsed'] && $plexItem['duration'] ? floor(($plexItem['elapsed'] / $plexItem['duration']) * 100) : 0);
  331. $plexItem['transcoded'] = isset($item->TranscodeSession['progress']) ? floor((int)$item->TranscodeSession['progress']- $plexItem['watched']) : '';
  332. $plexItem['stream'] = isset($item->Media->Part->Stream['decision']) ? (string)$item->Media->Part->Stream['decision']: '';
  333. $plexItem['id'] = str_replace('"', '', (string)$item->Player['machineIdentifier']);
  334. $plexItem['session'] = (string)$item->Session['id'];
  335. $plexItem['bandwidth'] = (string)$item->Session['bandwidth'];
  336. $plexItem['bandwidthType'] = (string)$item->Session['location'];
  337. $plexItem['sessionType'] = isset($item->TranscodeSession['progress']) ? 'Transcoding' : 'Direct Playing';
  338. $plexItem['state'] = (((string)$item->Player['state'] == "paused") ? "pause" : "play");
  339. $plexItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? (string)$item->User['title'] : "";
  340. $plexItem['userThumb'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? (string)$item->User['thumb'] : "";
  341. $plexItem['userAddress'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth']) ) ? (string)$item->Player['address'] : "x.x.x.x";
  342. $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'];
  343. $plexItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=plex&img='.$plexItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$plexItem['nowPlayingKey'].'$'.randString();
  344. $plexItem['originalImage'] = 'api/?v1/image&source=plex&img='.$plexItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$plexItem['key'].'$'.randString();
  345. $plexItem['openTab'] = $GLOBALS['plexTabURL'] && $GLOBALS['plexTabName'] ? true : false;
  346. $plexItem['tabName'] = $GLOBALS['plexTabName'] ? $GLOBALS['plexTabName'] : '';
  347. // Stream info
  348. $plexItem['userStream'] = array(
  349. 'platform' => (string)$item->Player['platform'],
  350. 'product' => (string)$item->Player['product'],
  351. 'device' => (string)$item->Player['device'],
  352. 'stream' => (string)$item->Media->Part['decision'].($item->TranscodeSession['throttled'] == '1' ? ' (Throttled)': ''),
  353. 'videoResolution' => (string)$item->Media['videoResolution'],
  354. 'throttled' => ($item->TranscodeSession['throttled'] == 1) ? true : false,
  355. 'sourceVideoCodec' => (string)$item->TranscodeSession['sourceVideoCodec'],
  356. 'videoCodec' => (string)$item->TranscodeSession['videoCodec'],
  357. 'audioCodec' => (string)$item->TranscodeSession['audioCodec'],
  358. 'sourceAudioCodec' => (string)$item->TranscodeSession['sourceAudioCodec'],
  359. 'videoDecision' => streamType((string)$item->TranscodeSession['videoDecision']),
  360. 'audioDecision' => streamType((string)$item->TranscodeSession['audioDecision']),
  361. 'container' => (string)$item->TranscodeSession['container'],
  362. 'audioChannels' => (string)$item->TranscodeSession['audioChannels']
  363. );
  364. // Genre catch all
  365. if($item->Genre){
  366. $genres = array();
  367. foreach ($item->Genre as $key => $value) {
  368. $genres[] = (string)$value['tag'];
  369. }
  370. }
  371. // Actor catch all
  372. if($item->Role ){
  373. $actors = array();
  374. foreach ($item->Role as $key => $value) {
  375. if($value['thumb']){
  376. $actors[] = array(
  377. 'name' => (string)$value['tag'],
  378. 'role' => (string)$value['role'],
  379. 'thumb' => (string)$value['thumb']
  380. );
  381. }
  382. }
  383. }
  384. // Metadata information
  385. $plexItem['metadata'] = array(
  386. 'guid' => (string)$item['guid'],
  387. 'summary' => (string)$item['summary'],
  388. 'rating' => (string)$item['rating'],
  389. 'duration' => (string)$item['duration'],
  390. 'originallyAvailableAt' => (string)$item['originallyAvailableAt'],
  391. 'year' => (string)$item['year'],
  392. 'studio' => (string)$item['studio'],
  393. 'tagline' => (string)$item['tagline'],
  394. 'genres' => ($item->Genre) ? $genres : '',
  395. 'actors' => ($item->Role) ? $actors : ''
  396. );
  397. if (file_exists($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg')){ $plexItem['nowPlayingImageURL'] = $cacheDirectoryWeb.$plexItem['nowPlayingKey'].'.jpg'; }
  398. if (file_exists($cacheDirectory.$plexItem['key'].'.jpg')){ $plexItem['imageURL'] = $cacheDirectoryWeb.$plexItem['key'].'.jpg'; }
  399. if (file_exists($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg') || !file_exists($cacheDirectory.$plexItem['nowPlayingKey'].'.jpg')) {
  400. $plexItem['nowPlayingImageURL'] = 'api/?v1/image&source=plex&img='.$plexItem['nowPlayingThumb'].'&height='.$nowPlayingHeight.'&width='.$nowPlayingWidth.'&key='.$plexItem['nowPlayingKey'].'';
  401. }
  402. if (file_exists($cacheDirectory.$plexItem['key'].'.jpg') && (time() - 604800) > filemtime($cacheDirectory.$plexItem['key'].'.jpg') || !file_exists($cacheDirectory.$plexItem['key'].'.jpg')) {
  403. $plexItem['imageURL'] = 'api/?v1/image&source=plex&img='.$plexItem['thumb'].'&height='.$height.'&width='.$width.'&key='.$plexItem['key'].'';
  404. }
  405. if(!$plexItem['nowPlayingThumb'] ){ $plexItem['nowPlayingOriginalImage'] = $plexItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png"; $plexItem['nowPlayingKey'] = "no-np"; }
  406. if(!$plexItem['thumb'] ){ $plexItem['originalImage'] = $plexItem['imageURL'] = "plugins/images/cache/no-list.png"; $plexItem['key'] = "no-list"; }
  407. if(isset($useImage)){ $plexItem['useImage'] = $useImage; }
  408. return $plexItem;
  409. }
  410. function plexConnect($action,$key=null){
  411. if($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']))){
  412. $url = qualifyURL($GLOBALS['plexURL']);
  413. switch ($action) {
  414. case 'streams':
  415. $url = $url."/status/sessions?X-Plex-Token=".$GLOBALS['plexToken'];
  416. break;
  417. case 'recent':
  418. $url = $url."/library/recentlyAdded?X-Plex-Token=".$GLOBALS['plexToken'];
  419. break;
  420. case 'metadata':
  421. $url = $url."/library/metadata/".$key."?X-Plex-Token=".$GLOBALS['plexToken'];
  422. break;
  423. case 'playlists':
  424. $url = $url."/playlists?X-Plex-Token=".$GLOBALS['plexToken'];
  425. break;
  426. default:
  427. # code...
  428. break;
  429. }
  430. try{
  431. $options = (localURL($url)) ? array('verify' => false ) : array();
  432. $response = Requests::get($url, array(), $options);
  433. libxml_use_internal_errors(true);
  434. if($response->success){
  435. $items = array();
  436. $plex = simplexml_load_string($response->body);
  437. foreach($plex AS $child) {
  438. $items[] = resolvePlexItem($child);
  439. }
  440. $api['content'] = $items;
  441. $api['plexID'] = $GLOBALS['plexID'];
  442. $api['showNames'] = true;
  443. $api['group'] = '1';
  444. return $api;
  445. }
  446. }catch( Requests_Exception $e ) {
  447. writeLog('error', 'Plex Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  448. };
  449. }
  450. return false;
  451. }
  452. function getPlexPlaylists(){
  453. if($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']) && qualifyRequest($GLOBALS['homepagePlexPlaylistAuth']) && $GLOBALS['homepagePlexPlaylist'])){
  454. $url = qualifyURL($GLOBALS['plexURL']);
  455. $url = $url."/playlists?X-Plex-Token=".$GLOBALS['plexToken'];
  456. try{
  457. $options = (localURL($url)) ? array('verify' => false ) : array();
  458. $response = Requests::get($url, array(), $options);
  459. libxml_use_internal_errors(true);
  460. if($response->success){
  461. $items = array();
  462. $plex = simplexml_load_string($response->body);
  463. foreach($plex AS $child) {
  464. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
  465. $playlistTitleClean = preg_replace("/(\W)+/", "", (string)$child['title']);
  466. $playlistURL = qualifyURL($GLOBALS['plexURL']);
  467. $playlistURL = $playlistURL.$child['key']."?X-Plex-Token=".$GLOBALS['plexToken'];
  468. $options = (localURL($url)) ? array('verify' => false ) : array();
  469. $playlistResponse = Requests::get($playlistURL, array(), $options);
  470. if($playlistResponse->success){
  471. $playlistResponse = simplexml_load_string($playlistResponse->body);
  472. $items[$playlistTitleClean]['title'] = (string)$child['title'];
  473. foreach($playlistResponse->Video AS $playlistItem){
  474. $items[$playlistTitleClean][] = resolvePlexItem($playlistItem);
  475. }
  476. }
  477. }
  478. }
  479. $api['content'] = $items;
  480. $api['plexID'] = $GLOBALS['plexID'];
  481. $api['showNames'] = true;
  482. $api['group'] = '1';
  483. return $api;
  484. }
  485. }catch( Requests_Exception $e ) {
  486. writeLog('error', 'Plex Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  487. };
  488. }
  489. return false;
  490. }
  491. function embyConnect($action,$key=null,$skip=false){
  492. if($GLOBALS['homepageEmbyEnabled'] && !empty($GLOBALS['embyURL']) && !empty($GLOBALS['embyToken']) && qualifyRequest($GLOBALS['homepageEmbyAuth'])){
  493. $url = qualifyURL($GLOBALS['embyURL']);
  494. switch ($action) {
  495. case 'streams':
  496. $url = $url.'/Sessions?api_key='.$GLOBALS['embyToken'];
  497. break;
  498. case 'recent':
  499. $username = false;
  500. if (isset($GLOBALS['organizrUser']['username'])) {
  501. $username = strtolower($GLOBALS['organizrUser']['username']);
  502. }
  503. // Get A User
  504. $userIds = $url."/Users?api_key=".$GLOBALS['embyToken'];
  505. $showPlayed = true;
  506. try{
  507. $options = (localURL($userIds)) ? array('verify' => false ) : array();
  508. $response = Requests::get($userIds, array(), $options);
  509. if($response->success){
  510. $emby = json_decode($response->body, true);
  511. foreach ($emby as $value) { // Scan for admin user
  512. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  513. $userId = $value['Id'];
  514. }
  515. if ($username && strtolower($value['Name']) == $username) {
  516. $userId = $value['Id'];
  517. $showPlayed = false;
  518. break;
  519. }
  520. }
  521. }
  522. }catch( Requests_Exception $e ) {
  523. writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  524. };
  525. $url = $url.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit=100&api_key='.$GLOBALS['embyToken'].($showPlayed?'':'&IsPlayed=false');
  526. break;
  527. case 'metadata':
  528. $skip = true;
  529. break;
  530. default:
  531. # code...
  532. break;
  533. }
  534. if($skip && $key){
  535. $items[] = resolveEmbyItem(array('Id'=>$key));
  536. $api['content'] = $items;
  537. return $api;
  538. }
  539. try{
  540. $options = (localURL($url)) ? array('verify' => false ) : array();
  541. $response = Requests::get($url, array(), $options);
  542. if($response->success){
  543. $items = array();
  544. $emby = json_decode($response->body, true);
  545. foreach($emby AS $child) {
  546. if (isset($child['NowPlayingItem']) || isset($child['Name'])) {
  547. $items[] = resolveEmbyItem($child);
  548. }
  549. }
  550. $api['content'] = array_filter($items);
  551. return $api;
  552. }
  553. }catch( Requests_Exception $e ) {
  554. writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  555. };
  556. }
  557. return false;
  558. }
  559. function sabnzbdConnect() {
  560. if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
  561. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  562. $url = $url.'/api?mode=queue&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  563. try{
  564. $options = (localURL($url)) ? array('verify' => false ) : array();
  565. $response = Requests::get($url, array(), $options);
  566. if($response->success){
  567. $api['content']['queueItems'] = json_decode($response->body, true);
  568. }
  569. }catch( Requests_Exception $e ) {
  570. writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  571. };
  572. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  573. $url = $url.'/api?mode=history&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  574. try{
  575. $options = (localURL($url)) ? array('verify' => false ) : array();
  576. $response = Requests::get($url, array(), $options);
  577. if($response->success){
  578. $api['content']['historyItems']= json_decode($response->body, true);
  579. }
  580. }catch( Requests_Exception $e ) {
  581. writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  582. };
  583. $api['content'] = isset($api['content']) ? $api['content'] : false;
  584. return $api;
  585. }
  586. }
  587. function nzbgetConnect() {
  588. if($GLOBALS['homepageNzbgetEnabled'] && !empty($GLOBALS['nzbgetURL']) && qualifyRequest($GLOBALS['homepageNzbgetAuth'])){
  589. $url = qualifyURL($GLOBALS['nzbgetURL']);
  590. $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/listgroups';
  591. try{
  592. $options = (localURL($url)) ? array('verify' => false ) : array();
  593. $response = Requests::get($url, array(), $options);
  594. if($response->success){
  595. $api['content']['queueItems'] = json_decode($response->body, true);
  596. }
  597. }catch( Requests_Exception $e ) {
  598. writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  599. };
  600. $url = qualifyURL($GLOBALS['nzbgetURL']);
  601. $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/history';
  602. try{
  603. $options = (localURL($url)) ? array('verify' => false ) : array();
  604. $response = Requests::get($url, array(), $options);
  605. if($response->success){
  606. $api['content']['historyItems']= json_decode($response->body, true);
  607. }
  608. }catch( Requests_Exception $e ) {
  609. writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  610. };
  611. $api['content'] = isset($api['content']) ? $api['content'] : false;
  612. return $api;
  613. }
  614. }
  615. function transmissionConnect() {
  616. if($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])){
  617. $digest = qualifyURL($GLOBALS['transmissionURL'], true);
  618. $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'].':'.decrypt($GLOBALS['transmissionPassword'])."@" : '';
  619. $url = $digest['scheme'].'://'.$passwordInclude.$digest['host'].$digest['port'].$digest['path'].'/rpc';
  620. try{
  621. $options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false ) : array();
  622. $response = Requests::get($url, array(), $options);
  623. if($response->headers['x-transmission-session-id']){
  624. $headers = array(
  625. 'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
  626. 'Content-Type' => 'application/json'
  627. );
  628. $data = array(
  629. 'method' => 'torrent-get',
  630. 'arguments' => array(
  631. 'fields' => array(
  632. "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir","errorString"
  633. ),
  634. ),
  635. 'tags' => ''
  636. );
  637. $response = Requests::post($url, $headers, json_encode($data), $options);
  638. if($response->success){
  639. $torrentList = json_decode($response->body, true)['arguments']['torrents'];
  640. if($GLOBALS['transmissionHideSeeding'] || $GLOBALS['transmissionHideCompleted']){
  641. $filter = array();
  642. $torrents['arguments']['torrents'] = array();
  643. if($GLOBALS['transmissionHideSeeding']){ array_push($filter, 6, 5); }
  644. if($GLOBALS['transmissionHideCompleted']){ array_push($filter, 0); }
  645. foreach ($torrentList as $key => $value) {
  646. if(!in_array($value['status'], $filter)){
  647. $torrents['arguments']['torrents'][] = $value;
  648. }
  649. }
  650. }else{
  651. $torrents = json_decode($response->body, true);
  652. }
  653. $api['content']['queueItems'] = $torrents;
  654. $api['content']['historyItems'] = false;
  655. }
  656. }else{
  657. writeLog('error', 'Transmission Connect Function - Error: Could not get session ID', 'SYSTEM');
  658. }
  659. }catch( Requests_Exception $e ) {
  660. writeLog('error', 'Transmission Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  661. };
  662. $api['content'] = isset($api['content']) ? $api['content'] : false;
  663. return $api;
  664. }
  665. }
  666. function qBittorrentConnect() {
  667. if($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])){
  668. $digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
  669. $passwordInclude = ($GLOBALS['qBittorrentUsername'] != '' && $GLOBALS['qBittorrentPassword'] != '') ? 'username='.$GLOBALS['qBittorrentUsername'].'&password='.decrypt($GLOBALS['qBittorrentPassword'])."@" : '';
  670. $data = array('username'=>$GLOBALS['qBittorrentUsername'], 'password'=> decrypt($GLOBALS['qBittorrentPassword']));
  671. $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/login';
  672. try{
  673. $options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false ) : array();
  674. $response = Requests::post($url, array(), $data, $options);
  675. $reflection = new ReflectionClass($response->cookies);
  676. $cookie = $reflection->getProperty("cookies");
  677. $cookie->setAccessible(true);
  678. $cookie = $cookie->getValue($response->cookies);
  679. if($cookie){
  680. $headers = array(
  681. 'Cookie' => 'SID=' . $cookie['SID']->value
  682. );
  683. $reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
  684. $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/query/torrents?sort=' . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
  685. $response = Requests::get($url, $headers, $options);
  686. if($response){
  687. $torrentList = json_decode($response->body, true);
  688. if($GLOBALS['qBittorrentHideSeeding'] || $GLOBALS['qBittorrentHideCompleted']){
  689. $filter = array();
  690. $torrents['arguments']['torrents'] = array();
  691. if($GLOBALS['qBittorrentHideSeeding']){ array_push($filter, 'uploading', 'stalledUP', 'queuedUP'); }
  692. if($GLOBALS['qBittorrentHideCompleted']){ array_push($filter, 'pausedUP'); }
  693. foreach ($torrentList as $key => $value) {
  694. if(!in_array($value['state'], $filter)){
  695. $torrents['arguments']['torrents'][] = $value;
  696. }
  697. }
  698. }else{
  699. $torrents['arguments']['torrents'] = json_decode($response->body, true);
  700. }
  701. $api['content']['queueItems'] = $torrents;
  702. $api['content']['historyItems'] = false;
  703. }
  704. }else{
  705. writeLog('error', 'qBittorrent Connect Function - Error: Could not get session ID', 'SYSTEM');
  706. }
  707. }catch( Requests_Exception $e ) {
  708. writeLog('error', 'qBittorrent Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  709. };
  710. $api['content'] = isset($api['content']) ? $api['content'] : false;
  711. return $api;
  712. }
  713. }
  714. function delugeConnect(){
  715. if($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])){
  716. try{
  717. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  718. $torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate');
  719. $api['content']['queueItems'] = $torrents;
  720. $api['content']['historyItems'] = false;
  721. }catch( Excecption $e){
  722. writeLog('error', 'Deluge Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  723. }
  724. }
  725. $api['content'] = isset($api['content']) ? $api['content'] : false;
  726. return $api;
  727. }
  728. function getCalendar(){
  729. $startDate = date('Y-m-d',strtotime("-".$GLOBALS['calendarStart']." days"));
  730. $endDate = date('Y-m-d',strtotime("+".$GLOBALS['calendarEnd']." days"));
  731. $calendarItems = array();
  732. // SONARR CONNECT
  733. if($GLOBALS['homepageSonarrEnabled'] && qualifyRequest($GLOBALS['homepageSonarrAuth']) && !empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])){
  734. $sonarrs = array();
  735. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  736. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  737. if(count($sonarrURLList) == count($sonarrTokenList)){
  738. foreach ($sonarrURLList as $key => $value) {
  739. $sonarrs[$key] = array(
  740. 'url' => $value,
  741. 'token' => $sonarrTokenList[$key]
  742. );
  743. }
  744. foreach ($sonarrs as $key => $value) {
  745. try {
  746. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  747. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate),$key);
  748. } catch (Exception $e) {
  749. writeLog('error', 'Sonarr Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  750. }
  751. if(!empty($sonarrCalendar)) { $calendarItems = array_merge($calendarItems, $sonarrCalendar); }
  752. }
  753. }
  754. }
  755. // RADARR CONNECT
  756. if($GLOBALS['homepageRadarrEnabled'] && qualifyRequest($GLOBALS['homepageRadarrAuth']) && !empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])){
  757. $radarrs = array();
  758. $radarrURLList = explode(',', $GLOBALS['radarrURL']);
  759. $radarrTokenList = explode(',', $GLOBALS['radarrToken']);
  760. if(count($radarrURLList) == count($radarrTokenList)){
  761. foreach ($radarrURLList as $key => $value) {
  762. $radarrs[$key] = array(
  763. 'url' => $value,
  764. 'token' => $radarrTokenList[$key]
  765. );
  766. }
  767. foreach ($radarrs as $key => $value) {
  768. try {
  769. $radarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  770. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate),$key,$value['url']);
  771. } catch (Exception $e) {
  772. writeLog('error', 'Radarr Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  773. }
  774. if(!empty($radarrCalendar)) { $calendarItems = array_merge($calendarItems, $radarrCalendar); }
  775. }
  776. }
  777. }
  778. // SICKRAGE/BEARD/MEDUSA CONNECT
  779. if($GLOBALS['homepageSickrageEnabled'] && qualifyRequest($GLOBALS['homepageSickrageAuth']) && !empty($GLOBALS['sickrageURL']) && !empty($GLOBALS['sickrageToken'])){
  780. $sicks = array();
  781. $sickURLList = explode(',', $GLOBALS['sickrageURL']);
  782. $sickTokenList = explode(',', $GLOBALS['sickrageToken']);
  783. if(count($sickURLList) == count($sickTokenList)){
  784. foreach ($sickURLList as $key => $value) {
  785. $sicks[$key] = array(
  786. 'url' => $value,
  787. 'token' => $sickTokenList[$key]
  788. );
  789. }
  790. foreach ($sicks as $key => $value) {
  791. try {
  792. $sickrage = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
  793. $sickrageFuture = getSickrageCalendarWanted($sickrage->future(),$key);
  794. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"),$key);
  795. if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
  796. if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
  797. } catch (Exception $e) {
  798. writeLog('error', 'Sickrage Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  799. }
  800. }
  801. }
  802. }
  803. // COUCHPOTATO CONNECT
  804. if($GLOBALS['homepageCouchpotatoEnabled'] && qualifyRequest($GLOBALS['homepageCouchpotatoAuth']) && !empty($GLOBALS['couchpotatoURL']) && !empty($GLOBALS['couchpotatoToken'])){
  805. $couchs = array();
  806. $couchpotatoURLList = explode(',', $GLOBALS['couchpotatoURL']);
  807. $couchpotatoTokenList = explode(',', $GLOBALS['couchpotatoToken']);
  808. if(count($couchpotatoURLList) == count($couchpotatoTokenList)){
  809. foreach ($couchpotatoURLList as $key => $value) {
  810. $couchs[$key] = array(
  811. 'url' => $value,
  812. 'token' => $couchpotatoTokenList[$key]
  813. );
  814. }
  815. foreach ($couchs as $key => $value) {
  816. try {
  817. $couchpotato = new Kryptonit3\CouchPotato\CouchPotato($value['url'], $value['token']);
  818. $couchCalendar = getCouchCalendar($couchpotato->getMediaList(),$key);
  819. if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
  820. } catch (Exception $e) {
  821. writeLog('error', 'Sickrage Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  822. }
  823. }
  824. }
  825. }
  826. return ($calendarItems) ? $calendarItems : false;
  827. }
  828. function getSonarrCalendar($array,$number){
  829. $array = json_decode($array, true);
  830. $gotCalendar = array();
  831. $i = 0;
  832. foreach($array AS $child) {
  833. $i++;
  834. $seriesName = $child['series']['title'];
  835. $episodeID = $child['series']['tvdbId'];
  836. if(!isset($episodeID)){ $episodeID = ""; }
  837. $episodeName = htmlentities($child['title'], ENT_QUOTES);
  838. if($child['episodeNumber'] == "1"){ $episodePremier = "true"; }else{ $episodePremier = "false"; }
  839. $episodeAirDate = $child['airDateUtc'];
  840. $episodeAirDate = strtotime($episodeAirDate);
  841. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  842. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  843. $downloaded = $child['hasFile'];
  844. if($downloaded == "0" && isset($unaired) && $episodePremier == "true"){ $downloaded = "text-primary"; }elseif($downloaded == "0" && isset($unaired)){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
  845. $fanart = "/plugins/images/cache/no-np.png";
  846. foreach ($child['series']['images'] as $image) {
  847. if($image['coverType'] == "fanart") {
  848. $fanart = $image['url'];
  849. }
  850. }
  851. $bottomTitle = 'S' . sprintf("%02d", $child['seasonNumber']) . 'E' . sprintf("%02d", $child['episodeNumber']) . ' - ' . $child['title'];
  852. $details = array(
  853. "seasonCount" => $child['series']['seasonCount'],
  854. "status" => $child['series']['status'],
  855. "topTitle" => $seriesName,
  856. "bottomTitle" => $bottomTitle,
  857. "overview" => isset($child['overview']) ? $child['overview'] : '',
  858. "runtime" => $child['series']['runtime'],
  859. "image" => $fanart,
  860. "ratings" => $child['series']['ratings']['value'],
  861. "videoQuality" => $child["hasFile"] ? $child['episodeFile']['quality']['quality']['name'] : "unknown",
  862. "audioChannels" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioChannels'] : "unknown",
  863. "audioCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioCodec'] : "unknown",
  864. "videoCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['videoCodec'] : "unknown",
  865. "size" => $child["hasFile"] ? $child['episodeFile']['size'] : "unknown",
  866. "genres" => $child['series']['genres'],
  867. );
  868. array_push($gotCalendar, array(
  869. "id" => "Sonarr-".$number."-".$i,
  870. "title" => $seriesName,
  871. "start" => $child['airDateUtc'],
  872. "className" => "bg-calendar calendar-item tvID--".$episodeID,
  873. "imagetype" => "tv ".$downloaded,
  874. "details" => $details
  875. ));
  876. }
  877. if ($i != 0){ return $gotCalendar; }
  878. }
  879. function getRadarrCalendar($array,$number, $url){
  880. $array = json_decode($array, true);
  881. $gotCalendar = array();
  882. $i = 0;
  883. foreach($array AS $child) {
  884. if(isset($child['physicalRelease'])){
  885. $i++;
  886. $movieName = $child['title'];
  887. $movieID = $child['tmdbId'];
  888. if(!isset($movieID)){ $movieID = ""; }
  889. $physicalRelease = $child['physicalRelease'];
  890. $physicalRelease = strtotime($physicalRelease);
  891. $physicalRelease = date("Y-m-d", $physicalRelease);
  892. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  893. $downloaded = $child['hasFile'];
  894. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
  895. $banner = "/plugins/images/cache/no-np.png";
  896. foreach ($child['images'] as $image) {
  897. if($image['coverType'] == "banner") {
  898. $url = rtrim($url, '/'); //remove trailing slash
  899. $imageUrl = $image['url'];
  900. $urlParts = explode("/", $url);
  901. $imageParts = explode("/", $image['url']);
  902. if ($imageParts[1] == end($urlParts)) {
  903. unset($imageParts[1]);
  904. $imageUrl = implode("/", $imageParts);
  905. }
  906. $banner = $url . $imageUrl;
  907. }
  908. }
  909. if($banner !== "/plugins/images/cache/no-np.png"){
  910. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  911. $imageURL = $banner;
  912. $cacheFile = $cacheDirectory.$movieID.'.jpg';
  913. $banner = 'plugins/images/cache/'.$movieID.'.jpg';
  914. if(!file_exists($cacheFile)){
  915. cacheImage($imageURL,$movieID);
  916. unset($imageURL);
  917. unset($cacheFile);
  918. }
  919. }
  920. $alternativeTitles = "";
  921. foreach ($child['alternativeTitles'] as $alternative) {
  922. $alternativeTitles .= $alternative['title'] . ', ';
  923. }
  924. $alternativeTitles = empty($child['alternativeTitles']) ? "" : substr($alternativeTitles, 0, -2);
  925. $details = array(
  926. "topTitle" => $movieName,
  927. "bottomTitle" => $alternativeTitles,
  928. "status" => $child['status'],
  929. "overview" => $child['overview'],
  930. "runtime" => $child['runtime'],
  931. "image" => $banner,
  932. "ratings" => $child['ratings']['value'],
  933. "videoQuality" => $child["hasFile"] ? $child['movieFile']['quality']['quality']['name'] : "unknown",
  934. "audioChannels" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioChannels'] : "unknown",
  935. "audioCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioFormat'] : "unknown",
  936. "videoCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['videoCodec'] : "unknown",
  937. "size" => $child["hasFile"] ? $child['movieFile']['size'] : "unknown",
  938. "genres" => $child['genres'],
  939. );
  940. array_push($gotCalendar, array(
  941. "id" => "Radarr-".$number."-".$i,
  942. "title" => $movieName,
  943. "start" => $physicalRelease,
  944. "className" => "bg-calendar movieID--".$movieID,
  945. "imagetype" => "film ".$downloaded,
  946. "details" => $details
  947. ));
  948. }
  949. }
  950. if ($i != 0){ return $gotCalendar; }
  951. }
  952. function getCouchCalendar($array,$number){
  953. $api = json_decode($array, true);
  954. $gotCalendar = array();
  955. $i = 0;
  956. foreach($api['movies'] AS $child) {
  957. if($child['status'] == "active" || $child['status'] == "done" ){
  958. $i++;
  959. $movieName = $child['info']['original_title'];
  960. $movieID = $child['info']['tmdb_id'];
  961. if(!isset($movieID)){ $movieID = ""; }
  962. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  963. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  964. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  965. $physicalRelease = strtotime($physicalRelease);
  966. $physicalRelease = date("Y-m-d", $physicalRelease);
  967. if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
  968. $downloaded = ($child['status'] == "active") ? "0" : "1";
  969. if($downloaded == "0" && $notReleased == "true"){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
  970. array_push($gotCalendar, array(
  971. "id" => "CouchPotato-".$number."-".$i,
  972. "title" => $movieName,
  973. "start" => $physicalRelease,
  974. "className" => "bg-calendar calendar-item movieID--".$movieID,
  975. "imagetype" => "film ".$downloaded,
  976. ));
  977. }
  978. }
  979. if ($i != 0){ return $gotCalendar; }
  980. }
  981. function getSickrageCalendarWanted($array,$number){
  982. $array = json_decode($array, true);
  983. $gotCalendar = array();
  984. $i = 0;
  985. foreach($array['data']['missed'] AS $child) {
  986. $i++;
  987. $seriesName = $child['show_name'];
  988. $episodeID = $child['tvdbid'];
  989. $episodeAirDate = $child['airdate'];
  990. $episodeAirDateTime = explode(" ",$child['airs']);
  991. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  992. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  993. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  994. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  995. $downloaded = "0";
  996. if($downloaded == "0" && isset($unaired)){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success";}else{ $downloaded = "text-danger"; }
  997. array_push($gotCalendar, array(
  998. "id" => "Sick-".$number."-Miss-".$i,
  999. "title" => $seriesName,
  1000. "start" => $episodeAirDate,
  1001. "className" => "bg-calendar calendar-item tvID--".$episodeID,
  1002. "imagetype" => "tv ".$downloaded,
  1003. ));
  1004. }
  1005. foreach($array['data']['today'] AS $child) {
  1006. $i++;
  1007. $seriesName = $child['show_name'];
  1008. $episodeID = $child['tvdbid'];
  1009. $episodeAirDate = $child['airdate'];
  1010. $episodeAirDateTime = explode(" ",$child['airs']);
  1011. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1012. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1013. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1014. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1015. $downloaded = "0";
  1016. if($downloaded == "0" && isset($unaired)){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success";}else{ $downloaded = "text-danger"; }
  1017. array_push($gotCalendar, array(
  1018. "id" => "Sick-".$number."-Today-".$i,
  1019. "title" => $seriesName,
  1020. "start" => $episodeAirDate,
  1021. "className" => "bg-calendar calendar-item tvID--".$episodeID,
  1022. "imagetype" => "tv ".$downloaded,
  1023. ));
  1024. }
  1025. foreach($array['data']['soon'] AS $child) {
  1026. $i++;
  1027. $seriesName = $child['show_name'];
  1028. $episodeID = $child['tvdbid'];
  1029. $episodeAirDate = $child['airdate'];
  1030. $episodeAirDateTime = explode(" ",$child['airs']);
  1031. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1032. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1033. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1034. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1035. $downloaded = "0";
  1036. if($downloaded == "0" && isset($unaired)){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success";}else{ $downloaded = "text-danger"; }
  1037. array_push($gotCalendar, array(
  1038. "id" => "Sick-".$number."-Soon-".$i,
  1039. "title" => $seriesName,
  1040. "start" => $episodeAirDate,
  1041. "className" => "bg-calendar calendar-item tvID--".$episodeID,
  1042. "imagetype" => "tv ".$downloaded,
  1043. ));
  1044. }
  1045. foreach($array['data']['later'] AS $child) {
  1046. $i++;
  1047. $seriesName = $child['show_name'];
  1048. $episodeID = $child['tvdbid'];
  1049. $episodeAirDate = $child['airdate'];
  1050. $episodeAirDateTime = explode(" ",$child['airs']);
  1051. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1].$episodeAirDateTime[2]));
  1052. $episodeAirDate = strtotime($episodeAirDate.$episodeAirDateTime);
  1053. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1054. if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
  1055. $downloaded = "0";
  1056. if($downloaded == "0" && isset($unaired)){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success";}else{ $downloaded = "text-danger"; }
  1057. array_push($gotCalendar, array(
  1058. "id" => "Sick-".$number."-Later-".$i,
  1059. "title" => $seriesName,
  1060. "start" => $episodeAirDate,
  1061. "className" => "bg-calendar calendar-item tvID--".$episodeID,
  1062. "imagetype" => "tv ".$downloaded,
  1063. ));
  1064. }
  1065. if ($i != 0){ return $gotCalendar; }
  1066. }
  1067. function getSickrageCalendarHistory($array,$number){
  1068. $array = json_decode($array, true);
  1069. $gotCalendar = array();
  1070. $i = 0;
  1071. foreach($array['data'] AS $child) {
  1072. $i++;
  1073. $seriesName = $child['show_name'];
  1074. $episodeID = $child['tvdbid'];
  1075. $episodeAirDate = $child['date'];
  1076. $downloaded = "text-success";
  1077. array_push($gotCalendar, array(
  1078. "id" => "Sick-".$number."-History-".$i,
  1079. "title" => $seriesName,
  1080. "start" => $episodeAirDate,
  1081. "className" => "bg-calendar calendar-item tvID--".$episodeID,
  1082. "imagetype" => "tv ".$downloaded,
  1083. ));
  1084. }
  1085. if ($i != 0){ return $gotCalendar; }
  1086. }
  1087. function ombiAPI($array){
  1088. return ombiAction($array['data']['id'],$array['data']['action'],$array['data']['type']);
  1089. }
  1090. function ombiAction($id, $action, $type) {
  1091. if($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])){
  1092. $url = qualifyURL($GLOBALS['ombiURL']);
  1093. $headers = array(
  1094. "Accept" => "application/json",
  1095. "Content-Type" => "application/json",
  1096. "Apikey" => $GLOBALS['ombiToken']
  1097. );
  1098. $data = array(
  1099. 'id' => $id,
  1100. );
  1101. switch ($type) {
  1102. case 'season':
  1103. case 'tv':
  1104. $type = 'tv';
  1105. $add = array(
  1106. 'tvDbId' => $id,
  1107. 'requestAll' => true,
  1108. 'latestSeason' => true,
  1109. 'firstSeason' => true
  1110. );
  1111. break;
  1112. default:
  1113. $type = 'movie';
  1114. $add = array("theMovieDbId" => (int)$id);
  1115. break;
  1116. }
  1117. $success['head'] = $headers;
  1118. $success['act'] = $action;
  1119. $success['data'] = $data;
  1120. $success['add'] = $add;
  1121. $success['type'] = $type;
  1122. try{
  1123. $options = (localURL($url)) ? array('verify' => false ) : array();
  1124. switch ($action) {
  1125. case 'add':
  1126. if(isset($_COOKIE['Auth'])){
  1127. $headers = array(
  1128. "Accept" => "application/json",
  1129. "Content-Type" => "application/json",
  1130. "Authorization" => "Bearer ".$_COOKIE['Auth']
  1131. );
  1132. $success['head'] = $headers;
  1133. }else{
  1134. return false;
  1135. }
  1136. $response = Requests::post($url."/api/v1/Request/".$type, $headers, json_encode($add), $options);
  1137. break;
  1138. default:
  1139. if(qualifyRequest(1)){
  1140. switch ($action) {
  1141. case 'approve':
  1142. $response = Requests::post($url."/api/v1/Request/".$type."/approve", $headers, json_encode($data), $options);
  1143. break;
  1144. case 'available':
  1145. $response = Requests::post($url."/api/v1/Request/".$type."/available", $headers, json_encode($data), $options);
  1146. break;
  1147. case 'unavailable':
  1148. $response = Requests::post($url."/api/v1/Request/".$type."/unavailable", $headers, json_encode($data), $options);
  1149. break;
  1150. case 'deny':
  1151. $response = Requests::put($url."/api/v1/Request/".$type."/deny", $headers, json_encode($data), $options);
  1152. break;
  1153. case 'delete':
  1154. $response = Requests::delete($url."/api/v1/Request/".$type."/".$id, $headers, $options);
  1155. break;
  1156. default:
  1157. return false;
  1158. }
  1159. }
  1160. break;
  1161. }
  1162. $success['api'] = $response;
  1163. $success['bd'] = $response->body;
  1164. $success['hd'] = $response->headers;
  1165. if($response->success){
  1166. $success['ok'] = true;
  1167. }
  1168. }catch( Requests_Exception $e ) {
  1169. writeLog('error', 'OMBI Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  1170. };
  1171. }
  1172. $api['content'] = isset($success) ? $success : false;
  1173. return $api;
  1174. }
  1175. function getOmbiRequests($type = "both"){
  1176. if($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])){
  1177. $url = qualifyURL($GLOBALS['ombiURL']);
  1178. $headers = array(
  1179. "Accept" => "application/json",
  1180. "Apikey" => $GLOBALS['ombiToken'],
  1181. );
  1182. $requests = array();
  1183. try{
  1184. $options = (localURL($url)) ? array('verify' => false ) : array();
  1185. switch ($type) {
  1186. case 'movie':
  1187. $movie = Requests::get($url."/api/v1/Request/movie", $headers, $options);
  1188. break;
  1189. case 'tv':
  1190. $tv = Requests::get($url."/api/v1/Request/tv", $headers, $options);
  1191. break;
  1192. default:
  1193. $movie = Requests::get($url."/api/v1/Request/movie", $headers, $options);
  1194. $tv = Requests::get($url."/api/v1/Request/tv", $headers, $options);
  1195. break;
  1196. }
  1197. if($movie->success || $tv->success){
  1198. if(isset($movie)){
  1199. $movie = json_decode($movie->body, true);
  1200. //$movie = array_reverse($movie);
  1201. foreach ($movie as $key => $value) {
  1202. $requests[] = array(
  1203. 'test' => $value,
  1204. 'id' => $value['theMovieDbId'],
  1205. 'title' => $value['title'],
  1206. 'overview' => $value['overview'],
  1207. 'poster' => (isset($value['posterPath']) && $value['posterPath'] !== '') ? 'https://image.tmdb.org/t/p/w300/'.$value['posterPath'] : '',
  1208. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/'.$value['background'] : '',
  1209. 'approved' => $value['approved'],
  1210. 'available' => $value['available'],
  1211. 'denied' => $value['denied'],
  1212. 'deniedReason' => $value['deniedReason'],
  1213. 'user' => $value['requestedUser']['userName'],
  1214. 'request_id' => $value['id'],
  1215. 'request_date' => $value['requestedDate'],
  1216. 'release_date' => $value['releaseDate'],
  1217. 'type' => 'movie',
  1218. 'icon' => 'mdi mdi-filmstrip',
  1219. 'color' => 'palette-Deep-Purple-900 bg white',
  1220. );
  1221. }
  1222. }
  1223. if(isset($tv) && (is_array($tv) || is_object($tv))){
  1224. $tv = json_decode($tv->body, true);
  1225. foreach ($tv as $key => $value) {
  1226. if(is_array($value['childRequests'][0])){
  1227. $requests[] = array(
  1228. 'test' => $value,
  1229. 'id' => $value['tvDbId'],
  1230. 'title' => $value['title'],
  1231. 'overview' => $value['overview'],
  1232. 'poster' => $value['posterPath'],
  1233. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/'.$value['background'] : '',
  1234. 'approved' => $value['childRequests'][0]['approved'],
  1235. 'available' => $value['childRequests'][0]['available'],
  1236. 'denied' => $value['childRequests'][0]['denied'],
  1237. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  1238. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  1239. 'request_id' => $value['id'],
  1240. 'request_date' => $value['childRequests'][0]['requestedDate'],
  1241. 'release_date' => $value['releaseDate'],
  1242. 'type' => 'tv',
  1243. 'icon' => 'mdi mdi-television',
  1244. 'color' => 'grayish-blue-bg',
  1245. );
  1246. }
  1247. }
  1248. }
  1249. //sort here
  1250. usort($requests, function ($item1, $item2) {
  1251. if ($item1['request_date'] == $item2['request_date']) return 0;
  1252. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  1253. });
  1254. }
  1255. }catch( Requests_Exception $e ) {
  1256. writeLog('error', 'OMBI Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  1257. };
  1258. }
  1259. $api['content'] = isset($requests) ? $requests : false;
  1260. return $api;
  1261. }