homepage-connect-functions.php 71 KB

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