homepage-connect-functions.php 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. <?php
  2. /** @noinspection PhpUndefinedFieldInspection */
  3. function homepageConnect($array)
  4. {
  5. switch ($array['data']['action']) {
  6. case 'getPlexStreams':
  7. return (qualifyRequest($GLOBALS['homepagePlexStreamsAuth'])) ? plexConnect('streams') : false;
  8. break;
  9. case 'getPlexRecent':
  10. return (qualifyRequest($GLOBALS['homepagePlexRecentAuth'])) ? plexConnect('recent') : false;
  11. break;
  12. case 'getPlexMetadata':
  13. return (qualifyRequest($GLOBALS['homepagePlexAuth'])) ? plexConnect('metadata', $array['data']['key']) : false;
  14. break;
  15. case 'getPlexSearch':
  16. return (qualifyRequest($GLOBALS['mediaSearchAuth'])) ? plexConnect('search', $array['data']['query']) : false;
  17. break;
  18. case 'getPlexPlaylists':
  19. return (qualifyRequest($GLOBALS['homepagePlexPlaylistAuth'])) ? getPlexPlaylists() : false;
  20. break;
  21. case 'getEmbyStreams':
  22. return (qualifyRequest($GLOBALS['homepageEmbyStreamsAuth'])) ? embyConnect('streams') : false;
  23. break;
  24. case 'getEmbyRecent':
  25. return (qualifyRequest($GLOBALS['homepageEmbyRecentAuth'])) ? embyConnect('recent') : false;
  26. break;
  27. case 'getEmbyMetadata':
  28. return (qualifyRequest($GLOBALS['homepageEmbyAuth'])) ? embyConnect('metadata', $array['data']['key'], true) : false;
  29. break;
  30. case 'getSabnzbd':
  31. return sabnzbdConnect();
  32. break;
  33. case 'getNzbget':
  34. return nzbgetConnect();
  35. break;
  36. case 'getTransmission':
  37. return transmissionConnect();
  38. break;
  39. case 'getqBittorrent':
  40. return qBittorrentConnect();
  41. break;
  42. case 'getDeluge':
  43. return delugeConnect();
  44. break;
  45. case 'getCalendar':
  46. return getCalendar();
  47. break;
  48. case 'getRequests':
  49. return getOmbiRequests();
  50. break;
  51. default:
  52. # code...
  53. break;
  54. }
  55. return false;
  56. }
  57. function streamType($value)
  58. {
  59. if ($value == "transcode" || $value == "Transcode") {
  60. return "Transcode";
  61. } elseif ($value == "copy" || $value == "DirectStream") {
  62. return "Direct Stream";
  63. } elseif ($value == "directplay" || $value == "DirectPlay") {
  64. return "Direct Play";
  65. } else {
  66. return "Direct Play";
  67. }
  68. }
  69. function resolveEmbyItem($itemDetails)
  70. {
  71. // Grab Each item info from Emby (extra call)
  72. $id = isset($itemDetails['NowPlayingItem']['Id']) ? $itemDetails['NowPlayingItem']['Id'] : $itemDetails['Id'];
  73. $url = qualifyURL($GLOBALS['embyURL']);
  74. $url = $url . '/Items?Ids=' . $id . '&api_key=' . $GLOBALS['embyToken'] . '&Fields=Overview,People,Genres,CriticRating,Studios,Taglines';
  75. try {
  76. $options = (localURL($url)) ? array('verify' => false) : array();
  77. $response = Requests::get($url, array(), $options);
  78. if ($response->success) {
  79. $item = json_decode($response->body, true)['Items'][0];
  80. }
  81. } catch (Requests_Exception $e) {
  82. return false;
  83. };
  84. // Static Height & Width
  85. $height = 300;
  86. $width = 200;
  87. $nowPlayingHeight = 675;
  88. $nowPlayingWidth = 1200;
  89. $actorHeight = 450;
  90. $actorWidth = 300;
  91. // Cache Directories
  92. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  93. $cacheDirectoryWeb = 'plugins/images/cache/';
  94. // Types
  95. $embyItem['array-item'] = $item;
  96. $embyItem['array-itemdetails'] = $itemDetails;
  97. switch (@$item['Type']) {
  98. case 'Series':
  99. $embyItem['type'] = 'tv';
  100. $embyItem['title'] = $item['Name'];
  101. $embyItem['summary'] = '';
  102. $embyItem['ratingKey'] = $item['Id'];
  103. $embyItem['thumb'] = $item['Id'];
  104. $embyItem['key'] = $item['Id'] . "-list";
  105. $embyItem['nowPlayingThumb'] = $item['Id'];
  106. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  107. $embyItem['metadataKey'] = $item['Id'];
  108. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['BackdropImageTags'][0]) ? 'Backdrop' : '');
  109. break;
  110. case 'Episode':
  111. $embyItem['type'] = 'tv';
  112. $embyItem['title'] = $item['SeriesName'];
  113. $embyItem['summary'] = '';
  114. $embyItem['ratingKey'] = $item['Id'];
  115. $embyItem['thumb'] = (isset($item['SeriesId']) ? $item['SeriesId'] : $item['Id']);
  116. $embyItem['key'] = (isset($item['SeriesId']) ? $item['SeriesId'] : $item['Id']) . "-list";
  117. $embyItem['nowPlayingThumb'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'] : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'] : false);
  118. $embyItem['nowPlayingKey'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'] . '-np' : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'] . '-np' : false);
  119. $embyItem['metadataKey'] = $item['Id'];
  120. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['ParentBackdropImageTags'][0]) ? 'Backdrop' : '');
  121. $embyItem['nowPlayingTitle'] = @$item['SeriesName'] . ' - ' . @$item['Name'];
  122. $embyItem['nowPlayingBottom'] = 'S' . @$item['ParentIndexNumber'] . ' · E' . @$item['IndexNumber'];
  123. break;
  124. case 'MusicAlbum':
  125. case 'Audio':
  126. $embyItem['type'] = 'music';
  127. $embyItem['title'] = $item['Name'];
  128. $embyItem['summary'] = '';
  129. $embyItem['ratingKey'] = $item['Id'];
  130. $embyItem['thumb'] = $item['Id'];
  131. $embyItem['key'] = $item['Id'] . "-list";
  132. $embyItem['nowPlayingThumb'] = (isset($item['AlbumId']) ? $item['AlbumId'] : @$item['ParentBackdropItemId']);
  133. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  134. $embyItem['metadataKey'] = isset($item['AlbumId']) ? $item['AlbumId'] : $item['Id'];
  135. $embyItem['nowPlayingImageType'] = (isset($item['ParentBackdropItemId']) ? "Primary" : "Backdrop");
  136. $embyItem['nowPlayingTitle'] = @$item['AlbumArtist'] . ' - ' . @$item['Name'];
  137. $embyItem['nowPlayingBottom'] = @$item['Album'];
  138. break;
  139. case 'Movie':
  140. $embyItem['type'] = 'movie';
  141. $embyItem['title'] = $item['Name'];
  142. $embyItem['summary'] = '';
  143. $embyItem['ratingKey'] = $item['Id'];
  144. $embyItem['thumb'] = $item['Id'];
  145. $embyItem['key'] = $item['Id'] . "-list";
  146. $embyItem['nowPlayingThumb'] = $item['Id'];
  147. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  148. $embyItem['metadataKey'] = $item['Id'];
  149. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
  150. $embyItem['nowPlayingTitle'] = @$item['Name'];
  151. $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
  152. break;
  153. case 'Video':
  154. $embyItem['type'] = 'video';
  155. $embyItem['title'] = $item['Name'];
  156. $embyItem['summary'] = '';
  157. $embyItem['ratingKey'] = $item['Id'];
  158. $embyItem['thumb'] = $item['Id'];
  159. $embyItem['key'] = $item['Id'] . "-list";
  160. $embyItem['nowPlayingThumb'] = $item['Id'];
  161. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  162. $embyItem['metadataKey'] = $item['Id'];
  163. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
  164. $embyItem['nowPlayingTitle'] = @$item['Name'];
  165. $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
  166. break;
  167. default:
  168. return false;
  169. }
  170. $embyItem['uid'] = $item['Id'];
  171. $embyItem['imageType'] = (isset($item['ImageTags']['Primary']) ? "Primary" : false);
  172. $embyItem['elapsed'] = isset($itemDetails['PlayState']['PositionTicks']) && $itemDetails['PlayState']['PositionTicks'] !== '0' ? (int)$itemDetails['PlayState']['PositionTicks'] : null;
  173. $embyItem['duration'] = isset($itemDetails['NowPlayingItem']['RunTimeTicks']) ? (int)$itemDetails['NowPlayingItem']['RunTimeTicks'] : (int)(isset($item['RunTimeTicks']) ? $item['RunTimeTicks'] : '');
  174. $embyItem['watched'] = ($embyItem['elapsed'] && $embyItem['duration'] ? floor(($embyItem['elapsed'] / $embyItem['duration']) * 100) : 0);
  175. $embyItem['transcoded'] = isset($itemDetails['TranscodingInfo']['CompletionPercentage']) ? floor((int)$itemDetails['TranscodingInfo']['CompletionPercentage']) : 100;
  176. $embyItem['stream'] = @$itemDetails['PlayState']['PlayMethod'];
  177. $embyItem['id'] = $item['ServerId'];
  178. $embyItem['session'] = @$itemDetails['DeviceId'];
  179. $embyItem['bandwidth'] = isset($itemDetails['TranscodingInfo']['Bitrate']) ? $itemDetails['TranscodingInfo']['Bitrate'] / 1000 : '';
  180. $embyItem['bandwidthType'] = 'wan';
  181. $embyItem['sessionType'] = (@$itemDetails['PlayState']['PlayMethod'] == 'Transcode') ? 'Transcoding' : 'Direct Playing';
  182. $embyItem['state'] = ((@(string)$itemDetails['PlayState']['IsPaused'] == '1') ? "pause" : "play");
  183. $embyItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? @(string)$itemDetails['UserName'] : "";
  184. $embyItem['userThumb'] = '';
  185. $embyItem['userAddress'] = (isset($itemDetails['RemoteEndPoint']) ? $itemDetails['RemoteEndPoint'] : "x.x.x.x");
  186. $embyItem['address'] = $GLOBALS['embyTabURL'] ? '' : '';
  187. $embyItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=emby&type=' . $embyItem['nowPlayingImageType'] . '&img=' . $embyItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $embyItem['nowPlayingKey'] . '$' . randString();
  188. $embyItem['originalImage'] = 'api/?v1/image&source=emby&type=' . $embyItem['imageType'] . '&img=' . $embyItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $embyItem['key'] . '$' . randString();
  189. $embyItem['openTab'] = $GLOBALS['embyTabURL'] && $GLOBALS['embyTabName'] ? true : false;
  190. $embyItem['tabName'] = $GLOBALS['embyTabName'] ? $GLOBALS['embyTabName'] : '';
  191. // Stream info
  192. $embyItem['userStream'] = array(
  193. 'platform' => @(string)$itemDetails['Client'],
  194. 'product' => @(string)$itemDetails['Client'],
  195. 'device' => @(string)$itemDetails['DeviceName'],
  196. 'stream' => @$itemDetails['PlayState']['PlayMethod'],
  197. 'videoResolution' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]['Width']) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Width'] : '',
  198. 'throttled' => false,
  199. 'sourceVideoCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : '',
  200. 'videoCodec' => @$itemDetails['TranscodingInfo']['VideoCodec'],
  201. 'audioCodec' => @$itemDetails['TranscodingInfo']['AudioCodec'],
  202. 'sourceAudioCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][1]) ? $itemDetails['NowPlayingItem']['MediaStreams'][1]['Codec'] : (isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : ''),
  203. 'videoDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
  204. 'audioDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
  205. 'container' => isset($itemDetails['NowPlayingItem']['Container']) ? $itemDetails['NowPlayingItem']['Container'] : '',
  206. 'audioChannels' => @$itemDetails['TranscodingInfo']['AudioChannels']
  207. );
  208. // Genre catch all
  209. if ($item['Genres']) {
  210. $genres = array();
  211. foreach ($item['Genres'] as $genre) {
  212. $genres[] = $genre;
  213. }
  214. }
  215. // Actor catch all
  216. if ($item['People']) {
  217. $actors = array();
  218. foreach ($item['People'] as $key => $value) {
  219. if (@$value['PrimaryImageTag'] && @$value['Role']) {
  220. if (file_exists($cacheDirectory . (string)$value['Id'] . '-cast.jpg')) {
  221. $actorImage = $cacheDirectoryWeb . (string)$value['Id'] . '-cast.jpg';
  222. }
  223. 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')) {
  224. $actorImage = 'api/?v1/image&source=emby&type=Primary&img=' . (string)$value['Id'] . '&height=' . $actorHeight . '&width=' . $actorWidth . '&key=' . (string)$value['Id'] . '-cast';
  225. }
  226. $actors[] = array(
  227. 'name' => (string)$value['Name'],
  228. 'role' => (string)$value['Role'],
  229. 'thumb' => $actorImage
  230. );
  231. }
  232. }
  233. }
  234. // Metadata information
  235. $embyItem['metadata'] = array(
  236. 'guid' => $item['Id'],
  237. 'summary' => @(string)$item['Overview'],
  238. 'rating' => @(string)$item['CommunityRating'],
  239. 'duration' => @(string)$item['RunTimeTicks'],
  240. 'originallyAvailableAt' => @(string)$item['PremiereDate'],
  241. 'year' => (string)isset($item['ProductionYear']) ? $item['ProductionYear'] : '',
  242. //'studio' => (string)$item['studio'],
  243. 'tagline' => @(string)$item['Taglines'][0],
  244. 'genres' => ($item['Genres']) ? $genres : '',
  245. 'actors' => ($item['People']) ? $actors : ''
  246. );
  247. if (file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg')) {
  248. $embyItem['nowPlayingImageURL'] = $cacheDirectoryWeb . $embyItem['nowPlayingKey'] . '.jpg';
  249. }
  250. if (file_exists($cacheDirectory . $embyItem['key'] . '.jpg')) {
  251. $embyItem['imageURL'] = $cacheDirectoryWeb . $embyItem['key'] . '.jpg';
  252. }
  253. if (file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg') || !file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg')) {
  254. $embyItem['nowPlayingImageURL'] = 'api/?v1/image&source=emby&type=' . $embyItem['nowPlayingImageType'] . '&img=' . $embyItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $embyItem['nowPlayingKey'] . '';
  255. }
  256. if (file_exists($cacheDirectory . $embyItem['key'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $embyItem['key'] . '.jpg') || !file_exists($cacheDirectory . $embyItem['key'] . '.jpg')) {
  257. $embyItem['imageURL'] = 'api/?v1/image&source=emby&type=' . $embyItem['imageType'] . '&img=' . $embyItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $embyItem['key'] . '';
  258. }
  259. if (!$embyItem['nowPlayingThumb']) {
  260. $embyItem['nowPlayingOriginalImage'] = $embyItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png";
  261. $embyItem['nowPlayingKey'] = "no-np";
  262. }
  263. if (!$embyItem['thumb']) {
  264. $embyItem['originalImage'] = $embyItem['imageURL'] = "plugins/images/cache/no-list.png";
  265. $embyItem['key'] = "no-list";
  266. }
  267. if (isset($useImage)) {
  268. $embyItem['useImage'] = $useImage;
  269. }
  270. return $embyItem;
  271. }
  272. function resolvePlexItem($item)
  273. {
  274. // Static Height & Width
  275. $height = 300;
  276. $width = 200;
  277. $nowPlayingHeight = 675;
  278. $nowPlayingWidth = 1200;
  279. // Cache Directories
  280. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  281. $cacheDirectoryWeb = 'plugins/images/cache/';
  282. // Types
  283. switch ($item['type']) {
  284. case 'season':
  285. $plexItem['type'] = 'tv';
  286. $plexItem['title'] = (string)$item['parentTitle'];
  287. $plexItem['summary'] = (string)$item['parentSummary'];
  288. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  289. $plexItem['thumb'] = (string)$item['thumb'];
  290. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  291. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  292. $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
  293. $plexItem['metadataKey'] = (string)$item['parentRatingKey'];
  294. break;
  295. case 'episode':
  296. $plexItem['type'] = 'tv';
  297. $plexItem['title'] = (string)$item['grandparentTitle'];
  298. $plexItem['summary'] = (string)$item['title'];
  299. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  300. $plexItem['thumb'] = ($item['parentThumb'] ? (string)$item['parentThumb'] : (string)$item['grandparentThumb']);
  301. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  302. $plexItem['nowPlayingThumb'] = (string)$item['grandparentArt'];
  303. $plexItem['nowPlayingKey'] = (string)$item['grandparentRatingKey'] . "-np";
  304. $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'] . ' - ' . (string)$item['title'];
  305. $plexItem['nowPlayingBottom'] = 'S' . (string)$item['parentIndex'] . ' · E' . (string)$item['index'];
  306. $plexItem['metadataKey'] = (string)$item['grandparentRatingKey'];
  307. break;
  308. case 'clip':
  309. $useImage = (isset($item['live']) ? "plugins/images/cache/livetv.png" : null);
  310. $plexItem['type'] = 'clip';
  311. $plexItem['title'] = (string)$item['title'];
  312. $plexItem['summary'] = (string)$item['summary'];
  313. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  314. $plexItem['thumb'] = (string)$item['thumb'];
  315. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  316. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  317. $plexItem['nowPlayingKey'] = isset($item['ratingKey']) ? (string)$item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  318. $plexItem['nowPlayingTitle'] = $plexItem['title'];
  319. $plexItem['nowPlayingBottom'] = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  320. break;
  321. case 'album':
  322. case 'track':
  323. $plexItem['type'] = 'music';
  324. $plexItem['title'] = (string)$item['parentTitle'] . ' - ' . (string)$item['title'];
  325. $plexItem['summary'] = (string)$item['title'];
  326. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  327. $plexItem['thumb'] = (string)$item['thumb'];
  328. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  329. $plexItem['nowPlayingThumb'] = ($item['parentThumb']) ? (string)$item['parentThumb'] : (string)$item['art'];
  330. $plexItem['nowPlayingKey'] = (string)$item['parentRatingKey'] . "-np";
  331. $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'] . ' - ' . (string)$item['title'];
  332. $plexItem['nowPlayingBottom'] = (string)$item['parentTitle'];
  333. $plexItem['metadataKey'] = isset($item['grandparentRatingKey']) ? (string)$item['grandparentRatingKey'] : (string)$item['parentRatingKey'];
  334. break;
  335. default:
  336. $plexItem['type'] = 'movie';
  337. $plexItem['title'] = (string)$item['title'];
  338. $plexItem['summary'] = (string)$item['summary'];
  339. $plexItem['ratingKey'] = (string)$item['ratingKey'];
  340. $plexItem['thumb'] = (string)$item['thumb'];
  341. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  342. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  343. $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
  344. $plexItem['nowPlayingTitle'] = (string)$item['title'];
  345. $plexItem['nowPlayingBottom'] = (string)$item['year'];
  346. $plexItem['metadataKey'] = (string)$item['ratingKey'];
  347. }
  348. $plexItem['uid'] = (string)$item['ratingKey'];
  349. $plexItem['elapsed'] = isset($item['viewOffset']) && $item['viewOffset'] !== '0' ? (int)$item['viewOffset'] : null;
  350. $plexItem['duration'] = isset($item['duration']) ? (int)$item['duration'] : (int)$item->Media['duration'];
  351. $plexItem['watched'] = ($plexItem['elapsed'] && $plexItem['duration'] ? floor(($plexItem['elapsed'] / $plexItem['duration']) * 100) : 0);
  352. $plexItem['transcoded'] = isset($item->TranscodeSession['progress']) ? floor((int)$item->TranscodeSession['progress'] - $plexItem['watched']) : '';
  353. $plexItem['stream'] = isset($item->Media->Part->Stream['decision']) ? (string)$item->Media->Part->Stream['decision'] : '';
  354. $plexItem['id'] = str_replace('"', '', (string)$item->Player['machineIdentifier']);
  355. $plexItem['session'] = (string)$item->Session['id'];
  356. $plexItem['bandwidth'] = (string)$item->Session['bandwidth'];
  357. $plexItem['bandwidthType'] = (string)$item->Session['location'];
  358. $plexItem['sessionType'] = isset($item->TranscodeSession['progress']) ? 'Transcoding' : 'Direct Playing';
  359. $plexItem['state'] = (((string)$item->Player['state'] == "paused") ? "pause" : "play");
  360. $plexItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? (string)$item->User['title'] : "";
  361. $plexItem['userThumb'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? (string)$item->User['thumb'] : "";
  362. $plexItem['userAddress'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? (string)$item->Player['address'] : "x.x.x.x";
  363. $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'];
  364. $plexItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=plex&img=' . $plexItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $plexItem['nowPlayingKey'] . '$' . randString();
  365. $plexItem['originalImage'] = 'api/?v1/image&source=plex&img=' . $plexItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $plexItem['key'] . '$' . randString();
  366. $plexItem['openTab'] = $GLOBALS['plexTabURL'] && $GLOBALS['plexTabName'] ? true : false;
  367. $plexItem['tabName'] = $GLOBALS['plexTabName'] ? $GLOBALS['plexTabName'] : '';
  368. // Stream info
  369. $plexItem['userStream'] = array(
  370. 'platform' => (string)$item->Player['platform'],
  371. 'product' => (string)$item->Player['product'],
  372. 'device' => (string)$item->Player['device'],
  373. 'stream' => (string)$item->Media->Part['decision'] . ($item->TranscodeSession['throttled'] == '1' ? ' (Throttled)' : ''),
  374. 'videoResolution' => (string)$item->Media['videoResolution'],
  375. 'throttled' => ($item->TranscodeSession['throttled'] == 1) ? true : false,
  376. 'sourceVideoCodec' => (string)$item->TranscodeSession['sourceVideoCodec'],
  377. 'videoCodec' => (string)$item->TranscodeSession['videoCodec'],
  378. 'audioCodec' => (string)$item->TranscodeSession['audioCodec'],
  379. 'sourceAudioCodec' => (string)$item->TranscodeSession['sourceAudioCodec'],
  380. 'videoDecision' => streamType((string)$item->TranscodeSession['videoDecision']),
  381. 'audioDecision' => streamType((string)$item->TranscodeSession['audioDecision']),
  382. 'container' => (string)$item->TranscodeSession['container'],
  383. 'audioChannels' => (string)$item->TranscodeSession['audioChannels']
  384. );
  385. // Genre catch all
  386. if ($item->Genre) {
  387. $genres = array();
  388. foreach ($item->Genre as $key => $value) {
  389. $genres[] = (string)$value['tag'];
  390. }
  391. }
  392. // Actor catch all
  393. if ($item->Role) {
  394. $actors = array();
  395. foreach ($item->Role as $key => $value) {
  396. if ($value['thumb']) {
  397. $actors[] = array(
  398. 'name' => (string)$value['tag'],
  399. 'role' => (string)$value['role'],
  400. 'thumb' => (string)$value['thumb']
  401. );
  402. }
  403. }
  404. }
  405. // Metadata information
  406. $plexItem['metadata'] = array(
  407. 'guid' => (string)$item['guid'],
  408. 'summary' => (string)$item['summary'],
  409. 'rating' => (string)$item['rating'],
  410. 'duration' => (string)$item['duration'],
  411. 'originallyAvailableAt' => (string)$item['originallyAvailableAt'],
  412. 'year' => (string)$item['year'],
  413. 'studio' => (string)$item['studio'],
  414. 'tagline' => (string)$item['tagline'],
  415. 'genres' => ($item->Genre) ? $genres : '',
  416. 'actors' => ($item->Role) ? $actors : ''
  417. );
  418. if (file_exists($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg')) {
  419. $plexItem['nowPlayingImageURL'] = $cacheDirectoryWeb . $plexItem['nowPlayingKey'] . '.jpg';
  420. }
  421. if (file_exists($cacheDirectory . $plexItem['key'] . '.jpg')) {
  422. $plexItem['imageURL'] = $cacheDirectoryWeb . $plexItem['key'] . '.jpg';
  423. }
  424. if (file_exists($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg') || !file_exists($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg')) {
  425. $plexItem['nowPlayingImageURL'] = 'api/?v1/image&source=plex&img=' . $plexItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $plexItem['nowPlayingKey'] . '';
  426. }
  427. if (file_exists($cacheDirectory . $plexItem['key'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $plexItem['key'] . '.jpg') || !file_exists($cacheDirectory . $plexItem['key'] . '.jpg')) {
  428. $plexItem['imageURL'] = 'api/?v1/image&source=plex&img=' . $plexItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $plexItem['key'] . '';
  429. }
  430. if (!$plexItem['nowPlayingThumb']) {
  431. $plexItem['nowPlayingOriginalImage'] = $plexItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png";
  432. $plexItem['nowPlayingKey'] = "no-np";
  433. }
  434. if (!$plexItem['thumb']) {
  435. $plexItem['originalImage'] = $plexItem['imageURL'] = "plugins/images/cache/no-list.png";
  436. $plexItem['key'] = "no-list";
  437. }
  438. if (isset($useImage)) {
  439. $plexItem['useImage'] = $useImage;
  440. }
  441. return $plexItem;
  442. }
  443. function plexConnect($action, $key = null)
  444. {
  445. if ($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']))) {
  446. $url = qualifyURL($GLOBALS['plexURL']);
  447. $ignore = array();
  448. switch ($action) {
  449. case 'streams':
  450. $url = $url . "/status/sessions?X-Plex-Token=" . $GLOBALS['plexToken'];
  451. break;
  452. case 'recent':
  453. $url = $url . "/library/recentlyAdded?X-Plex-Token=" . $GLOBALS['plexToken'] . "&limit=" . $GLOBALS['homepageRecentLimit'];
  454. break;
  455. case 'metadata':
  456. $url = $url . "/library/metadata/" . $key . "?X-Plex-Token=" . $GLOBALS['plexToken'];
  457. break;
  458. case 'playlists':
  459. $url = $url . "/playlists?X-Plex-Token=" . $GLOBALS['plexToken'];
  460. break;
  461. case 'search':
  462. $url = $url . "/search?query=" . rawurlencode($key) . "&X-Plex-Token=" . $GLOBALS['plexToken'];
  463. $ignore = array('artist', 'episode');
  464. break;
  465. default:
  466. # code...
  467. break;
  468. }
  469. try {
  470. $options = (localURL($url)) ? array('verify' => false) : array();
  471. $response = Requests::get($url, array(), $options);
  472. libxml_use_internal_errors(true);
  473. if ($response->success) {
  474. $items = array();
  475. $plex = simplexml_load_string($response->body);
  476. foreach ($plex as $child) {
  477. if (!in_array($child['type'], $ignore) && isset($child['librarySectionID'])) {
  478. $items[] = resolvePlexItem($child);
  479. }
  480. }
  481. $api['content'] = $items;
  482. $api['plexID'] = $GLOBALS['plexID'];
  483. $api['showNames'] = true;
  484. $api['group'] = '1';
  485. return $api;
  486. }
  487. } catch (Requests_Exception $e) {
  488. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  489. };
  490. }
  491. return false;
  492. }
  493. function getPlexPlaylists()
  494. {
  495. if ($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']) && qualifyRequest($GLOBALS['homepagePlexPlaylistAuth']) && $GLOBALS['homepagePlexPlaylist'])) {
  496. $url = qualifyURL($GLOBALS['plexURL']);
  497. $url = $url . "/playlists?X-Plex-Token=" . $GLOBALS['plexToken'];
  498. try {
  499. $options = (localURL($url)) ? array('verify' => false) : array();
  500. $response = Requests::get($url, array(), $options);
  501. libxml_use_internal_errors(true);
  502. if ($response->success) {
  503. $items = array();
  504. $plex = simplexml_load_string($response->body);
  505. foreach ($plex as $child) {
  506. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']), 'private') === false) {
  507. $playlistTitleClean = preg_replace("/(\W)+/", "", (string)$child['title']);
  508. $playlistURL = qualifyURL($GLOBALS['plexURL']);
  509. $playlistURL = $playlistURL . $child['key'] . "?X-Plex-Token=" . $GLOBALS['plexToken'];
  510. $options = (localURL($url)) ? array('verify' => false) : array();
  511. $playlistResponse = Requests::get($playlistURL, array(), $options);
  512. if ($playlistResponse->success) {
  513. $playlistResponse = simplexml_load_string($playlistResponse->body);
  514. $items[$playlistTitleClean]['title'] = (string)$child['title'];
  515. foreach ($playlistResponse->Video as $playlistItem) {
  516. $items[$playlistTitleClean][] = resolvePlexItem($playlistItem);
  517. }
  518. }
  519. }
  520. }
  521. $api['content'] = $items;
  522. $api['plexID'] = $GLOBALS['plexID'];
  523. $api['showNames'] = true;
  524. $api['group'] = '1';
  525. return $api;
  526. }
  527. } catch (Requests_Exception $e) {
  528. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  529. };
  530. }
  531. return false;
  532. }
  533. function embyConnect($action, $key = null, $skip = false)
  534. {
  535. if ($GLOBALS['homepageEmbyEnabled'] && !empty($GLOBALS['embyURL']) && !empty($GLOBALS['embyToken']) && qualifyRequest($GLOBALS['homepageEmbyAuth'])) {
  536. $url = qualifyURL($GLOBALS['embyURL']);
  537. switch ($action) {
  538. case 'streams':
  539. $url = $url . '/Sessions?api_key=' . $GLOBALS['embyToken'];
  540. break;
  541. case 'recent':
  542. $username = false;
  543. if (isset($GLOBALS['organizrUser']['username'])) {
  544. $username = strtolower($GLOBALS['organizrUser']['username']);
  545. }
  546. // Get A User
  547. $userIds = $url . "/Users?api_key=" . $GLOBALS['embyToken'];
  548. $showPlayed = true;
  549. try {
  550. $options = (localURL($userIds)) ? array('verify' => false) : array();
  551. $response = Requests::get($userIds, array(), $options);
  552. if ($response->success) {
  553. $emby = json_decode($response->body, true);
  554. foreach ($emby as $value) { // Scan for admin user
  555. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  556. $userId = $value['Id'];
  557. }
  558. if ($username && strtolower($value['Name']) == $username) {
  559. $userId = $value['Id'];
  560. $showPlayed = false;
  561. break;
  562. }
  563. }
  564. }
  565. } catch (Requests_Exception $e) {
  566. writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  567. };
  568. $url = $url . '/Users/' . $userId . '/Items/Latest?EnableImages=false&Limit=' . $GLOBALS['homepageRecentLimit'] . '&api_key=' . $GLOBALS['embyToken'] . ($showPlayed ? '' : '&IsPlayed=false');
  569. break;
  570. case 'metadata':
  571. $skip = true;
  572. break;
  573. default:
  574. # code...
  575. break;
  576. }
  577. if ($skip && $key) {
  578. $items[] = resolveEmbyItem(array('Id' => $key));
  579. $api['content'] = $items;
  580. return $api;
  581. }
  582. try {
  583. $options = (localURL($url)) ? array('verify' => false) : array();
  584. $response = Requests::get($url, array(), $options);
  585. if ($response->success) {
  586. $items = array();
  587. $emby = json_decode($response->body, true);
  588. foreach ($emby as $child) {
  589. if (isset($child['NowPlayingItem']) || isset($child['Name'])) {
  590. $items[] = resolveEmbyItem($child);
  591. }
  592. }
  593. $api['content'] = array_filter($items);
  594. return $api;
  595. }
  596. } catch (Requests_Exception $e) {
  597. writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  598. };
  599. }
  600. return false;
  601. }
  602. function sabnzbdConnect()
  603. {
  604. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  605. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  606. $url = $url . '/api?mode=queue&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  607. try {
  608. $options = (localURL($url)) ? array('verify' => false) : array();
  609. $response = Requests::get($url, array(), $options);
  610. if ($response->success) {
  611. $api['content']['queueItems'] = json_decode($response->body, true);
  612. }
  613. } catch (Requests_Exception $e) {
  614. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  615. };
  616. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  617. $url = $url . '/api?mode=history&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  618. try {
  619. $options = (localURL($url)) ? array('verify' => false) : array();
  620. $response = Requests::get($url, array(), $options);
  621. if ($response->success) {
  622. $api['content']['historyItems'] = json_decode($response->body, true);
  623. }
  624. } catch (Requests_Exception $e) {
  625. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  626. };
  627. $api['content'] = isset($api['content']) ? $api['content'] : false;
  628. return $api;
  629. }
  630. return false;
  631. }
  632. function nzbgetConnect()
  633. {
  634. if ($GLOBALS['homepageNzbgetEnabled'] && !empty($GLOBALS['nzbgetURL']) && qualifyRequest($GLOBALS['homepageNzbgetAuth'])) {
  635. $url = qualifyURL($GLOBALS['nzbgetURL']);
  636. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/listgroups';
  637. try {
  638. $options = (localURL($url)) ? array('verify' => false) : array();
  639. $response = Requests::get($url, array(), $options);
  640. if ($response->success) {
  641. $api['content']['queueItems'] = json_decode($response->body, true);
  642. }
  643. } catch (Requests_Exception $e) {
  644. writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  645. };
  646. $url = qualifyURL($GLOBALS['nzbgetURL']);
  647. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/history';
  648. try {
  649. $options = (localURL($url)) ? array('verify' => false) : array();
  650. $response = Requests::get($url, array(), $options);
  651. if ($response->success) {
  652. $api['content']['historyItems'] = json_decode($response->body, true);
  653. }
  654. } catch (Requests_Exception $e) {
  655. writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  656. };
  657. $api['content'] = isset($api['content']) ? $api['content'] : false;
  658. return $api;
  659. }
  660. return false;
  661. }
  662. function transmissionConnect()
  663. {
  664. if ($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])) {
  665. $digest = qualifyURL($GLOBALS['transmissionURL'], true);
  666. $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'] . ':' . decrypt($GLOBALS['transmissionPassword']) . "@" : '';
  667. $url = $digest['scheme'] . '://' . $passwordInclude . $digest['host'] . $digest['port'] . $digest['path'] . '/rpc';
  668. try {
  669. $options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false) : array();
  670. $response = Requests::get($url, array(), $options);
  671. if ($response->headers['x-transmission-session-id']) {
  672. $headers = array(
  673. 'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
  674. 'Content-Type' => 'application/json'
  675. );
  676. $data = array(
  677. 'method' => 'torrent-get',
  678. 'arguments' => array(
  679. 'fields' => array(
  680. "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir", "errorString"
  681. ),
  682. ),
  683. 'tags' => ''
  684. );
  685. $response = Requests::post($url, $headers, json_encode($data), $options);
  686. if ($response->success) {
  687. $torrentList = json_decode($response->body, true)['arguments']['torrents'];
  688. if ($GLOBALS['transmissionHideSeeding'] || $GLOBALS['transmissionHideCompleted']) {
  689. $filter = array();
  690. $torrents['arguments']['torrents'] = array();
  691. if ($GLOBALS['transmissionHideSeeding']) {
  692. array_push($filter, 6, 5);
  693. }
  694. if ($GLOBALS['transmissionHideCompleted']) {
  695. array_push($filter, 0);
  696. }
  697. foreach ($torrentList as $key => $value) {
  698. if (!in_array($value['status'], $filter)) {
  699. $torrents['arguments']['torrents'][] = $value;
  700. }
  701. }
  702. } else {
  703. $torrents = json_decode($response->body, true);
  704. }
  705. $api['content']['queueItems'] = $torrents;
  706. $api['content']['historyItems'] = false;
  707. }
  708. } else {
  709. writeLog('error', 'Transmission Connect Function - Error: Could not get session ID', 'SYSTEM');
  710. }
  711. } catch (Requests_Exception $e) {
  712. writeLog('error', 'Transmission Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  713. };
  714. $api['content'] = isset($api['content']) ? $api['content'] : false;
  715. return $api;
  716. }
  717. return false;
  718. }
  719. function qBittorrentConnect()
  720. {
  721. if ($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])) {
  722. $digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
  723. $data = array('username' => $GLOBALS['qBittorrentUsername'], 'password' => decrypt($GLOBALS['qBittorrentPassword']));
  724. $url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/login';
  725. try {
  726. $options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false) : array();
  727. $response = Requests::post($url, array(), $data, $options);
  728. $reflection = new ReflectionClass($response->cookies);
  729. $cookie = $reflection->getProperty("cookies");
  730. $cookie->setAccessible(true);
  731. $cookie = $cookie->getValue($response->cookies);
  732. if ($cookie) {
  733. $headers = array(
  734. 'Cookie' => 'SID=' . $cookie['SID']->value
  735. );
  736. $reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
  737. $url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/query/torrents?sort=' . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
  738. $response = Requests::get($url, $headers, $options);
  739. if ($response) {
  740. $torrentList = json_decode($response->body, true);
  741. if ($GLOBALS['qBittorrentHideSeeding'] || $GLOBALS['qBittorrentHideCompleted']) {
  742. $filter = array();
  743. $torrents['arguments']['torrents'] = array();
  744. if ($GLOBALS['qBittorrentHideSeeding']) {
  745. array_push($filter, 'uploading', 'stalledUP', 'queuedUP');
  746. }
  747. if ($GLOBALS['qBittorrentHideCompleted']) {
  748. array_push($filter, 'pausedUP');
  749. }
  750. foreach ($torrentList as $key => $value) {
  751. if (!in_array($value['state'], $filter)) {
  752. $torrents['arguments']['torrents'][] = $value;
  753. }
  754. }
  755. } else {
  756. $torrents['arguments']['torrents'] = json_decode($response->body, true);
  757. }
  758. $api['content']['queueItems'] = $torrents;
  759. $api['content']['historyItems'] = false;
  760. }
  761. } else {
  762. writeLog('error', 'qBittorrent Connect Function - Error: Could not get session ID', 'SYSTEM');
  763. }
  764. } catch (Requests_Exception $e) {
  765. writeLog('error', 'qBittorrent Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  766. };
  767. $api['content'] = isset($api['content']) ? $api['content'] : false;
  768. return $api;
  769. }
  770. return false;
  771. }
  772. function delugeConnect()
  773. {
  774. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  775. try {
  776. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  777. $torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, hash, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate');
  778. if ($GLOBALS['delugeHideSeeding'] || $GLOBALS['delugeHideCompleted']) {
  779. $filter = array();
  780. if ($GLOBALS['delugeHideSeeding']) {
  781. array_push($filter, 'Seeding', 'Uploading', 'queuedUP');
  782. }
  783. if ($GLOBALS['delugeHideCompleted']) {
  784. array_push($filter, 'Seeding', 'Completed');
  785. }
  786. //prettyPrint($torrents);
  787. foreach ($torrents as $key => $value) {
  788. if (!in_array($value->state, $filter)) {
  789. $api['content']['queueItems'][] = $value;
  790. }
  791. }
  792. } else {
  793. $api['content']['queueItems'] = $torrents;
  794. }
  795. $api['content']['queueItems'] = (empty($api['content']['queueItems'])) ? [] : $api['content']['queueItems'];
  796. $api['content']['historyItems'] = false;
  797. } catch (Excecption $e) {
  798. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  799. }
  800. }
  801. $api['content'] = isset($api['content']) ? $api['content'] : false;
  802. return $api;
  803. }
  804. function getCalendar()
  805. {
  806. $startDate = date('Y-m-d', strtotime("-" . $GLOBALS['calendarStart'] . " days"));
  807. $endDate = date('Y-m-d', strtotime("+" . $GLOBALS['calendarEnd'] . " days"));
  808. $calendarItems = array();
  809. // SONARR CONNECT
  810. if ($GLOBALS['homepageSonarrEnabled'] && qualifyRequest($GLOBALS['homepageSonarrAuth']) && !empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
  811. $sonarrs = array();
  812. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  813. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  814. if (count($sonarrURLList) == count($sonarrTokenList)) {
  815. foreach ($sonarrURLList as $key => $value) {
  816. $sonarrs[$key] = array(
  817. 'url' => $value,
  818. 'token' => $sonarrTokenList[$key]
  819. );
  820. }
  821. foreach ($sonarrs as $key => $value) {
  822. try {
  823. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  824. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate, $GLOBALS['sonarrUnmonitored']), $key);
  825. } catch (Exception $e) {
  826. writeLog('error', 'Sonarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  827. }
  828. if (!empty($sonarrCalendar)) {
  829. $calendarItems = array_merge($calendarItems, $sonarrCalendar);
  830. }
  831. }
  832. }
  833. }
  834. // RADARR CONNECT
  835. if ($GLOBALS['homepageRadarrEnabled'] && qualifyRequest($GLOBALS['homepageRadarrAuth']) && !empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
  836. $radarrs = array();
  837. $radarrURLList = explode(',', $GLOBALS['radarrURL']);
  838. $radarrTokenList = explode(',', $GLOBALS['radarrToken']);
  839. if (count($radarrURLList) == count($radarrTokenList)) {
  840. foreach ($radarrURLList as $key => $value) {
  841. $radarrs[$key] = array(
  842. 'url' => $value,
  843. 'token' => $radarrTokenList[$key]
  844. );
  845. }
  846. foreach ($radarrs as $key => $value) {
  847. try {
  848. $radarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  849. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate), $key, $value['url']);
  850. } catch (Exception $e) {
  851. writeLog('error', 'Radarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  852. }
  853. if (!empty($radarrCalendar)) {
  854. $calendarItems = array_merge($calendarItems, $radarrCalendar);
  855. }
  856. }
  857. }
  858. }
  859. // SICKRAGE/BEARD/MEDUSA CONNECT
  860. if ($GLOBALS['homepageSickrageEnabled'] && qualifyRequest($GLOBALS['homepageSickrageAuth']) && !empty($GLOBALS['sickrageURL']) && !empty($GLOBALS['sickrageToken'])) {
  861. $sicks = array();
  862. $sickURLList = explode(',', $GLOBALS['sickrageURL']);
  863. $sickTokenList = explode(',', $GLOBALS['sickrageToken']);
  864. if (count($sickURLList) == count($sickTokenList)) {
  865. foreach ($sickURLList as $key => $value) {
  866. $sicks[$key] = array(
  867. 'url' => $value,
  868. 'token' => $sickTokenList[$key]
  869. );
  870. }
  871. foreach ($sicks as $key => $value) {
  872. try {
  873. $sickrage = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
  874. $sickrageFuture = getSickrageCalendarWanted($sickrage->future(), $key);
  875. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100", "downloaded"), $key);
  876. if (!empty($sickrageFuture)) {
  877. $calendarItems = array_merge($calendarItems, $sickrageFuture);
  878. }
  879. if (!empty($sickrageHistory)) {
  880. $calendarItems = array_merge($calendarItems, $sickrageHistory);
  881. }
  882. } catch (Exception $e) {
  883. writeLog('error', 'Sickrage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  884. }
  885. }
  886. }
  887. }
  888. // COUCHPOTATO CONNECT
  889. if ($GLOBALS['homepageCouchpotatoEnabled'] && qualifyRequest($GLOBALS['homepageCouchpotatoAuth']) && !empty($GLOBALS['couchpotatoURL']) && !empty($GLOBALS['couchpotatoToken'])) {
  890. $couchs = array();
  891. $couchpotatoURLList = explode(',', $GLOBALS['couchpotatoURL']);
  892. $couchpotatoTokenList = explode(',', $GLOBALS['couchpotatoToken']);
  893. if (count($couchpotatoURLList) == count($couchpotatoTokenList)) {
  894. foreach ($couchpotatoURLList as $key => $value) {
  895. $couchs[$key] = array(
  896. 'url' => $value,
  897. 'token' => $couchpotatoTokenList[$key]
  898. );
  899. }
  900. foreach ($couchs as $key => $value) {
  901. try {
  902. $couchpotato = new Kryptonit3\CouchPotato\CouchPotato($value['url'], $value['token']);
  903. $couchCalendar = getCouchCalendar($couchpotato->getMediaList(), $key);
  904. if (!empty($couchCalendar)) {
  905. $calendarItems = array_merge($calendarItems, $couchCalendar);
  906. }
  907. } catch (Exception $e) {
  908. writeLog('error', 'Sickrage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  909. }
  910. }
  911. }
  912. }
  913. return ($calendarItems) ? $calendarItems : false;
  914. }
  915. function getSonarrCalendar($array, $number)
  916. {
  917. $array = json_decode($array, true);
  918. $gotCalendar = array();
  919. $i = 0;
  920. foreach ($array as $child) {
  921. $i++;
  922. $seriesName = $child['series']['title'];
  923. $seriesID = $child['series']['tvdbId'];
  924. $episodeID = $child['series']['tvdbId'];
  925. $monitored = $child['monitored'];
  926. if (!isset($episodeID)) {
  927. $episodeID = "";
  928. }
  929. //$episodeName = htmlentities($child['title'], ENT_QUOTES);
  930. if ($child['episodeNumber'] == "1") {
  931. $episodePremier = "true";
  932. } else {
  933. $episodePremier = "false";
  934. }
  935. $episodeAirDate = $child['airDateUtc'];
  936. $episodeAirDate = strtotime($episodeAirDate);
  937. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  938. if (new DateTime() < new DateTime($episodeAirDate)) {
  939. $unaired = true;
  940. }
  941. $downloaded = $child['hasFile'];
  942. if ($downloaded == "0" && isset($unaired) && $episodePremier == "true") {
  943. $downloaded = "text-primary animated flash";
  944. } elseif ($downloaded == "0" && isset($unaired) && $monitored == "0") {
  945. $downloaded = "text-dark";
  946. } elseif ($downloaded == "0" && isset($unaired)) {
  947. $downloaded = "text-info";
  948. } elseif ($downloaded == "1") {
  949. $downloaded = "text-success";
  950. } else {
  951. $downloaded = "text-danger";
  952. }
  953. $fanart = "/plugins/images/cache/no-np.png";
  954. foreach ($child['series']['images'] as $image) {
  955. if ($image['coverType'] == "fanart") {
  956. $fanart = $image['url'];
  957. }
  958. }
  959. if ($fanart !== "/plugins/images/cache/no-np.png") {
  960. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  961. $imageURL = $fanart;
  962. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  963. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  964. if (!file_exists($cacheFile)) {
  965. cacheImage($imageURL, $seriesID);
  966. unset($imageURL);
  967. unset($cacheFile);
  968. }
  969. }
  970. $bottomTitle = 'S' . sprintf("%02d", $child['seasonNumber']) . 'E' . sprintf("%02d", $child['episodeNumber']) . ' - ' . $child['title'];
  971. $details = array(
  972. "seasonCount" => $child['series']['seasonCount'],
  973. "status" => $child['series']['status'],
  974. "topTitle" => $seriesName,
  975. "bottomTitle" => $bottomTitle,
  976. "overview" => isset($child['overview']) ? $child['overview'] : '',
  977. "runtime" => $child['series']['runtime'],
  978. "image" => $fanart,
  979. "ratings" => $child['series']['ratings']['value'],
  980. "videoQuality" => $child["hasFile"] ? $child['episodeFile']['quality']['quality']['name'] : "unknown",
  981. "audioChannels" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioChannels'] : "unknown",
  982. "audioCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioCodec'] : "unknown",
  983. "videoCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['videoCodec'] : "unknown",
  984. "size" => $child["hasFile"] ? $child['episodeFile']['size'] : "unknown",
  985. "genres" => $child['series']['genres'],
  986. );
  987. array_push($gotCalendar, array(
  988. "id" => "Sonarr-" . $number . "-" . $i,
  989. "title" => $seriesName,
  990. "start" => $child['airDateUtc'],
  991. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  992. "imagetype" => "tv " . $downloaded,
  993. "details" => $details
  994. ));
  995. }
  996. if ($i != 0) {
  997. return $gotCalendar;
  998. }
  999. return false;
  1000. }
  1001. function getRadarrCalendar($array, $number, $url)
  1002. {
  1003. $array = json_decode($array, true);
  1004. $gotCalendar = array();
  1005. $i = 0;
  1006. foreach ($array as $child) {
  1007. if (isset($child['physicalRelease'])) {
  1008. $i++;
  1009. $movieName = $child['title'];
  1010. $movieID = $child['tmdbId'];
  1011. if (!isset($movieID)) {
  1012. $movieID = "";
  1013. }
  1014. $physicalRelease = $child['physicalRelease'];
  1015. $physicalRelease = strtotime($physicalRelease);
  1016. $physicalRelease = date("Y-m-d", $physicalRelease);
  1017. if (new DateTime() < new DateTime($physicalRelease)) {
  1018. $notReleased = "true";
  1019. } else {
  1020. $notReleased = "false";
  1021. }
  1022. $downloaded = $child['hasFile'];
  1023. if ($downloaded == "0" && $notReleased == "true") {
  1024. $downloaded = "text-info";
  1025. } elseif ($downloaded == "1") {
  1026. $downloaded = "text-success";
  1027. } else {
  1028. $downloaded = "text-danger";
  1029. }
  1030. $banner = "/plugins/images/cache/no-np.png";
  1031. foreach ($child['images'] as $image) {
  1032. if ($image['coverType'] == "banner") {
  1033. $url = rtrim($url, '/'); //remove trailing slash
  1034. $imageUrl = $image['url'];
  1035. $urlParts = explode("/", $url);
  1036. $imageParts = explode("/", $image['url']);
  1037. if ($imageParts[1] == end($urlParts)) {
  1038. unset($imageParts[1]);
  1039. $imageUrl = implode("/", $imageParts);
  1040. }
  1041. $banner = $url . $imageUrl;
  1042. }
  1043. }
  1044. if ($banner !== "/plugins/images/cache/no-np.png") {
  1045. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1046. $imageURL = $banner;
  1047. $cacheFile = $cacheDirectory . $movieID . '.jpg';
  1048. $banner = 'plugins/images/cache/' . $movieID . '.jpg';
  1049. if (!file_exists($cacheFile)) {
  1050. cacheImage($imageURL, $movieID);
  1051. unset($imageURL);
  1052. unset($cacheFile);
  1053. }
  1054. }
  1055. $alternativeTitles = "";
  1056. foreach ($child['alternativeTitles'] as $alternative) {
  1057. $alternativeTitles .= $alternative['title'] . ', ';
  1058. }
  1059. $alternativeTitles = empty($child['alternativeTitles']) ? "" : substr($alternativeTitles, 0, -2);
  1060. $details = array(
  1061. "topTitle" => $movieName,
  1062. "bottomTitle" => $alternativeTitles,
  1063. "status" => $child['status'],
  1064. "overview" => $child['overview'],
  1065. "runtime" => $child['runtime'],
  1066. "image" => $banner,
  1067. "ratings" => $child['ratings']['value'],
  1068. "videoQuality" => $child["hasFile"] ? $child['movieFile']['quality']['quality']['name'] : "unknown",
  1069. "audioChannels" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioChannels'] : "unknown",
  1070. "audioCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioFormat'] : "unknown",
  1071. "videoCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['videoCodec'] : "unknown",
  1072. "size" => $child["hasFile"] ? $child['movieFile']['size'] : "unknown",
  1073. "genres" => $child['genres'],
  1074. );
  1075. array_push($gotCalendar, array(
  1076. "id" => "Radarr-" . $number . "-" . $i,
  1077. "title" => $movieName,
  1078. "start" => $physicalRelease,
  1079. "className" => "bg-calendar movieID--" . $movieID,
  1080. "imagetype" => "film " . $downloaded,
  1081. "details" => $details
  1082. ));
  1083. }
  1084. }
  1085. if ($i != 0) {
  1086. return $gotCalendar;
  1087. }
  1088. return false;
  1089. }
  1090. function getCouchCalendar($array, $number)
  1091. {
  1092. $api = json_decode($array, true);
  1093. $gotCalendar = array();
  1094. $i = 0;
  1095. foreach ($api['movies'] as $child) {
  1096. if ($child['status'] == "active" || $child['status'] == "done") {
  1097. $i++;
  1098. $movieName = $child['info']['original_title'];
  1099. $movieID = $child['info']['tmdb_id'];
  1100. if (!isset($movieID)) {
  1101. $movieID = "";
  1102. }
  1103. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  1104. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  1105. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  1106. $physicalRelease = strtotime($physicalRelease);
  1107. $physicalRelease = date("Y-m-d", $physicalRelease);
  1108. if (new DateTime() < new DateTime($physicalRelease)) {
  1109. $notReleased = "true";
  1110. } else {
  1111. $notReleased = "false";
  1112. }
  1113. $downloaded = ($child['status'] == "active") ? "0" : "1";
  1114. if ($downloaded == "0" && $notReleased == "true") {
  1115. $downloaded = "text-info";
  1116. } elseif ($downloaded == "1") {
  1117. $downloaded = "text-success";
  1118. } else {
  1119. $downloaded = "text-danger";
  1120. }
  1121. if (!empty($child['info']['images']['backdrop_original'])) {
  1122. $banner = $child['info']['images']['backdrop_original'][0];
  1123. } elseif (!empty($child['info']['images']['backdrop'])) {
  1124. $banner = $child['info']['images']['backdrop_original'][0];
  1125. } else {
  1126. $banner = "/plugins/images/cache/no-np.png";
  1127. }
  1128. if ($banner !== "/plugins/images/cache/no-np.png") {
  1129. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1130. $imageURL = $banner;
  1131. $cacheFile = $cacheDirectory . $movieID . '.jpg';
  1132. $banner = 'plugins/images/cache/' . $movieID . '.jpg';
  1133. if (!file_exists($cacheFile)) {
  1134. cacheImage($imageURL, $movieID);
  1135. unset($imageURL);
  1136. unset($cacheFile);
  1137. }
  1138. }
  1139. $hasFile = (!empty($child['releases']) && !empty($child['releases'][0]['files']['movie']));
  1140. $details = array(
  1141. "topTitle" => $movieName,
  1142. "bottomTitle" => $child['info']['tagline'],
  1143. "status" => $child['status'],
  1144. "overview" => $child['info']['plot'],
  1145. "runtime" => $child['info']['runtime'],
  1146. "image" => $banner,
  1147. "ratings" => isset($child['info']['rating']['imdb'][0]) ? $child['info']['rating']['imdb'][0] : '',
  1148. "videoQuality" => $hasFile ? $child['releases'][0]['quality'] : "unknown",
  1149. "audioChannels" => "",
  1150. "audioCodec" => "",
  1151. "videoCodec" => "",
  1152. "genres" => $child['info']['genres'],
  1153. );
  1154. array_push($gotCalendar, array(
  1155. "id" => "CouchPotato-" . $number . "-" . $i,
  1156. "title" => $movieName,
  1157. "start" => $physicalRelease,
  1158. "className" => "bg-calendar calendar-item movieID--" . $movieID,
  1159. "imagetype" => "film " . $downloaded,
  1160. "details" => $details
  1161. ));
  1162. }
  1163. }
  1164. if ($i != 0) {
  1165. return $gotCalendar;
  1166. }
  1167. return false;
  1168. }
  1169. function getSickrageCalendarWanted($array, $number)
  1170. {
  1171. $array = json_decode($array, true);
  1172. $gotCalendar = array();
  1173. $i = 0;
  1174. foreach ($array['data']['missed'] as $child) {
  1175. $i++;
  1176. $seriesName = $child['show_name'];
  1177. $seriesID = $child['tvdbid'];
  1178. $episodeID = $child['tvdbid'];
  1179. $episodeAirDate = $child['airdate'];
  1180. $episodeAirDateTime = explode(" ", $child['airs']);
  1181. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1182. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1183. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1184. if (new DateTime() < new DateTime($episodeAirDate)) {
  1185. $unaired = true;
  1186. }
  1187. $downloaded = "0";
  1188. if ($downloaded == "0" && isset($unaired)) {
  1189. $downloaded = "text-info";
  1190. } elseif ($downloaded == "1") {
  1191. $downloaded = "text-success";
  1192. } else {
  1193. $downloaded = "text-danger";
  1194. }
  1195. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1196. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1197. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1198. $fanart = "/plugins/images/cache/no-np.png";
  1199. if (file_exists($cacheFile)) {
  1200. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1201. unset($cacheFile);
  1202. }
  1203. $details = array(
  1204. "seasonCount" => "",
  1205. "status" => $child['show_status'],
  1206. "topTitle" => $seriesName,
  1207. "bottomTitle" => $bottomTitle,
  1208. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1209. "runtime" => "",
  1210. "image" => $fanart,
  1211. "ratings" => "",
  1212. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1213. "audioChannels" => "",
  1214. "audioCodec" => "",
  1215. "videoCodec" => "",
  1216. "size" => "",
  1217. "genres" => "",
  1218. );
  1219. array_push($gotCalendar, array(
  1220. "id" => "Sick-" . $number . "-Miss-" . $i,
  1221. "title" => $seriesName,
  1222. "start" => $episodeAirDate,
  1223. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1224. "imagetype" => "tv " . $downloaded,
  1225. "details" => $details,
  1226. ));
  1227. }
  1228. foreach ($array['data']['today'] as $child) {
  1229. $i++;
  1230. $seriesName = $child['show_name'];
  1231. $seriesID = $child['tvdbid'];
  1232. $episodeID = $child['tvdbid'];
  1233. $episodeAirDate = $child['airdate'];
  1234. $episodeAirDateTime = explode(" ", $child['airs']);
  1235. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1236. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1237. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1238. if (new DateTime() < new DateTime($episodeAirDate)) {
  1239. $unaired = true;
  1240. }
  1241. $downloaded = "0";
  1242. if ($downloaded == "0" && isset($unaired)) {
  1243. $downloaded = "text-info";
  1244. } elseif ($downloaded == "1") {
  1245. $downloaded = "text-success";
  1246. } else {
  1247. $downloaded = "text-danger";
  1248. }
  1249. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1250. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1251. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1252. $fanart = "/plugins/images/cache/no-np.png";
  1253. if (file_exists($cacheFile)) {
  1254. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1255. unset($cacheFile);
  1256. }
  1257. $details = array(
  1258. "seasonCount" => "",
  1259. "status" => $child['show_status'],
  1260. "topTitle" => $seriesName,
  1261. "bottomTitle" => $bottomTitle,
  1262. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1263. "runtime" => "",
  1264. "image" => $fanart,
  1265. "ratings" => "",
  1266. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1267. "audioChannels" => "",
  1268. "audioCodec" => "",
  1269. "videoCodec" => "",
  1270. "size" => "",
  1271. "genres" => "",
  1272. );
  1273. array_push($gotCalendar, array(
  1274. "id" => "Sick-" . $number . "-Today-" . $i,
  1275. "title" => $seriesName,
  1276. "start" => $episodeAirDate,
  1277. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1278. "imagetype" => "tv " . $downloaded,
  1279. "details" => $details,
  1280. ));
  1281. }
  1282. foreach ($array['data']['soon'] as $child) {
  1283. $i++;
  1284. $seriesName = $child['show_name'];
  1285. $seriesID = $child['tvdbid'];
  1286. $episodeID = $child['tvdbid'];
  1287. $episodeAirDate = $child['airdate'];
  1288. $episodeAirDateTime = explode(" ", $child['airs']);
  1289. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1290. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1291. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1292. if (new DateTime() < new DateTime($episodeAirDate)) {
  1293. $unaired = true;
  1294. }
  1295. $downloaded = "0";
  1296. if ($downloaded == "0" && isset($unaired)) {
  1297. $downloaded = "text-info";
  1298. } elseif ($downloaded == "1") {
  1299. $downloaded = "text-success";
  1300. } else {
  1301. $downloaded = "text-danger";
  1302. }
  1303. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1304. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1305. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1306. $fanart = "/plugins/images/cache/no-np.png";
  1307. if (file_exists($cacheFile)) {
  1308. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1309. unset($cacheFile);
  1310. }
  1311. $details = array(
  1312. "seasonCount" => "",
  1313. "status" => $child['show_status'],
  1314. "topTitle" => $seriesName,
  1315. "bottomTitle" => $bottomTitle,
  1316. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1317. "runtime" => "",
  1318. "image" => $fanart,
  1319. "ratings" => "",
  1320. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1321. "audioChannels" => "",
  1322. "audioCodec" => "",
  1323. "videoCodec" => "",
  1324. "size" => "",
  1325. "genres" => "",
  1326. );
  1327. array_push($gotCalendar, array(
  1328. "id" => "Sick-" . $number . "-Soon-" . $i,
  1329. "title" => $seriesName,
  1330. "start" => $episodeAirDate,
  1331. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1332. "imagetype" => "tv " . $downloaded,
  1333. "details" => $details,
  1334. ));
  1335. }
  1336. foreach ($array['data']['later'] as $child) {
  1337. $i++;
  1338. $seriesName = $child['show_name'];
  1339. $seriesID = $child['tvdbid'];
  1340. $episodeID = $child['tvdbid'];
  1341. $episodeAirDate = $child['airdate'];
  1342. $episodeAirDateTime = explode(" ", $child['airs']);
  1343. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1344. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1345. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1346. if (new DateTime() < new DateTime($episodeAirDate)) {
  1347. $unaired = true;
  1348. }
  1349. $downloaded = "0";
  1350. if ($downloaded == "0" && isset($unaired)) {
  1351. $downloaded = "text-info";
  1352. } elseif ($downloaded == "1") {
  1353. $downloaded = "text-success";
  1354. } else {
  1355. $downloaded = "text-danger";
  1356. }
  1357. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1358. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1359. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1360. $fanart = "/plugins/images/cache/no-np.png";
  1361. if (file_exists($cacheFile)) {
  1362. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1363. unset($cacheFile);
  1364. }
  1365. $details = array(
  1366. "seasonCount" => "",
  1367. "status" => $child['show_status'],
  1368. "topTitle" => $seriesName,
  1369. "bottomTitle" => $bottomTitle,
  1370. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1371. "runtime" => "",
  1372. "image" => $fanart,
  1373. "ratings" => "",
  1374. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1375. "audioChannels" => "",
  1376. "audioCodec" => "",
  1377. "videoCodec" => "",
  1378. "size" => "",
  1379. "genres" => "",
  1380. );
  1381. array_push($gotCalendar, array(
  1382. "id" => "Sick-" . $number . "-Later-" . $i,
  1383. "title" => $seriesName,
  1384. "start" => $episodeAirDate,
  1385. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1386. "imagetype" => "tv " . $downloaded,
  1387. "details" => $details,
  1388. ));
  1389. }
  1390. if ($i != 0) {
  1391. return $gotCalendar;
  1392. }
  1393. return false;
  1394. }
  1395. function getSickrageCalendarHistory($array, $number)
  1396. {
  1397. $array = json_decode($array, true);
  1398. $gotCalendar = array();
  1399. $i = 0;
  1400. foreach ($array['data'] as $child) {
  1401. $i++;
  1402. $seriesName = $child['show_name'];
  1403. $seriesID = $child['tvdbid'];
  1404. $episodeID = $child['tvdbid'];
  1405. $episodeAirDate = $child['date'];
  1406. $downloaded = "text-success";
  1407. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']);
  1408. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1409. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1410. $fanart = "/plugins/images/cache/no-np.png";
  1411. if (file_exists($cacheFile)) {
  1412. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1413. unset($cacheFile);
  1414. }
  1415. $details = array(
  1416. "seasonCount" => "",
  1417. "status" => $child['status'],
  1418. "topTitle" => $seriesName,
  1419. "bottomTitle" => $bottomTitle,
  1420. "overview" => '',
  1421. "runtime" => $child['series']['runtime'],
  1422. "image" => $fanart,
  1423. "ratings" => $child['series']['ratings']['value'],
  1424. "videoQuality" => isset($child["quality"]) ? $child['quality'] : "unknown",
  1425. "audioChannels" => "",
  1426. "audioCodec" => "",
  1427. "videoCodec" => "",
  1428. "size" => "",
  1429. "genres" => "",
  1430. );
  1431. array_push($gotCalendar, array(
  1432. "id" => "Sick-" . $number . "-History-" . $i,
  1433. "title" => $seriesName,
  1434. "start" => $episodeAirDate,
  1435. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1436. "imagetype" => "tv " . $downloaded,
  1437. "details" => $details,
  1438. ));
  1439. }
  1440. if ($i != 0) {
  1441. return $gotCalendar;
  1442. }
  1443. return false;
  1444. }
  1445. function ombiAPI($array)
  1446. {
  1447. return ombiAction($array['data']['id'], $array['data']['action'], $array['data']['type']);
  1448. }
  1449. function ombiAction($id, $action, $type)
  1450. {
  1451. if ($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])) {
  1452. $url = qualifyURL($GLOBALS['ombiURL']);
  1453. $headers = array(
  1454. "Accept" => "application/json",
  1455. "Content-Type" => "application/json",
  1456. "Apikey" => $GLOBALS['ombiToken']
  1457. );
  1458. $data = array(
  1459. 'id' => $id,
  1460. );
  1461. switch ($type) {
  1462. case 'season':
  1463. case 'tv':
  1464. $type = 'tv';
  1465. $add = array(
  1466. 'tvDbId' => $id,
  1467. 'requestAll' => true,
  1468. 'latestSeason' => true,
  1469. 'firstSeason' => true
  1470. );
  1471. break;
  1472. default:
  1473. $type = 'movie';
  1474. $add = array("theMovieDbId" => (int)$id);
  1475. break;
  1476. }
  1477. $success['head'] = $headers;
  1478. $success['act'] = $action;
  1479. $success['data'] = $data;
  1480. $success['add'] = $add;
  1481. $success['type'] = $type;
  1482. try {
  1483. $options = (localURL($url)) ? array('verify' => false) : array();
  1484. switch ($action) {
  1485. case 'add':
  1486. if (isset($_COOKIE['Auth'])) {
  1487. $headers = array(
  1488. "Accept" => "application/json",
  1489. "Content-Type" => "application/json",
  1490. "Authorization" => "Bearer " . $_COOKIE['Auth']
  1491. );
  1492. $success['head'] = $headers;
  1493. } else {
  1494. return false;
  1495. }
  1496. $response = Requests::post($url . "/api/v1/Request/" . $type, $headers, json_encode($add), $options);
  1497. break;
  1498. default:
  1499. if (qualifyRequest(1)) {
  1500. switch ($action) {
  1501. case 'approve':
  1502. $response = Requests::post($url . "/api/v1/Request/" . $type . "/approve", $headers, json_encode($data), $options);
  1503. break;
  1504. case 'available':
  1505. $response = Requests::post($url . "/api/v1/Request/" . $type . "/available", $headers, json_encode($data), $options);
  1506. break;
  1507. case 'unavailable':
  1508. $response = Requests::post($url . "/api/v1/Request/" . $type . "/unavailable", $headers, json_encode($data), $options);
  1509. break;
  1510. case 'deny':
  1511. $response = Requests::put($url . "/api/v1/Request/" . $type . "/deny", $headers, json_encode($data), $options);
  1512. break;
  1513. case 'delete':
  1514. $response = Requests::delete($url . "/api/v1/Request/" . $type . "/" . $id, $headers, $options);
  1515. break;
  1516. default:
  1517. return false;
  1518. }
  1519. }
  1520. break;
  1521. }
  1522. $success['api'] = $response;
  1523. $success['bd'] = $response->body;
  1524. $success['hd'] = $response->headers;
  1525. if ($response->success) {
  1526. $success['ok'] = true;
  1527. }
  1528. } catch (Requests_Exception $e) {
  1529. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1530. };
  1531. }
  1532. return isset($success['ok']) ? $success : false;
  1533. }
  1534. function getOmbiRequests($type = "both")
  1535. {
  1536. if ($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])) {
  1537. $url = qualifyURL($GLOBALS['ombiURL']);
  1538. $headers = array(
  1539. "Accept" => "application/json",
  1540. "Apikey" => $GLOBALS['ombiToken'],
  1541. );
  1542. $requests = array();
  1543. try {
  1544. $options = (localURL($url)) ? array('verify' => false) : array();
  1545. switch ($type) {
  1546. case 'movie':
  1547. $movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
  1548. break;
  1549. case 'tv':
  1550. $tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
  1551. break;
  1552. default:
  1553. $movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
  1554. $tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
  1555. break;
  1556. }
  1557. if ($movie->success || $tv->success) {
  1558. if (isset($movie)) {
  1559. $movie = json_decode($movie->body, true);
  1560. //$movie = array_reverse($movie);
  1561. foreach ($movie as $key => $value) {
  1562. $requests[] = array(
  1563. 'test' => $value,
  1564. 'id' => $value['theMovieDbId'],
  1565. 'title' => $value['title'],
  1566. 'overview' => $value['overview'],
  1567. 'poster' => (isset($value['posterPath']) && $value['posterPath'] !== '') ? 'https://image.tmdb.org/t/p/w300/' . $value['posterPath'] : '',
  1568. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/' . $value['background'] : '',
  1569. 'approved' => $value['approved'],
  1570. 'available' => $value['available'],
  1571. 'denied' => $value['denied'],
  1572. 'deniedReason' => $value['deniedReason'],
  1573. 'user' => $value['requestedUser']['userName'],
  1574. 'request_id' => $value['id'],
  1575. 'request_date' => $value['requestedDate'],
  1576. 'release_date' => $value['releaseDate'],
  1577. 'type' => 'movie',
  1578. 'icon' => 'mdi mdi-filmstrip',
  1579. 'color' => 'palette-Deep-Purple-900 bg white',
  1580. );
  1581. }
  1582. }
  1583. if (isset($tv) && (is_array($tv) || is_object($tv))) {
  1584. $tv = json_decode($tv->body, true);
  1585. foreach ($tv as $key => $value) {
  1586. if (is_array($value['childRequests'][0])) {
  1587. $requests[] = array(
  1588. 'test' => $value,
  1589. 'id' => $value['tvDbId'],
  1590. 'title' => $value['title'],
  1591. 'overview' => $value['overview'],
  1592. 'poster' => $value['posterPath'],
  1593. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/' . $value['background'] : '',
  1594. 'approved' => $value['childRequests'][0]['approved'],
  1595. 'available' => $value['childRequests'][0]['available'],
  1596. 'denied' => $value['childRequests'][0]['denied'],
  1597. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  1598. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  1599. 'request_id' => $value['id'],
  1600. 'request_date' => $value['childRequests'][0]['requestedDate'],
  1601. 'release_date' => $value['releaseDate'],
  1602. 'type' => 'tv',
  1603. 'icon' => 'mdi mdi-television',
  1604. 'color' => 'grayish-blue-bg',
  1605. );
  1606. }
  1607. }
  1608. }
  1609. //sort here
  1610. usort($requests, function ($item1, $item2) {
  1611. if ($item1['request_date'] == $item2['request_date']) {
  1612. return 0;
  1613. }
  1614. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  1615. });
  1616. }
  1617. } catch (Requests_Exception $e) {
  1618. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1619. };
  1620. }
  1621. $api['content'] = isset($requests) ? $requests : false;
  1622. return $api;
  1623. }
  1624. function testAPIConnection($array)
  1625. {
  1626. switch ($array['data']['action']) {
  1627. case 'plex':
  1628. if (!empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken'])) {
  1629. $url = qualifyURL($GLOBALS['plexURL']);
  1630. $url = $url . "/?X-Plex-Token=" . $GLOBALS['plexToken'];
  1631. try {
  1632. $options = (localURL($url)) ? array('verify' => false) : array();
  1633. $response = Requests::get($url, array(), $options);
  1634. libxml_use_internal_errors(true);
  1635. if ($response->success) {
  1636. return true;
  1637. }
  1638. } catch (Requests_Exception $e) {
  1639. return $e->getMessage();
  1640. };
  1641. } else {
  1642. return 'URL and/or Token not setup';
  1643. }
  1644. break;
  1645. case 'emby':
  1646. break;
  1647. case 'sonarr':
  1648. if (!empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
  1649. $sonarrs = array();
  1650. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  1651. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  1652. if (count($sonarrURLList) == count($sonarrTokenList)) {
  1653. foreach ($sonarrURLList as $key => $value) {
  1654. $sonarrs[$key] = array(
  1655. 'url' => $value,
  1656. 'token' => $sonarrTokenList[$key]
  1657. );
  1658. }
  1659. foreach ($sonarrs as $key => $value) {
  1660. try {
  1661. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  1662. $sonarr->getSystemStatus();
  1663. return true;
  1664. } catch (Exception $e) {
  1665. return $e->getMessage();
  1666. }
  1667. }
  1668. }
  1669. } else {
  1670. return 'URL/s and/or Token/s not setup';
  1671. }
  1672. break;
  1673. case 'radarr':
  1674. if (!empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
  1675. $sonarrs = array();
  1676. $sonarrURLList = explode(',', $GLOBALS['radarrURL']);
  1677. $sonarrTokenList = explode(',', $GLOBALS['radarrToken']);
  1678. if (count($sonarrURLList) == count($sonarrTokenList)) {
  1679. foreach ($sonarrURLList as $key => $value) {
  1680. $sonarrs[$key] = array(
  1681. 'url' => $value,
  1682. 'token' => $sonarrTokenList[$key]
  1683. );
  1684. }
  1685. foreach ($sonarrs as $key => $value) {
  1686. try {
  1687. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  1688. $sonarr->getSystemStatus();
  1689. return true;
  1690. } catch (Exception $e) {
  1691. return $e->getMessage();
  1692. }
  1693. }
  1694. }
  1695. } else {
  1696. return 'URL/s and/or Token/s not setup';
  1697. }
  1698. break;
  1699. case 'sabnzbd':
  1700. if (!empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken'])) {
  1701. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1702. $url = $url . '/api?mode=queue&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1703. try {
  1704. $options = (localURL($url)) ? array('verify' => false) : array();
  1705. $response = Requests::get($url, array(), $options);
  1706. if ($response->success) {
  1707. return true;
  1708. }
  1709. } catch (Requests_Exception $e) {
  1710. return $e->getMessage();
  1711. };
  1712. } else {
  1713. return 'URL and/or Token not setup';
  1714. }
  1715. break;
  1716. case 'nzbget':
  1717. if (!empty($GLOBALS['nzbgetURL']) && !empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  1718. $url = qualifyURL($GLOBALS['nzbgetURL']);
  1719. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/listgroups';
  1720. try {
  1721. $options = (localURL($url)) ? array('verify' => false) : array();
  1722. $response = Requests::get($url, array(), $options);
  1723. if ($response->success) {
  1724. return true;
  1725. }
  1726. } catch (Requests_Exception $e) {
  1727. return $e->getMessage();
  1728. };
  1729. } else {
  1730. return 'URL and/or Username/Password not setup';
  1731. }
  1732. break;
  1733. case 'deluge':
  1734. if (!empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword'])) {
  1735. try {
  1736. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1737. $torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, hash, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate');
  1738. return true;
  1739. } catch (\Excecption $e) {
  1740. return $e->getMessage();
  1741. }
  1742. } else {
  1743. return 'URL and/or Password not setup';
  1744. }
  1745. break;
  1746. default :
  1747. return false;
  1748. }
  1749. return false;
  1750. }