homepage-connect-functions.php 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  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 'getrTorrent':
  43. return rTorrentConnect();
  44. break;
  45. case 'getDeluge':
  46. return delugeConnect();
  47. break;
  48. case 'getCalendar':
  49. return getCalendar();
  50. break;
  51. case 'getRequests':
  52. return getOmbiRequests();
  53. break;
  54. default:
  55. # code...
  56. break;
  57. }
  58. return false;
  59. }
  60. function streamType($value)
  61. {
  62. if ($value == "transcode" || $value == "Transcode") {
  63. return "Transcode";
  64. } elseif ($value == "copy" || $value == "DirectStream") {
  65. return "Direct Stream";
  66. } elseif ($value == "directplay" || $value == "DirectPlay") {
  67. return "Direct Play";
  68. } else {
  69. return "Direct Play";
  70. }
  71. }
  72. function resolveEmbyItem($itemDetails)
  73. {
  74. // Grab Each item info from Emby (extra call)
  75. $id = isset($itemDetails['NowPlayingItem']['Id']) ? $itemDetails['NowPlayingItem']['Id'] : $itemDetails['Id'];
  76. $url = qualifyURL($GLOBALS['embyURL']);
  77. $url = $url . '/Items?Ids=' . $id . '&api_key=' . $GLOBALS['embyToken'] . '&Fields=Overview,People,Genres,CriticRating,Studios,Taglines';
  78. try {
  79. $options = (localURL($url)) ? array('verify' => false) : array();
  80. $response = Requests::get($url, array(), $options);
  81. if ($response->success) {
  82. $item = json_decode($response->body, true)['Items'][0];
  83. }
  84. } catch (Requests_Exception $e) {
  85. return false;
  86. };
  87. // Static Height & Width
  88. $height = getCacheImageSize('h');
  89. $width = getCacheImageSize('w');
  90. $nowPlayingHeight = getCacheImageSize('nph');
  91. $nowPlayingWidth = getCacheImageSize('npw');
  92. $actorHeight = 450;
  93. $actorWidth = 300;
  94. // Cache Directories
  95. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  96. $cacheDirectoryWeb = 'plugins/images/cache/';
  97. // Types
  98. $embyItem['array-item'] = $item;
  99. $embyItem['array-itemdetails'] = $itemDetails;
  100. switch (@$item['Type']) {
  101. case 'Series':
  102. $embyItem['type'] = 'tv';
  103. $embyItem['title'] = $item['Name'];
  104. $embyItem['secondaryTitle'] = '';
  105. $embyItem['summary'] = '';
  106. $embyItem['ratingKey'] = $item['Id'];
  107. $embyItem['thumb'] = $item['Id'];
  108. $embyItem['key'] = $item['Id'] . "-list";
  109. $embyItem['nowPlayingThumb'] = $item['Id'];
  110. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  111. $embyItem['metadataKey'] = $item['Id'];
  112. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['BackdropImageTags'][0]) ? 'Backdrop' : '');
  113. break;
  114. case 'Episode':
  115. $embyItem['type'] = 'tv';
  116. $embyItem['title'] = $item['SeriesName'];
  117. $embyItem['secondaryTitle'] = '';
  118. $embyItem['summary'] = '';
  119. $embyItem['ratingKey'] = $item['Id'];
  120. $embyItem['thumb'] = (isset($item['SeriesId']) ? $item['SeriesId'] : $item['Id']);
  121. $embyItem['key'] = (isset($item['SeriesId']) ? $item['SeriesId'] : $item['Id']) . "-list";
  122. $embyItem['nowPlayingThumb'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'] : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'] : false);
  123. $embyItem['nowPlayingKey'] = isset($item['ParentThumbItemId']) ? $item['ParentThumbItemId'] . '-np' : (isset($item['ParentBackdropItemId']) ? $item['ParentBackdropItemId'] . '-np' : false);
  124. $embyItem['metadataKey'] = $item['Id'];
  125. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? 'Thumb' : (isset($item['ParentBackdropImageTags'][0]) ? 'Backdrop' : '');
  126. $embyItem['nowPlayingTitle'] = @$item['SeriesName'] . ' - ' . @$item['Name'];
  127. $embyItem['nowPlayingBottom'] = 'S' . @$item['ParentIndexNumber'] . ' · E' . @$item['IndexNumber'];
  128. break;
  129. case 'MusicAlbum':
  130. case 'Audio':
  131. $embyItem['type'] = 'music';
  132. $embyItem['title'] = $item['Name'];
  133. $embyItem['secondaryTitle'] = '';
  134. $embyItem['summary'] = '';
  135. $embyItem['ratingKey'] = $item['Id'];
  136. $embyItem['thumb'] = $item['Id'];
  137. $embyItem['key'] = $item['Id'] . "-list";
  138. $embyItem['nowPlayingThumb'] = (isset($item['AlbumId']) ? $item['AlbumId'] : @$item['ParentBackdropItemId']);
  139. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  140. $embyItem['metadataKey'] = isset($item['AlbumId']) ? $item['AlbumId'] : $item['Id'];
  141. $embyItem['nowPlayingImageType'] = (isset($item['ParentBackdropItemId']) ? "Primary" : "Backdrop");
  142. $embyItem['nowPlayingTitle'] = @$item['AlbumArtist'] . ' - ' . @$item['Name'];
  143. $embyItem['nowPlayingBottom'] = @$item['Album'];
  144. break;
  145. case 'Movie':
  146. $embyItem['type'] = 'movie';
  147. $embyItem['title'] = $item['Name'];
  148. $embyItem['secondaryTitle'] = '';
  149. $embyItem['summary'] = '';
  150. $embyItem['ratingKey'] = $item['Id'];
  151. $embyItem['thumb'] = $item['Id'];
  152. $embyItem['key'] = $item['Id'] . "-list";
  153. $embyItem['nowPlayingThumb'] = $item['Id'];
  154. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  155. $embyItem['metadataKey'] = $item['Id'];
  156. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
  157. $embyItem['nowPlayingTitle'] = @$item['Name'];
  158. $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
  159. break;
  160. case 'Video':
  161. $embyItem['type'] = 'video';
  162. $embyItem['title'] = $item['Name'];
  163. $embyItem['secondaryTitle'] = '';
  164. $embyItem['summary'] = '';
  165. $embyItem['ratingKey'] = $item['Id'];
  166. $embyItem['thumb'] = $item['Id'];
  167. $embyItem['key'] = $item['Id'] . "-list";
  168. $embyItem['nowPlayingThumb'] = $item['Id'];
  169. $embyItem['nowPlayingKey'] = $item['Id'] . "-np";
  170. $embyItem['metadataKey'] = $item['Id'];
  171. $embyItem['nowPlayingImageType'] = isset($item['ImageTags']['Thumb']) ? "Thumb" : (isset($item['BackdropImageTags']) ? "Backdrop" : false);
  172. $embyItem['nowPlayingTitle'] = @$item['Name'];
  173. $embyItem['nowPlayingBottom'] = @$item['ProductionYear'];
  174. break;
  175. default:
  176. return false;
  177. }
  178. $embyItem['uid'] = $item['Id'];
  179. $embyItem['imageType'] = (isset($item['ImageTags']['Primary']) ? "Primary" : false);
  180. $embyItem['elapsed'] = isset($itemDetails['PlayState']['PositionTicks']) && $itemDetails['PlayState']['PositionTicks'] !== '0' ? (int)$itemDetails['PlayState']['PositionTicks'] : null;
  181. $embyItem['duration'] = isset($itemDetails['NowPlayingItem']['RunTimeTicks']) ? (int)$itemDetails['NowPlayingItem']['RunTimeTicks'] : (int)(isset($item['RunTimeTicks']) ? $item['RunTimeTicks'] : '');
  182. $embyItem['watched'] = ($embyItem['elapsed'] && $embyItem['duration'] ? floor(($embyItem['elapsed'] / $embyItem['duration']) * 100) : 0);
  183. $embyItem['transcoded'] = isset($itemDetails['TranscodingInfo']['CompletionPercentage']) ? floor((int)$itemDetails['TranscodingInfo']['CompletionPercentage']) : 100;
  184. $embyItem['stream'] = @$itemDetails['PlayState']['PlayMethod'];
  185. $embyItem['id'] = $item['ServerId'];
  186. $embyItem['session'] = @$itemDetails['DeviceId'];
  187. $embyItem['bandwidth'] = isset($itemDetails['TranscodingInfo']['Bitrate']) ? $itemDetails['TranscodingInfo']['Bitrate'] / 1000 : '';
  188. $embyItem['bandwidthType'] = 'wan';
  189. $embyItem['sessionType'] = (@$itemDetails['PlayState']['PlayMethod'] == 'Transcode') ? 'Transcoding' : 'Direct Playing';
  190. $embyItem['state'] = ((@(string)$itemDetails['PlayState']['IsPaused'] == '1') ? "pause" : "play");
  191. $embyItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? @(string)$itemDetails['UserName'] : "";
  192. $embyItem['userThumb'] = '';
  193. $embyItem['userAddress'] = (isset($itemDetails['RemoteEndPoint']) ? $itemDetails['RemoteEndPoint'] : "x.x.x.x");
  194. $embyItem['address'] = $GLOBALS['embyTabURL'] ? rtrim($GLOBALS['embyTabURL'], '/') . "/web/#!/itemdetails.html?id=" . $embyItem['uid'] : "https://app.emby.media/#!/itemdetails.html?id=" . $embyItem['uid'] . "&serverId=" . $embyItem['id'];
  195. $embyItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=emby&type=' . $embyItem['nowPlayingImageType'] . '&img=' . $embyItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $embyItem['nowPlayingKey'] . '$' . randString();
  196. $embyItem['originalImage'] = 'api/?v1/image&source=emby&type=' . $embyItem['imageType'] . '&img=' . $embyItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $embyItem['key'] . '$' . randString();
  197. $embyItem['openTab'] = $GLOBALS['embyTabURL'] && $GLOBALS['embyTabName'] ? true : false;
  198. $embyItem['tabName'] = $GLOBALS['embyTabName'] ? $GLOBALS['embyTabName'] : '';
  199. // Stream info
  200. $embyItem['userStream'] = array(
  201. 'platform' => @(string)$itemDetails['Client'],
  202. 'product' => @(string)$itemDetails['Client'],
  203. 'device' => @(string)$itemDetails['DeviceName'],
  204. 'stream' => @$itemDetails['PlayState']['PlayMethod'],
  205. 'videoResolution' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]['Width']) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Width'] : '',
  206. 'throttled' => false,
  207. 'sourceVideoCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : '',
  208. 'videoCodec' => @$itemDetails['TranscodingInfo']['VideoCodec'],
  209. 'audioCodec' => @$itemDetails['TranscodingInfo']['AudioCodec'],
  210. 'sourceAudioCodec' => isset($itemDetails['NowPlayingItem']['MediaStreams'][1]) ? $itemDetails['NowPlayingItem']['MediaStreams'][1]['Codec'] : (isset($itemDetails['NowPlayingItem']['MediaStreams'][0]) ? $itemDetails['NowPlayingItem']['MediaStreams'][0]['Codec'] : ''),
  211. 'videoDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
  212. 'audioDecision' => streamType(@$itemDetails['PlayState']['PlayMethod']),
  213. 'container' => isset($itemDetails['NowPlayingItem']['Container']) ? $itemDetails['NowPlayingItem']['Container'] : '',
  214. 'audioChannels' => @$itemDetails['TranscodingInfo']['AudioChannels']
  215. );
  216. // Genre catch all
  217. if ($item['Genres']) {
  218. $genres = array();
  219. foreach ($item['Genres'] as $genre) {
  220. $genres[] = $genre;
  221. }
  222. }
  223. // Actor catch all
  224. if ($item['People']) {
  225. $actors = array();
  226. foreach ($item['People'] as $key => $value) {
  227. if (@$value['PrimaryImageTag'] && @$value['Role']) {
  228. if (file_exists($cacheDirectory . (string)$value['Id'] . '-cast.jpg')) {
  229. $actorImage = $cacheDirectoryWeb . (string)$value['Id'] . '-cast.jpg';
  230. }
  231. 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')) {
  232. $actorImage = 'api/?v1/image&source=emby&type=Primary&img=' . (string)$value['Id'] . '&height=' . $actorHeight . '&width=' . $actorWidth . '&key=' . (string)$value['Id'] . '-cast';
  233. }
  234. $actors[] = array(
  235. 'name' => (string)$value['Name'],
  236. 'role' => (string)$value['Role'],
  237. 'thumb' => $actorImage
  238. );
  239. }
  240. }
  241. }
  242. // Metadata information
  243. $embyItem['metadata'] = array(
  244. 'guid' => $item['Id'],
  245. 'summary' => @(string)$item['Overview'],
  246. 'rating' => @(string)$item['CommunityRating'],
  247. 'duration' => @(string)$item['RunTimeTicks'],
  248. 'originallyAvailableAt' => @(string)$item['PremiereDate'],
  249. 'year' => (string)isset($item['ProductionYear']) ? $item['ProductionYear'] : '',
  250. //'studio' => (string)$item['studio'],
  251. 'tagline' => @(string)$item['Taglines'][0],
  252. 'genres' => ($item['Genres']) ? $genres : '',
  253. 'actors' => ($item['People']) ? $actors : ''
  254. );
  255. if (file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg')) {
  256. $embyItem['nowPlayingImageURL'] = $cacheDirectoryWeb . $embyItem['nowPlayingKey'] . '.jpg';
  257. }
  258. if (file_exists($cacheDirectory . $embyItem['key'] . '.jpg')) {
  259. $embyItem['imageURL'] = $cacheDirectoryWeb . $embyItem['key'] . '.jpg';
  260. }
  261. if (file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg') || !file_exists($cacheDirectory . $embyItem['nowPlayingKey'] . '.jpg')) {
  262. $embyItem['nowPlayingImageURL'] = 'api/?v1/image&source=emby&type=' . $embyItem['nowPlayingImageType'] . '&img=' . $embyItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $embyItem['nowPlayingKey'] . '';
  263. }
  264. if (file_exists($cacheDirectory . $embyItem['key'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $embyItem['key'] . '.jpg') || !file_exists($cacheDirectory . $embyItem['key'] . '.jpg')) {
  265. $embyItem['imageURL'] = 'api/?v1/image&source=emby&type=' . $embyItem['imageType'] . '&img=' . $embyItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $embyItem['key'] . '';
  266. }
  267. if (!$embyItem['nowPlayingThumb']) {
  268. $embyItem['nowPlayingOriginalImage'] = $embyItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png";
  269. $embyItem['nowPlayingKey'] = "no-np";
  270. }
  271. if (!$embyItem['thumb']) {
  272. $embyItem['originalImage'] = $embyItem['imageURL'] = "plugins/images/cache/no-list.png";
  273. $embyItem['key'] = "no-list";
  274. }
  275. if (isset($useImage)) {
  276. $embyItem['useImage'] = $useImage;
  277. }
  278. return $embyItem;
  279. }
  280. function getCacheImageSize($type)
  281. {
  282. switch ($type) {
  283. case 'height':
  284. case 'h':
  285. return 300 * $GLOBALS['cacheImageSize'];
  286. break;
  287. case 'width':
  288. case 'w':
  289. return 200 * $GLOBALS['cacheImageSize'];
  290. break;
  291. case 'nowPlayingHeight':
  292. case 'nph':
  293. return 675 * $GLOBALS['cacheImageSize'];
  294. break;
  295. case 'nowPlayingWidth':
  296. case 'npw':
  297. return 1200 * $GLOBALS['cacheImageSize'];
  298. break;
  299. }
  300. }
  301. function resolvePlexItem($item)
  302. {
  303. // Static Height & Width
  304. $height = getCacheImageSize('h');
  305. $width = getCacheImageSize('w');
  306. $nowPlayingHeight = getCacheImageSize('nph');
  307. $nowPlayingWidth = getCacheImageSize('npw');
  308. // Cache Directories
  309. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  310. $cacheDirectoryWeb = 'plugins/images/cache/';
  311. // Types
  312. switch ($item['type']) {
  313. case 'season':
  314. $plexItem['type'] = 'tv';
  315. $plexItem['title'] = (string)$item['parentTitle'];
  316. $plexItem['secondaryTitle'] = (string)$item['title'];
  317. $plexItem['summary'] = (string)$item['parentSummary'];
  318. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  319. $plexItem['thumb'] = (string)$item['thumb'];
  320. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  321. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  322. $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
  323. $plexItem['metadataKey'] = (string)$item['parentRatingKey'];
  324. break;
  325. case 'episode':
  326. $plexItem['type'] = 'tv';
  327. $plexItem['title'] = (string)$item['grandparentTitle'];
  328. $plexItem['secondaryTitle'] = (string)$item['parentTitle'];
  329. $plexItem['summary'] = (string)$item['title'];
  330. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  331. $plexItem['thumb'] = ($item['parentThumb'] ? (string)$item['parentThumb'] : (string)$item['grandparentThumb']);
  332. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  333. $plexItem['nowPlayingThumb'] = (string)$item['grandparentArt'];
  334. $plexItem['nowPlayingKey'] = (string)$item['grandparentRatingKey'] . "-np";
  335. $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'] . ' - ' . (string)$item['title'];
  336. $plexItem['nowPlayingBottom'] = 'S' . (string)$item['parentIndex'] . ' · E' . (string)$item['index'];
  337. $plexItem['metadataKey'] = (string)$item['grandparentRatingKey'];
  338. break;
  339. case 'clip':
  340. $useImage = (isset($item['live']) ? "plugins/images/cache/livetv.png" : null);
  341. $plexItem['type'] = 'clip';
  342. $plexItem['title'] = (isset($item['live']) ? 'Live TV' : (string)$item['title']);
  343. $plexItem['secondaryTitle'] = '';
  344. $plexItem['summary'] = (string)$item['summary'];
  345. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  346. $plexItem['thumb'] = (string)$item['thumb'];
  347. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  348. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  349. $plexItem['nowPlayingKey'] = isset($item['ratingKey']) ? (string)$item['ratingKey'] . "-np" : (isset($item['live']) ? "livetv.png" : ":)");
  350. $plexItem['nowPlayingTitle'] = $plexItem['title'];
  351. $plexItem['nowPlayingBottom'] = isset($item['extraType']) ? "Trailer" : (isset($item['live']) ? "Live TV" : ":)");
  352. break;
  353. case 'album':
  354. case 'track':
  355. $plexItem['type'] = 'music';
  356. $plexItem['title'] = (string)$item['parentTitle'];
  357. $plexItem['secondaryTitle'] = (string)$item['title'];
  358. $plexItem['summary'] = (string)$item['title'];
  359. $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
  360. $plexItem['thumb'] = (string)$item['thumb'];
  361. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  362. $plexItem['nowPlayingThumb'] = ($item['parentThumb']) ? (string)$item['parentThumb'] : (string)$item['art'];
  363. $plexItem['nowPlayingKey'] = (string)$item['parentRatingKey'] . "-np";
  364. $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'] . ' - ' . (string)$item['title'];
  365. $plexItem['nowPlayingBottom'] = (string)$item['parentTitle'];
  366. $plexItem['metadataKey'] = isset($item['grandparentRatingKey']) ? (string)$item['grandparentRatingKey'] : (string)$item['parentRatingKey'];
  367. break;
  368. default:
  369. $plexItem['type'] = 'movie';
  370. $plexItem['title'] = (string)$item['title'];
  371. $plexItem['secondaryTitle'] = (string)$item['year'];
  372. $plexItem['summary'] = (string)$item['summary'];
  373. $plexItem['ratingKey'] = (string)$item['ratingKey'];
  374. $plexItem['thumb'] = (string)$item['thumb'];
  375. $plexItem['key'] = (string)$item['ratingKey'] . "-list";
  376. $plexItem['nowPlayingThumb'] = (string)$item['art'];
  377. $plexItem['nowPlayingKey'] = (string)$item['ratingKey'] . "-np";
  378. $plexItem['nowPlayingTitle'] = (string)$item['title'];
  379. $plexItem['nowPlayingBottom'] = (string)$item['year'];
  380. $plexItem['metadataKey'] = (string)$item['ratingKey'];
  381. }
  382. $plexItem['uid'] = (string)$item['ratingKey'];
  383. $plexItem['elapsed'] = isset($item['viewOffset']) && $item['viewOffset'] !== '0' ? (int)$item['viewOffset'] : null;
  384. $plexItem['duration'] = isset($item['duration']) ? (int)$item['duration'] : (int)$item->Media['duration'];
  385. $plexItem['watched'] = ($plexItem['elapsed'] && $plexItem['duration'] ? floor(($plexItem['elapsed'] / $plexItem['duration']) * 100) : 0);
  386. $plexItem['transcoded'] = isset($item->TranscodeSession['progress']) ? floor((int)$item->TranscodeSession['progress'] - $plexItem['watched']) : '';
  387. $plexItem['stream'] = isset($item->Media->Part->Stream['decision']) ? (string)$item->Media->Part->Stream['decision'] : '';
  388. $plexItem['id'] = str_replace('"', '', (string)$item->Player['machineIdentifier']);
  389. $plexItem['session'] = (string)$item->Session['id'];
  390. $plexItem['bandwidth'] = (string)$item->Session['bandwidth'];
  391. $plexItem['bandwidthType'] = (string)$item->Session['location'];
  392. $plexItem['sessionType'] = isset($item->TranscodeSession['progress']) ? 'Transcoding' : 'Direct Playing';
  393. $plexItem['state'] = (((string)$item->Player['state'] == "paused") ? "pause" : "play");
  394. $plexItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? (string)$item->User['title'] : "";
  395. $plexItem['userThumb'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? (string)$item->User['thumb'] : "";
  396. $plexItem['userAddress'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? (string)$item->Player['address'] : "x.x.x.x";
  397. $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'];
  398. $plexItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=plex&img=' . $plexItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $plexItem['nowPlayingKey'] . '$' . randString();
  399. $plexItem['originalImage'] = 'api/?v1/image&source=plex&img=' . $plexItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $plexItem['key'] . '$' . randString();
  400. $plexItem['openTab'] = $GLOBALS['plexTabURL'] && $GLOBALS['plexTabName'] ? true : false;
  401. $plexItem['tabName'] = $GLOBALS['plexTabName'] ? $GLOBALS['plexTabName'] : '';
  402. // Stream info
  403. $plexItem['userStream'] = array(
  404. 'platform' => (string)$item->Player['platform'],
  405. 'product' => (string)$item->Player['product'],
  406. 'device' => (string)$item->Player['device'],
  407. 'stream' => (string)$item->Media->Part['decision'] . ($item->TranscodeSession['throttled'] == '1' ? ' (Throttled)' : ''),
  408. 'videoResolution' => (string)$item->Media['videoResolution'],
  409. 'throttled' => ($item->TranscodeSession['throttled'] == 1) ? true : false,
  410. 'sourceVideoCodec' => (string)$item->TranscodeSession['sourceVideoCodec'],
  411. 'videoCodec' => (string)$item->TranscodeSession['videoCodec'],
  412. 'audioCodec' => (string)$item->TranscodeSession['audioCodec'],
  413. 'sourceAudioCodec' => (string)$item->TranscodeSession['sourceAudioCodec'],
  414. 'videoDecision' => streamType((string)$item->TranscodeSession['videoDecision']),
  415. 'audioDecision' => streamType((string)$item->TranscodeSession['audioDecision']),
  416. 'container' => (string)$item->TranscodeSession['container'],
  417. 'audioChannels' => (string)$item->TranscodeSession['audioChannels']
  418. );
  419. // Genre catch all
  420. if ($item->Genre) {
  421. $genres = array();
  422. foreach ($item->Genre as $key => $value) {
  423. $genres[] = (string)$value['tag'];
  424. }
  425. }
  426. // Actor catch all
  427. if ($item->Role) {
  428. $actors = array();
  429. foreach ($item->Role as $key => $value) {
  430. if ($value['thumb']) {
  431. $actors[] = array(
  432. 'name' => (string)$value['tag'],
  433. 'role' => (string)$value['role'],
  434. 'thumb' => (string)$value['thumb']
  435. );
  436. }
  437. }
  438. }
  439. // Metadata information
  440. $plexItem['metadata'] = array(
  441. 'guid' => (string)$item['guid'],
  442. 'summary' => (string)$item['summary'],
  443. 'rating' => (string)$item['rating'],
  444. 'duration' => (string)$item['duration'],
  445. 'originallyAvailableAt' => (string)$item['originallyAvailableAt'],
  446. 'year' => (string)$item['year'],
  447. 'studio' => (string)$item['studio'],
  448. 'tagline' => (string)$item['tagline'],
  449. 'genres' => ($item->Genre) ? $genres : '',
  450. 'actors' => ($item->Role) ? $actors : ''
  451. );
  452. if (file_exists($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg')) {
  453. $plexItem['nowPlayingImageURL'] = $cacheDirectoryWeb . $plexItem['nowPlayingKey'] . '.jpg';
  454. }
  455. if (file_exists($cacheDirectory . $plexItem['key'] . '.jpg')) {
  456. $plexItem['imageURL'] = $cacheDirectoryWeb . $plexItem['key'] . '.jpg';
  457. }
  458. if (file_exists($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg') || !file_exists($cacheDirectory . $plexItem['nowPlayingKey'] . '.jpg')) {
  459. $plexItem['nowPlayingImageURL'] = 'api/?v1/image&source=plex&img=' . $plexItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $plexItem['nowPlayingKey'] . '';
  460. }
  461. if (file_exists($cacheDirectory . $plexItem['key'] . '.jpg') && (time() - 604800) > filemtime($cacheDirectory . $plexItem['key'] . '.jpg') || !file_exists($cacheDirectory . $plexItem['key'] . '.jpg')) {
  462. $plexItem['imageURL'] = 'api/?v1/image&source=plex&img=' . $plexItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $plexItem['key'] . '';
  463. }
  464. if (!$plexItem['nowPlayingThumb']) {
  465. $plexItem['nowPlayingOriginalImage'] = $plexItem['nowPlayingImageURL'] = "plugins/images/cache/no-np.png";
  466. $plexItem['nowPlayingKey'] = "no-np";
  467. }
  468. if (!$plexItem['thumb']) {
  469. $plexItem['originalImage'] = $plexItem['imageURL'] = "plugins/images/cache/no-list.png";
  470. $plexItem['key'] = "no-list";
  471. }
  472. if (isset($useImage)) {
  473. $plexItem['useImage'] = $useImage;
  474. }
  475. return $plexItem;
  476. }
  477. function plexConnect($action, $key = null)
  478. {
  479. if ($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']))) {
  480. $url = qualifyURL($GLOBALS['plexURL']);
  481. $ignore = array();
  482. $resolve = true;
  483. switch ($action) {
  484. case 'streams':
  485. $url = $url . "/status/sessions?X-Plex-Token=" . $GLOBALS['plexToken'];
  486. break;
  487. case 'libraries':
  488. $url = $url . "/library/sections?X-Plex-Token=" . $GLOBALS['plexToken'];
  489. $resolve = false;
  490. break;
  491. case 'recent':
  492. $url = $url . "/library/recentlyAdded?X-Plex-Token=" . $GLOBALS['plexToken'] . "&limit=" . $GLOBALS['homepageRecentLimit'];
  493. break;
  494. case 'metadata':
  495. $url = $url . "/library/metadata/" . $key . "?X-Plex-Token=" . $GLOBALS['plexToken'];
  496. break;
  497. case 'playlists':
  498. $url = $url . "/playlists?X-Plex-Token=" . $GLOBALS['plexToken'];
  499. break;
  500. case 'search':
  501. $url = $url . "/search?query=" . rawurlencode($key) . "&X-Plex-Token=" . $GLOBALS['plexToken'];
  502. $ignore = array('artist', 'episode');
  503. break;
  504. default:
  505. # code...
  506. break;
  507. }
  508. try {
  509. $options = (localURL($url)) ? array('verify' => false) : array();
  510. $response = Requests::get($url, array(), $options);
  511. libxml_use_internal_errors(true);
  512. if ($response->success) {
  513. $items = array();
  514. $plex = simplexml_load_string($response->body);
  515. foreach ($plex as $child) {
  516. if (!in_array($child['type'], $ignore) && isset($child['librarySectionID'])) {
  517. $items[] = resolvePlexItem($child);
  518. }
  519. }
  520. $api['content'] = ($resolve) ? $items : $plex;
  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 getPlexPlaylists()
  533. {
  534. if ($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']) && qualifyRequest($GLOBALS['homepagePlexPlaylistAuth']) && $GLOBALS['homepagePlexPlaylist'])) {
  535. $url = qualifyURL($GLOBALS['plexURL']);
  536. $url = $url . "/playlists?X-Plex-Token=" . $GLOBALS['plexToken'];
  537. try {
  538. $options = (localURL($url)) ? array('verify' => false) : array();
  539. $response = Requests::get($url, array(), $options);
  540. libxml_use_internal_errors(true);
  541. if ($response->success) {
  542. $items = array();
  543. $plex = simplexml_load_string($response->body);
  544. foreach ($plex as $child) {
  545. if ($child['playlistType'] == "video" && strpos(strtolower($child['title']), 'private') === false) {
  546. $playlistTitleClean = preg_replace("/(\W)+/", "", (string)$child['title']);
  547. $playlistURL = qualifyURL($GLOBALS['plexURL']);
  548. $playlistURL = $playlistURL . $child['key'] . "?X-Plex-Token=" . $GLOBALS['plexToken'];
  549. $options = (localURL($url)) ? array('verify' => false) : array();
  550. $playlistResponse = Requests::get($playlistURL, array(), $options);
  551. if ($playlistResponse->success) {
  552. $playlistResponse = simplexml_load_string($playlistResponse->body);
  553. $items[$playlistTitleClean]['title'] = (string)$child['title'];
  554. foreach ($playlistResponse->Video as $playlistItem) {
  555. $items[$playlistTitleClean][] = resolvePlexItem($playlistItem);
  556. }
  557. }
  558. }
  559. }
  560. $api['content'] = $items;
  561. $api['plexID'] = $GLOBALS['plexID'];
  562. $api['showNames'] = true;
  563. $api['group'] = '1';
  564. return $api;
  565. }
  566. } catch (Requests_Exception $e) {
  567. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  568. };
  569. }
  570. return false;
  571. }
  572. function embyConnect($action, $key = null, $skip = false)
  573. {
  574. if ($GLOBALS['homepageEmbyEnabled'] && !empty($GLOBALS['embyURL']) && !empty($GLOBALS['embyToken']) && qualifyRequest($GLOBALS['homepageEmbyAuth'])) {
  575. $url = qualifyURL($GLOBALS['embyURL']);
  576. switch ($action) {
  577. case 'streams':
  578. $url = $url . '/Sessions?api_key=' . $GLOBALS['embyToken'];
  579. break;
  580. case 'recent':
  581. $username = false;
  582. if (isset($GLOBALS['organizrUser']['username'])) {
  583. $username = strtolower($GLOBALS['organizrUser']['username']);
  584. }
  585. // Get A User
  586. $userIds = $url . "/Users?api_key=" . $GLOBALS['embyToken'];
  587. $showPlayed = true;
  588. try {
  589. $options = (localURL($userIds)) ? array('verify' => false) : array();
  590. $response = Requests::get($userIds, array(), $options);
  591. if ($response->success) {
  592. $emby = json_decode($response->body, true);
  593. foreach ($emby as $value) { // Scan for admin user
  594. if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
  595. $userId = $value['Id'];
  596. }
  597. if ($username && strtolower($value['Name']) == $username) {
  598. $userId = $value['Id'];
  599. $showPlayed = false;
  600. break;
  601. }
  602. }
  603. $url = $url . '/Users/' . $userId . '/Items/Latest?EnableImages=false&Limit=' . $GLOBALS['homepageRecentLimit'] . '&api_key=' . $GLOBALS['embyToken'] . ($showPlayed ? '' : '&IsPlayed=false');
  604. }
  605. } catch (Requests_Exception $e) {
  606. writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  607. };
  608. break;
  609. case 'metadata':
  610. $skip = true;
  611. break;
  612. default:
  613. # code...
  614. break;
  615. }
  616. if ($skip && $key) {
  617. $items[] = resolveEmbyItem(array('Id' => $key));
  618. $api['content'] = $items;
  619. return $api;
  620. }
  621. try {
  622. $options = (localURL($url)) ? array('verify' => false) : array();
  623. $response = Requests::get($url, array(), $options);
  624. if ($response->success) {
  625. $items = array();
  626. $emby = json_decode($response->body, true);
  627. foreach ($emby as $child) {
  628. if (isset($child['NowPlayingItem']) || isset($child['Name'])) {
  629. $items[] = resolveEmbyItem($child);
  630. }
  631. }
  632. $api['content'] = array_filter($items);
  633. return $api;
  634. }
  635. } catch (Requests_Exception $e) {
  636. writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  637. };
  638. }
  639. return false;
  640. }
  641. function sabnzbdConnect()
  642. {
  643. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  644. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  645. $url = $url . '/api?mode=queue&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  646. try {
  647. $options = (localURL($url)) ? array('verify' => false) : array();
  648. $response = Requests::get($url, array(), $options);
  649. if ($response->success) {
  650. $api['content']['queueItems'] = json_decode($response->body, true);
  651. }
  652. } catch (Requests_Exception $e) {
  653. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  654. };
  655. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  656. $url = $url . '/api?mode=history&output=json&limit=100&apikey=' . $GLOBALS['sabnzbdToken'];
  657. try {
  658. $options = (localURL($url)) ? array('verify' => false) : array();
  659. $response = Requests::get($url, array(), $options);
  660. if ($response->success) {
  661. $api['content']['historyItems'] = json_decode($response->body, true);
  662. }
  663. } catch (Requests_Exception $e) {
  664. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  665. };
  666. $api['content'] = isset($api['content']) ? $api['content'] : false;
  667. return $api;
  668. }
  669. return false;
  670. }
  671. function nzbgetConnect()
  672. {
  673. if ($GLOBALS['homepageNzbgetEnabled'] && !empty($GLOBALS['nzbgetURL']) && qualifyRequest($GLOBALS['homepageNzbgetAuth'])) {
  674. $url = qualifyURL($GLOBALS['nzbgetURL']);
  675. if (!empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  676. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/listgroups';
  677. } else {
  678. $url = $url . '/jsonrpc/listgroups';
  679. }
  680. try {
  681. $options = (localURL($url)) ? array('verify' => false) : array();
  682. $response = Requests::get($url, array(), $options);
  683. if ($response->success) {
  684. $api['content']['queueItems'] = json_decode($response->body, true);
  685. }
  686. } catch (Requests_Exception $e) {
  687. writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  688. };
  689. $url = qualifyURL($GLOBALS['nzbgetURL']);
  690. if (!empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  691. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/history';
  692. } else {
  693. $url = $url . '/jsonrpc/history';
  694. }
  695. try {
  696. $options = (localURL($url)) ? array('verify' => false) : array();
  697. $response = Requests::get($url, array(), $options);
  698. if ($response->success) {
  699. $api['content']['historyItems'] = json_decode($response->body, true);
  700. }
  701. } catch (Requests_Exception $e) {
  702. writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  703. };
  704. $api['content'] = isset($api['content']) ? $api['content'] : false;
  705. return $api;
  706. }
  707. return false;
  708. }
  709. function transmissionConnect()
  710. {
  711. if ($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])) {
  712. $digest = qualifyURL($GLOBALS['transmissionURL'], true);
  713. $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'] . ':' . decrypt($GLOBALS['transmissionPassword']) . "@" : '';
  714. $url = $digest['scheme'] . '://' . $passwordInclude . $digest['host'] . $digest['port'] . $digest['path'] . '/rpc';
  715. try {
  716. $options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false) : array();
  717. $response = Requests::get($url, array(), $options);
  718. if ($response->headers['x-transmission-session-id']) {
  719. $headers = array(
  720. 'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
  721. 'Content-Type' => 'application/json'
  722. );
  723. $data = array(
  724. 'method' => 'torrent-get',
  725. 'arguments' => array(
  726. 'fields' => array(
  727. "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir", "errorString"
  728. ),
  729. ),
  730. 'tags' => ''
  731. );
  732. $response = Requests::post($url, $headers, json_encode($data), $options);
  733. if ($response->success) {
  734. $torrentList = json_decode($response->body, true)['arguments']['torrents'];
  735. if ($GLOBALS['transmissionHideSeeding'] || $GLOBALS['transmissionHideCompleted']) {
  736. $filter = array();
  737. $torrents['arguments']['torrents'] = array();
  738. if ($GLOBALS['transmissionHideSeeding']) {
  739. array_push($filter, 6, 5);
  740. }
  741. if ($GLOBALS['transmissionHideCompleted']) {
  742. array_push($filter, 0);
  743. }
  744. foreach ($torrentList as $key => $value) {
  745. if (!in_array($value['status'], $filter)) {
  746. $torrents['arguments']['torrents'][] = $value;
  747. }
  748. }
  749. } else {
  750. $torrents = json_decode($response->body, true);
  751. }
  752. $api['content']['queueItems'] = $torrents;
  753. $api['content']['historyItems'] = false;
  754. }
  755. } else {
  756. writeLog('error', 'Transmission Connect Function - Error: Could not get session ID', 'SYSTEM');
  757. }
  758. } catch (Requests_Exception $e) {
  759. writeLog('error', 'Transmission Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  760. };
  761. $api['content'] = isset($api['content']) ? $api['content'] : false;
  762. return $api;
  763. }
  764. return false;
  765. }
  766. function rTorrentStatus($completed, $state, $status)
  767. {
  768. if ($completed && $state && $status == 'seed') {
  769. $state = 'Seeding';
  770. } elseif (!$completed && !$state && $status == 'leech') {
  771. $state = 'Stopped';
  772. } elseif (!$completed && $state && $status == 'leech') {
  773. $state = 'Downloading';
  774. } elseif ($completed && !$state && $status == 'seed') {
  775. $state = 'Finished';
  776. }
  777. return ($state) ? $state : $status;
  778. }
  779. function rTorrentConnect()
  780. {
  781. if ($GLOBALS['homepagerTorrentEnabled'] && !empty($GLOBALS['rTorrentURL']) && qualifyRequest($GLOBALS['homepagerTorrentAuth'])) {
  782. try {
  783. $torrents = array();
  784. $digest = (empty($GLOBALS['rTorrentURLOverride'])) ? qualifyURL($GLOBALS['rTorrentURL'], true) : qualifyURL(checkOverrideURL($GLOBALS['rTorrentURL'], $GLOBALS['rTorrentURLOverride']), true);
  785. $passwordInclude = ($GLOBALS['rTorrentUsername'] != '' && $GLOBALS['rTorrentPassword'] != '') ? $GLOBALS['rTorrentUsername'] . ':' . decrypt($GLOBALS['rTorrentPassword']) . "@" : '';
  786. $extraPath = (strpos($GLOBALS['rTorrentURL'], '.php') !== false) ? '' : '/RPC2';
  787. $extraPath = (empty($GLOBALS['rTorrentURLOverride'])) ? $extraPath : '';
  788. $url = $digest['scheme'] . '://' . $passwordInclude . $digest['host'] . $digest['port'] . $digest['path'] . $extraPath;
  789. $options = (localURL($url)) ? array('verify' => false) : array();
  790. $data = xmlrpc_encode_request("d.multicall2", array(
  791. "",
  792. "main",
  793. "d.name=",
  794. "d.base_path=",
  795. "d.up.total=",
  796. "d.size_bytes=",
  797. "d.down.total=",
  798. "d.completed_bytes=",
  799. "d.connection_current=",
  800. "d.down.rate=",
  801. "d.up.rate=",
  802. "d.timestamp.started=",
  803. "d.state=",
  804. "d.group.name=",
  805. "d.hash=",
  806. "d.complete=",
  807. "d.ratio=",
  808. "d.chunk_size=",
  809. "f.size_bytes=",
  810. "f.size_chunks=",
  811. "f.completed_chunks=",
  812. "d.custom=",
  813. "d.custom1=",
  814. "d.custom2=",
  815. "d.custom3=",
  816. "d.custom4=",
  817. "d.custom5=",
  818. ), array());
  819. $response = Requests::post($url, array(), $data, $options);
  820. if ($response->success) {
  821. $torrentList = xmlrpc_decode(str_replace('i8>', 'string>', $response->body));
  822. foreach ($torrentList as $key => $value) {
  823. $tempStatus = rTorrentStatus($value[13], $value[10], $value[6]);
  824. if ($tempStatus == 'Seeding' && $GLOBALS['rTorrentHideSeeding']) {
  825. //do nothing
  826. } elseif ($tempStatus == 'Finished' && $GLOBALS['rTorrentHideCompleted']) {
  827. //do nothing
  828. } else {
  829. $torrents[$key] = array(
  830. 'name' => $value[0],
  831. 'base' => $value[1],
  832. 'upTotal' => $value[2],
  833. 'size' => $value[3],
  834. 'downTotal' => $value[4],
  835. 'downloaded' => $value[5],
  836. 'connectionState' => $value[6],
  837. 'leech' => $value[7],
  838. 'seed' => $value[8],
  839. 'date' => $value[9],
  840. 'state' => ($value[10]) ? 'on' : 'off',
  841. 'group' => $value[11],
  842. 'hash' => $value[12],
  843. 'complete' => ($value[13]) ? 'yes' : 'no',
  844. 'ratio' => $value[14],
  845. 'label' => $value[20],
  846. 'status' => $tempStatus,
  847. 'temp' => $value[16] . ' - ' . $value[17] . ' - ' . $value[18],
  848. 'custom' => $value[19] . ' - ' . $value[20] . ' - ' . $value[21],
  849. 'custom2' => $value[22] . ' - ' . $value[23] . ' - ' . $value[24],
  850. );
  851. }
  852. }
  853. if (count($torrents) !== 0) {
  854. usort($torrents, function ($a, $b) {
  855. $direction = substr($GLOBALS['rTorrentSortOrder'], -1);
  856. $sort = substr($GLOBALS['rTorrentSortOrder'], 0, strlen($GLOBALS['rTorrentSortOrder']) - 1);
  857. switch ($direction) {
  858. case 'a':
  859. return $a[$sort] <=> $b[$sort];
  860. break;
  861. case 'd':
  862. return $b[$sort] <=> $a[$sort];
  863. break;
  864. default:
  865. return $b['date'] <=> $a['date'];
  866. }
  867. });
  868. }
  869. $api['content']['queueItems'] = $torrents;
  870. $api['content']['historyItems'] = false;
  871. }
  872. } catch
  873. (Requests_Exception $e) {
  874. writeLog('error', 'rTorrent Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  875. };
  876. $api['content'] = isset($api['content']) ? $api['content'] : false;
  877. return $api;
  878. }
  879. return false;
  880. }
  881. function qBittorrentConnect()
  882. {
  883. if ($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])) {
  884. $digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
  885. $data = array('username' => $GLOBALS['qBittorrentUsername'], 'password' => decrypt($GLOBALS['qBittorrentPassword']));
  886. $url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/login';
  887. try {
  888. $options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false) : array();
  889. $response = Requests::post($url, array(), $data, $options);
  890. $reflection = new ReflectionClass($response->cookies);
  891. $cookie = $reflection->getProperty("cookies");
  892. $cookie->setAccessible(true);
  893. $cookie = $cookie->getValue($response->cookies);
  894. if ($cookie) {
  895. $headers = array(
  896. 'Cookie' => 'SID=' . $cookie['SID']->value
  897. );
  898. $reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
  899. $url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/query/torrents?sort=' . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
  900. $response = Requests::get($url, $headers, $options);
  901. if ($response) {
  902. $torrentList = json_decode($response->body, true);
  903. if ($GLOBALS['qBittorrentHideSeeding'] || $GLOBALS['qBittorrentHideCompleted']) {
  904. $filter = array();
  905. $torrents['arguments']['torrents'] = array();
  906. if ($GLOBALS['qBittorrentHideSeeding']) {
  907. array_push($filter, 'uploading', 'stalledUP', 'queuedUP');
  908. }
  909. if ($GLOBALS['qBittorrentHideCompleted']) {
  910. array_push($filter, 'pausedUP');
  911. }
  912. foreach ($torrentList as $key => $value) {
  913. if (!in_array($value['state'], $filter)) {
  914. $torrents['arguments']['torrents'][] = $value;
  915. }
  916. }
  917. } else {
  918. $torrents['arguments']['torrents'] = json_decode($response->body, true);
  919. }
  920. $api['content']['queueItems'] = $torrents;
  921. $api['content']['historyItems'] = false;
  922. }
  923. } else {
  924. writeLog('error', 'qBittorrent Connect Function - Error: Could not get session ID', 'SYSTEM');
  925. }
  926. } catch (Requests_Exception $e) {
  927. writeLog('error', 'qBittorrent Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  928. };
  929. $api['content'] = isset($api['content']) ? $api['content'] : false;
  930. return $api;
  931. }
  932. return false;
  933. }
  934. function delugeStatus($queued, $status, $state)
  935. {
  936. if ($queued == '-1' && $state == '100' && ($status == 'Seeding' || $status == 'Queued' || $status == 'Paused')) {
  937. $state = 'Seeding';
  938. } elseif ($state !== '100') {
  939. $state = 'Downloading';
  940. } else {
  941. $state = 'Finished';
  942. }
  943. return ($state) ? $state : $status;
  944. }
  945. function delugeConnect()
  946. {
  947. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  948. try {
  949. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  950. $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');
  951. foreach ($torrents as $key => $value) {
  952. $tempStatus = delugeStatus($value->queue, $value->state, $value->progress);
  953. if ($tempStatus == 'Seeding' && $GLOBALS['delugeHideSeeding']) {
  954. //do nothing
  955. } elseif ($tempStatus == 'Finished' && $GLOBALS['delugeHideCompleted']) {
  956. //do nothing
  957. } else {
  958. $api['content']['queueItems'][] = $value;
  959. }
  960. }
  961. $api['content']['queueItems'] = (empty($api['content']['queueItems'])) ? [] : $api['content']['queueItems'];
  962. $api['content']['historyItems'] = false;
  963. } catch (Excecption $e) {
  964. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  965. }
  966. }
  967. $api['content'] = isset($api['content']) ? $api['content'] : false;
  968. return $api;
  969. }
  970. function getCalendar()
  971. {
  972. $startDate = date('Y-m-d', strtotime("-" . $GLOBALS['calendarStart'] . " days"));
  973. $endDate = date('Y-m-d', strtotime("+" . $GLOBALS['calendarEnd'] . " days"));
  974. $icalCalendarSources = array();
  975. $calendarItems = array();
  976. // SONARR CONNECT
  977. if ($GLOBALS['homepageSonarrEnabled'] && qualifyRequest($GLOBALS['homepageSonarrAuth']) && !empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
  978. $sonarrs = array();
  979. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  980. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  981. if (count($sonarrURLList) == count($sonarrTokenList)) {
  982. foreach ($sonarrURLList as $key => $value) {
  983. $sonarrs[$key] = array(
  984. 'url' => $value,
  985. 'token' => $sonarrTokenList[$key]
  986. );
  987. }
  988. foreach ($sonarrs as $key => $value) {
  989. try {
  990. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  991. $sonarr = $sonarr->getCalendar($startDate, $endDate, $GLOBALS['sonarrUnmonitored']);
  992. $result = json_decode($sonarr, true);
  993. $sonarrCalendar = (array_key_exists('error', $result)) ? '' : getSonarrCalendar($sonarr, $key);;
  994. } catch (Exception $e) {
  995. writeLog('error', 'Sonarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  996. }
  997. if (!empty($sonarrCalendar)) {
  998. $calendarItems = array_merge($calendarItems, $sonarrCalendar);
  999. }
  1000. }
  1001. }
  1002. }
  1003. // LIDARR CONNECT
  1004. if ($GLOBALS['homepageLidarrEnabled'] && qualifyRequest($GLOBALS['homepageLidarrAuth']) && !empty($GLOBALS['lidarrURL']) && !empty($GLOBALS['lidarrToken'])) {
  1005. $lidarrs = array();
  1006. $lidarrURLList = explode(',', $GLOBALS['lidarrURL']);
  1007. $lidarrTokenList = explode(',', $GLOBALS['lidarrToken']);
  1008. if (count($lidarrURLList) == count($lidarrTokenList)) {
  1009. foreach ($lidarrURLList as $key => $value) {
  1010. $lidarrs[$key] = array(
  1011. 'url' => $value,
  1012. 'token' => $lidarrTokenList[$key]
  1013. );
  1014. }
  1015. foreach ($lidarrs as $key => $value) {
  1016. try {
  1017. $lidarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token'], true);
  1018. $lidarr = $lidarr->getCalendar($startDate, $endDate);
  1019. $result = json_decode($lidarr, true);
  1020. $lidarrCalendar = (array_key_exists('error', $result)) ? '' : getLidarrCalendar($lidarr, $key);;
  1021. } catch (Exception $e) {
  1022. writeLog('error', 'Lidarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1023. }
  1024. if (!empty($lidarrCalendar)) {
  1025. $calendarItems = array_merge($calendarItems, $lidarrCalendar);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. // RADARR CONNECT
  1031. if ($GLOBALS['homepageRadarrEnabled'] && qualifyRequest($GLOBALS['homepageRadarrAuth']) && !empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
  1032. $radarrs = array();
  1033. $radarrURLList = explode(',', $GLOBALS['radarrURL']);
  1034. $radarrTokenList = explode(',', $GLOBALS['radarrToken']);
  1035. if (count($radarrURLList) == count($radarrTokenList)) {
  1036. foreach ($radarrURLList as $key => $value) {
  1037. $radarrs[$key] = array(
  1038. 'url' => $value,
  1039. 'token' => $radarrTokenList[$key]
  1040. );
  1041. }
  1042. foreach ($radarrs as $key => $value) {
  1043. try {
  1044. $radarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  1045. $radarr = $radarr->getCalendar($startDate, $endDate);
  1046. $result = json_decode($radarr, true);
  1047. $radarrCalendar = (array_key_exists('error', $result)) ? '' : getRadarrCalendar($radarr, $key, $value['url']);
  1048. } catch (Exception $e) {
  1049. writeLog('error', 'Radarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1050. }
  1051. if (!empty($radarrCalendar)) {
  1052. $calendarItems = array_merge($calendarItems, $radarrCalendar);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. // SICKRAGE/BEARD/MEDUSA CONNECT
  1058. if ($GLOBALS['homepageSickrageEnabled'] && qualifyRequest($GLOBALS['homepageSickrageAuth']) && !empty($GLOBALS['sickrageURL']) && !empty($GLOBALS['sickrageToken'])) {
  1059. $sicks = array();
  1060. $sickURLList = explode(',', $GLOBALS['sickrageURL']);
  1061. $sickTokenList = explode(',', $GLOBALS['sickrageToken']);
  1062. if (count($sickURLList) == count($sickTokenList)) {
  1063. foreach ($sickURLList as $key => $value) {
  1064. $sicks[$key] = array(
  1065. 'url' => $value,
  1066. 'token' => $sickTokenList[$key]
  1067. );
  1068. }
  1069. foreach ($sicks as $key => $value) {
  1070. try {
  1071. $sickrage = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
  1072. $sickrageFuture = getSickrageCalendarWanted($sickrage->future(), $key);
  1073. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100", "downloaded"), $key);
  1074. if (!empty($sickrageFuture)) {
  1075. $calendarItems = array_merge($calendarItems, $sickrageFuture);
  1076. }
  1077. if (!empty($sickrageHistory)) {
  1078. $calendarItems = array_merge($calendarItems, $sickrageHistory);
  1079. }
  1080. } catch (Exception $e) {
  1081. writeLog('error', 'Sickrage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1082. }
  1083. }
  1084. }
  1085. }
  1086. // COUCHPOTATO CONNECT
  1087. if ($GLOBALS['homepageCouchpotatoEnabled'] && qualifyRequest($GLOBALS['homepageCouchpotatoAuth']) && !empty($GLOBALS['couchpotatoURL']) && !empty($GLOBALS['couchpotatoToken'])) {
  1088. $couchs = array();
  1089. $couchpotatoURLList = explode(',', $GLOBALS['couchpotatoURL']);
  1090. $couchpotatoTokenList = explode(',', $GLOBALS['couchpotatoToken']);
  1091. if (count($couchpotatoURLList) == count($couchpotatoTokenList)) {
  1092. foreach ($couchpotatoURLList as $key => $value) {
  1093. $couchs[$key] = array(
  1094. 'url' => $value,
  1095. 'token' => $couchpotatoTokenList[$key]
  1096. );
  1097. }
  1098. foreach ($couchs as $key => $value) {
  1099. try {
  1100. $couchpotato = new Kryptonit3\CouchPotato\CouchPotato($value['url'], $value['token']);
  1101. $couchCalendar = getCouchCalendar($couchpotato->getMediaList(), $key);
  1102. if (!empty($couchCalendar)) {
  1103. $calendarItems = array_merge($calendarItems, $couchCalendar);
  1104. }
  1105. } catch (Exception $e) {
  1106. writeLog('error', 'Sickrage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1107. }
  1108. }
  1109. }
  1110. }
  1111. // iCal URL
  1112. if ($GLOBALS['homepageCalendarEnabled'] && qualifyRequest($GLOBALS['homepageCalendarAuth']) && !empty($GLOBALS['calendariCal'])) {
  1113. $calendars = array();
  1114. $calendarURLList = explode(',', $GLOBALS['calendariCal']);
  1115. $icalEvents = array();
  1116. foreach ($calendarURLList as $key => $value) {
  1117. $icsEvents = getIcsEventsAsArray($value);
  1118. if (isset($icsEvents) && !empty($icsEvents)) {
  1119. $timeZone = isset($icsEvents [1] ['X-WR-TIMEZONE']) ? trim($icsEvents[1]['X-WR-TIMEZONE']) : date_default_timezone_get();
  1120. unset($icsEvents [1]);
  1121. foreach ($icsEvents as $icsEvent) {
  1122. if ((isset($icsEvent['DTSTART']) || isset($icsEvent['DTSTART;VALUE=DATE'])) && (isset($icsEvent['DTEND']) || isset($icsEvent['DTEND;VALUE=DATE'])) && isset($icsEvent['SUMMARY'])) {
  1123. /* Getting start date and time */
  1124. $start = isset($icsEvent ['DTSTART;VALUE=DATE']) ? $icsEvent ['DTSTART;VALUE=DATE'] : $icsEvent ['DTSTART'];
  1125. /* Converting to datetime and apply the timezone to get proper date time */
  1126. $startDt = new DateTime ($start);
  1127. $startDt->setTimeZone(new DateTimezone ($timeZone));
  1128. $startDate = $startDt->format(DateTime::ATOM);
  1129. /* Getting end date with time */
  1130. $end = isset($icsEvent ['DTEND;VALUE=DATE']) ? $icsEvent ['DTEND;VALUE=DATE'] : $icsEvent ['DTEND'];
  1131. $endDt = new DateTime ($end);
  1132. $endDate = $endDt->format(DateTime::ATOM);
  1133. if (new DateTime() < $endDt) {
  1134. $extraClass = 'text-info';
  1135. } else {
  1136. $extraClass = 'text-success';
  1137. }
  1138. /* Getting the name of event */
  1139. $eventName = $icsEvent['SUMMARY'];
  1140. $icalEvents[] = array(
  1141. 'title' => $eventName,
  1142. 'imagetype' => 'calendar-o text-warning text-custom-calendar ' . $extraClass,
  1143. 'className' => 'bg-calendar calendar-item bg-custom-calendar',
  1144. 'start' => $startDate,
  1145. 'end' => $endDate
  1146. );
  1147. }
  1148. }
  1149. }
  1150. }
  1151. $calendarSources['ical'] = $icalEvents;
  1152. }
  1153. $calendarSources['events'] = $calendarItems;
  1154. return ($calendarSources) ? $calendarSources : false;
  1155. }
  1156. function getSonarrCalendar($array, $number)
  1157. {
  1158. $array = json_decode($array, true);
  1159. $gotCalendar = array();
  1160. $i = 0;
  1161. foreach ($array as $child) {
  1162. $i++;
  1163. $seriesName = $child['series']['title'];
  1164. $seriesID = $child['series']['tvdbId'];
  1165. $episodeID = $child['series']['tvdbId'];
  1166. $monitored = $child['monitored'];
  1167. if (!isset($episodeID)) {
  1168. $episodeID = "";
  1169. }
  1170. //$episodeName = htmlentities($child['title'], ENT_QUOTES);
  1171. $episodeAirDate = $child['airDateUtc'];
  1172. $episodeAirDate = strtotime($episodeAirDate);
  1173. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1174. if (new DateTime() < new DateTime($episodeAirDate)) {
  1175. $unaired = true;
  1176. }
  1177. if ($child['episodeNumber'] == "1") {
  1178. $episodePremier = "true";
  1179. } else {
  1180. $episodePremier = "false";
  1181. $date = new DateTime($episodeAirDate);
  1182. $date->add(new DateInterval("PT1S"));
  1183. $date->format(DateTime::ATOM);
  1184. $child['airDateUtc'] = gmdate('Y-m-d\TH:i:s\Z', strtotime($date->format(DateTime::ATOM)));
  1185. }
  1186. $downloaded = $child['hasFile'];
  1187. if ($downloaded == "0" && isset($unaired) && $episodePremier == "true") {
  1188. $downloaded = "text-primary animated flash";
  1189. } elseif ($downloaded == "0" && isset($unaired) && $monitored == "0") {
  1190. $downloaded = "text-dark";
  1191. } elseif ($downloaded == "0" && isset($unaired)) {
  1192. $downloaded = "text-info";
  1193. } elseif ($downloaded == "1") {
  1194. $downloaded = "text-success";
  1195. } else {
  1196. $downloaded = "text-danger";
  1197. }
  1198. $fanart = "/plugins/images/cache/no-np.png";
  1199. foreach ($child['series']['images'] as $image) {
  1200. if ($image['coverType'] == "fanart") {
  1201. $fanart = $image['url'];
  1202. }
  1203. }
  1204. if ($fanart !== "/plugins/images/cache/no-np.png") {
  1205. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1206. $imageURL = $fanart;
  1207. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1208. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1209. if (!file_exists($cacheFile)) {
  1210. cacheImage($imageURL, $seriesID);
  1211. unset($imageURL);
  1212. unset($cacheFile);
  1213. }
  1214. }
  1215. $bottomTitle = 'S' . sprintf("%02d", $child['seasonNumber']) . 'E' . sprintf("%02d", $child['episodeNumber']) . ' - ' . $child['title'];
  1216. $details = array(
  1217. "seasonCount" => $child['series']['seasonCount'],
  1218. "status" => $child['series']['status'],
  1219. "topTitle" => $seriesName,
  1220. "bottomTitle" => $bottomTitle,
  1221. "overview" => isset($child['overview']) ? $child['overview'] : '',
  1222. "runtime" => $child['series']['runtime'],
  1223. "image" => $fanart,
  1224. "ratings" => $child['series']['ratings']['value'],
  1225. "videoQuality" => $child["hasFile"] ? $child['episodeFile']['quality']['quality']['name'] : "unknown",
  1226. "audioChannels" => $child["hasFile"] && isset($child['episodeFile']['mediaInfo']) ? $child['episodeFile']['mediaInfo']['audioChannels'] : "unknown",
  1227. "audioCodec" => $child["hasFile"] && isset($child['episodeFile']['mediaInfo']) ? $child['episodeFile']['mediaInfo']['audioCodec'] : "unknown",
  1228. "videoCodec" => $child["hasFile"] && isset($child['episodeFile']['mediaInfo']) ? $child['episodeFile']['mediaInfo']['videoCodec'] : "unknown",
  1229. "size" => $child["hasFile"] ? $child['episodeFile']['size'] : "unknown",
  1230. "genres" => $child['series']['genres'],
  1231. );
  1232. array_push($gotCalendar, array(
  1233. "id" => "Sonarr-" . $number . "-" . $i,
  1234. "title" => $seriesName,
  1235. "start" => $child['airDateUtc'],
  1236. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1237. "imagetype" => "tv " . $downloaded,
  1238. "imagetypeFilter" => "tv",
  1239. "downloadFilter" => $downloaded,
  1240. "bgColor" => str_replace('text', 'bg', $downloaded),
  1241. "details" => $details
  1242. ));
  1243. }
  1244. if ($i != 0) {
  1245. return $gotCalendar;
  1246. }
  1247. return false;
  1248. }
  1249. function getLidarrCalendar($array, $number)
  1250. {
  1251. $array = json_decode($array, true);
  1252. $gotCalendar = array();
  1253. $i = 0;
  1254. foreach ($array as $child) {
  1255. $i++;
  1256. $albumName = $child['title'];
  1257. $artistName = $child['artist']['artistName'];
  1258. $albumID = '';
  1259. $releaseDate = $child['releaseDate'];
  1260. $releaseDate = strtotime($releaseDate);
  1261. $releaseDate = date("Y-m-d H:i:s", $releaseDate);
  1262. if (new DateTime() < new DateTime($releaseDate)) {
  1263. $unaired = true;
  1264. }
  1265. $downloaded = (isset($child['statistics']['percentOfEpisodes']) && $child['statistics']['percentOfEpisodes'] !== '100.0') ? '0' : '1';
  1266. if ($downloaded == "0" && isset($unaired)) {
  1267. $downloaded = "text-info";
  1268. } elseif ($downloaded == "1") {
  1269. $downloaded = "text-success";
  1270. } else {
  1271. $downloaded = "text-danger";
  1272. }
  1273. $fanart = "/plugins/images/cache/no-np.png";
  1274. foreach ($child['artist']['images'] as $image) {
  1275. if ($image['coverType'] == "fanart") {
  1276. $fanart = str_replace('http://', 'https://', $image['url']);
  1277. }
  1278. }
  1279. $details = array(
  1280. "seasonCount" => '',
  1281. "status" => '',
  1282. "topTitle" => $albumName,
  1283. "bottomTitle" => $artistName,
  1284. "overview" => isset($child['artist']['overview']) ? $child['artist']['overview'] : '',
  1285. "runtime" => '',
  1286. "image" => $fanart,
  1287. "ratings" => $child['artist']['ratings']['value'],
  1288. "videoQuality" => "unknown",
  1289. "audioChannels" => "unknown",
  1290. "audioCodec" => "unknown",
  1291. "videoCodec" => "unknown",
  1292. "size" => "unknown",
  1293. "genres" => $child['genres'],
  1294. );
  1295. array_push($gotCalendar, array(
  1296. "id" => "Lidarr-" . $number . "-" . $i,
  1297. "title" => $artistName,
  1298. "start" => $child['releaseDate'],
  1299. "className" => "bg-calendar calendar-item musicID--",
  1300. "imagetype" => "music " . $downloaded,
  1301. "imagetypeFilter" => "music",
  1302. "downloadFilter" => $downloaded,
  1303. "bgColor" => str_replace('text', 'bg', $downloaded),
  1304. "details" => $details
  1305. ));
  1306. }
  1307. if ($i != 0) {
  1308. return $gotCalendar;
  1309. }
  1310. return false;
  1311. }
  1312. function getRadarrCalendar($array, $number, $url)
  1313. {
  1314. $array = json_decode($array, true);
  1315. $gotCalendar = array();
  1316. $i = 0;
  1317. foreach ($array as $child) {
  1318. if (isset($child['physicalRelease'])) {
  1319. $i++;
  1320. $movieName = $child['title'];
  1321. $movieID = $child['tmdbId'];
  1322. if (!isset($movieID)) {
  1323. $movieID = "";
  1324. }
  1325. $physicalRelease = $child['physicalRelease'];
  1326. $physicalRelease = strtotime($physicalRelease);
  1327. $physicalRelease = date("Y-m-d", $physicalRelease);
  1328. if (new DateTime() < new DateTime($physicalRelease)) {
  1329. $notReleased = "true";
  1330. } else {
  1331. $notReleased = "false";
  1332. }
  1333. $downloaded = $child['hasFile'];
  1334. if ($downloaded == "0" && $notReleased == "true") {
  1335. $downloaded = "text-info";
  1336. } elseif ($downloaded == "1") {
  1337. $downloaded = "text-success";
  1338. } else {
  1339. $downloaded = "text-danger";
  1340. }
  1341. $banner = "/plugins/images/cache/no-np.png";
  1342. foreach ($child['images'] as $image) {
  1343. if ($image['coverType'] == "banner" || $image['coverType'] == "fanart") {
  1344. $url = rtrim($url, '/'); //remove trailing slash
  1345. $imageUrl = $image['url'];
  1346. $urlParts = explode("/", $url);
  1347. $imageParts = explode("/", $image['url']);
  1348. if ($imageParts[1] == end($urlParts)) {
  1349. unset($imageParts[1]);
  1350. $imageUrl = implode("/", $imageParts);
  1351. }
  1352. $banner = $url . $imageUrl;
  1353. }
  1354. }
  1355. if ($banner !== "/plugins/images/cache/no-np.png") {
  1356. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1357. $imageURL = $banner;
  1358. $cacheFile = $cacheDirectory . $movieID . '.jpg';
  1359. $banner = 'plugins/images/cache/' . $movieID . '.jpg';
  1360. if (!file_exists($cacheFile)) {
  1361. cacheImage($imageURL, $movieID);
  1362. unset($imageURL);
  1363. unset($cacheFile);
  1364. }
  1365. }
  1366. $alternativeTitles = "";
  1367. foreach ($child['alternativeTitles'] as $alternative) {
  1368. $alternativeTitles .= $alternative['title'] . ', ';
  1369. }
  1370. $alternativeTitles = empty($child['alternativeTitles']) ? "" : substr($alternativeTitles, 0, -2);
  1371. $details = array(
  1372. "topTitle" => $movieName,
  1373. "bottomTitle" => $alternativeTitles,
  1374. "status" => $child['status'],
  1375. "overview" => $child['overview'],
  1376. "runtime" => $child['runtime'],
  1377. "image" => $banner,
  1378. "ratings" => $child['ratings']['value'],
  1379. "videoQuality" => $child["hasFile"] ? @$child['movieFile']['quality']['quality']['name'] : "unknown",
  1380. "audioChannels" => $child["hasFile"] ? @$child['movieFile']['mediaInfo']['audioChannels'] : "unknown",
  1381. "audioCodec" => $child["hasFile"] ? @$child['movieFile']['mediaInfo']['audioFormat'] : "unknown",
  1382. "videoCodec" => $child["hasFile"] ? @$child['movieFile']['mediaInfo']['videoCodec'] : "unknown",
  1383. "size" => $child["hasFile"] ? @$child['movieFile']['size'] : "unknown",
  1384. "genres" => $child['genres'],
  1385. );
  1386. array_push($gotCalendar, array(
  1387. "id" => "Radarr-" . $number . "-" . $i,
  1388. "title" => $movieName,
  1389. "start" => $physicalRelease,
  1390. "className" => "bg-calendar movieID--" . $movieID,
  1391. "imagetype" => "film " . $downloaded,
  1392. "imagetypeFilter" => "film",
  1393. "downloadFilter" => $downloaded,
  1394. "bgColor" => str_replace('text', 'bg', $downloaded),
  1395. "details" => $details
  1396. ));
  1397. }
  1398. }
  1399. if ($i != 0) {
  1400. return $gotCalendar;
  1401. }
  1402. return false;
  1403. }
  1404. function getCouchCalendar($array, $number)
  1405. {
  1406. $api = json_decode($array, true);
  1407. $gotCalendar = array();
  1408. $i = 0;
  1409. foreach ($api['movies'] as $child) {
  1410. if ($child['status'] == "active" || $child['status'] == "done") {
  1411. $i++;
  1412. $movieName = $child['info']['original_title'];
  1413. $movieID = $child['info']['tmdb_id'];
  1414. if (!isset($movieID)) {
  1415. $movieID = "";
  1416. }
  1417. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  1418. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  1419. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  1420. $physicalRelease = strtotime($physicalRelease);
  1421. $physicalRelease = date("Y-m-d", $physicalRelease);
  1422. if (new DateTime() < new DateTime($physicalRelease)) {
  1423. $notReleased = "true";
  1424. } else {
  1425. $notReleased = "false";
  1426. }
  1427. $downloaded = ($child['status'] == "active") ? "0" : "1";
  1428. if ($downloaded == "0" && $notReleased == "true") {
  1429. $downloaded = "text-info";
  1430. } elseif ($downloaded == "1") {
  1431. $downloaded = "text-success";
  1432. } else {
  1433. $downloaded = "text-danger";
  1434. }
  1435. if (!empty($child['info']['images']['backdrop_original'])) {
  1436. $banner = $child['info']['images']['backdrop_original'][0];
  1437. } elseif (!empty($child['info']['images']['backdrop'])) {
  1438. $banner = $child['info']['images']['backdrop_original'][0];
  1439. } else {
  1440. $banner = "/plugins/images/cache/no-np.png";
  1441. }
  1442. if ($banner !== "/plugins/images/cache/no-np.png") {
  1443. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1444. $imageURL = $banner;
  1445. $cacheFile = $cacheDirectory . $movieID . '.jpg';
  1446. $banner = 'plugins/images/cache/' . $movieID . '.jpg';
  1447. if (!file_exists($cacheFile)) {
  1448. cacheImage($imageURL, $movieID);
  1449. unset($imageURL);
  1450. unset($cacheFile);
  1451. }
  1452. }
  1453. $hasFile = (!empty($child['releases']) && !empty($child['releases'][0]['files']['movie']));
  1454. $details = array(
  1455. "topTitle" => $movieName,
  1456. "bottomTitle" => $child['info']['tagline'],
  1457. "status" => $child['status'],
  1458. "overview" => $child['info']['plot'],
  1459. "runtime" => $child['info']['runtime'],
  1460. "image" => $banner,
  1461. "ratings" => isset($child['info']['rating']['imdb'][0]) ? $child['info']['rating']['imdb'][0] : '',
  1462. "videoQuality" => $hasFile ? $child['releases'][0]['quality'] : "unknown",
  1463. "audioChannels" => "",
  1464. "audioCodec" => "",
  1465. "videoCodec" => "",
  1466. "genres" => $child['info']['genres'],
  1467. );
  1468. array_push($gotCalendar, array(
  1469. "id" => "CouchPotato-" . $number . "-" . $i,
  1470. "title" => $movieName,
  1471. "start" => $physicalRelease,
  1472. "className" => "bg-calendar calendar-item movieID--" . $movieID,
  1473. "imagetype" => "film " . $downloaded,
  1474. "imagetypeFilter" => "film",
  1475. "downloadFilter" => $downloaded,
  1476. "bgColor" => str_replace('text', 'bg', $downloaded),
  1477. "details" => $details
  1478. ));
  1479. }
  1480. }
  1481. if ($i != 0) {
  1482. return $gotCalendar;
  1483. }
  1484. return false;
  1485. }
  1486. function getSickrageCalendarWanted($array, $number)
  1487. {
  1488. $array = json_decode($array, true);
  1489. $gotCalendar = array();
  1490. $i = 0;
  1491. foreach ($array['data']['missed'] as $child) {
  1492. $i++;
  1493. $seriesName = $child['show_name'];
  1494. $seriesID = $child['tvdbid'];
  1495. $episodeID = $child['tvdbid'];
  1496. $episodeAirDate = $child['airdate'];
  1497. $episodeAirDateTime = explode(" ", $child['airs']);
  1498. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1499. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1500. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1501. if (new DateTime() < new DateTime($episodeAirDate)) {
  1502. $unaired = true;
  1503. }
  1504. $downloaded = "0";
  1505. if ($downloaded == "0" && isset($unaired)) {
  1506. $downloaded = "text-info";
  1507. } elseif ($downloaded == "1") {
  1508. $downloaded = "text-success";
  1509. } else {
  1510. $downloaded = "text-danger";
  1511. }
  1512. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1513. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1514. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1515. $fanart = "/plugins/images/cache/no-np.png";
  1516. if (file_exists($cacheFile)) {
  1517. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1518. unset($cacheFile);
  1519. }
  1520. $details = array(
  1521. "seasonCount" => "",
  1522. "status" => $child['show_status'],
  1523. "topTitle" => $seriesName,
  1524. "bottomTitle" => $bottomTitle,
  1525. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1526. "runtime" => "",
  1527. "image" => $fanart,
  1528. "ratings" => "",
  1529. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1530. "audioChannels" => "",
  1531. "audioCodec" => "",
  1532. "videoCodec" => "",
  1533. "size" => "",
  1534. "genres" => "",
  1535. );
  1536. array_push($gotCalendar, array(
  1537. "id" => "Sick-" . $number . "-Miss-" . $i,
  1538. "title" => $seriesName,
  1539. "start" => $episodeAirDate,
  1540. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1541. "imagetype" => "tv " . $downloaded,
  1542. "imagetypeFilter" => "tv",
  1543. "downloadFilter" => $downloaded,
  1544. "bgColor" => str_replace('text', 'bg', $downloaded),
  1545. "details" => $details,
  1546. ));
  1547. }
  1548. foreach ($array['data']['today'] as $child) {
  1549. $i++;
  1550. $seriesName = $child['show_name'];
  1551. $seriesID = $child['tvdbid'];
  1552. $episodeID = $child['tvdbid'];
  1553. $episodeAirDate = $child['airdate'];
  1554. $episodeAirDateTime = explode(" ", $child['airs']);
  1555. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1556. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1557. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1558. if (new DateTime() < new DateTime($episodeAirDate)) {
  1559. $unaired = true;
  1560. }
  1561. $downloaded = "0";
  1562. if ($downloaded == "0" && isset($unaired)) {
  1563. $downloaded = "text-info";
  1564. } elseif ($downloaded == "1") {
  1565. $downloaded = "text-success";
  1566. } else {
  1567. $downloaded = "text-danger";
  1568. }
  1569. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1570. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1571. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1572. $fanart = "/plugins/images/cache/no-np.png";
  1573. if (file_exists($cacheFile)) {
  1574. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1575. unset($cacheFile);
  1576. }
  1577. $details = array(
  1578. "seasonCount" => "",
  1579. "status" => $child['show_status'],
  1580. "topTitle" => $seriesName,
  1581. "bottomTitle" => $bottomTitle,
  1582. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1583. "runtime" => "",
  1584. "image" => $fanart,
  1585. "ratings" => "",
  1586. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1587. "audioChannels" => "",
  1588. "audioCodec" => "",
  1589. "videoCodec" => "",
  1590. "size" => "",
  1591. "genres" => "",
  1592. );
  1593. array_push($gotCalendar, array(
  1594. "id" => "Sick-" . $number . "-Today-" . $i,
  1595. "title" => $seriesName,
  1596. "start" => $episodeAirDate,
  1597. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1598. "imagetype" => "tv " . $downloaded,
  1599. "imagetypeFilter" => "tv",
  1600. "downloadFilter" => $downloaded,
  1601. "bgColor" => str_replace('text', 'bg', $downloaded),
  1602. "details" => $details,
  1603. ));
  1604. }
  1605. foreach ($array['data']['soon'] as $child) {
  1606. $i++;
  1607. $seriesName = $child['show_name'];
  1608. $seriesID = $child['tvdbid'];
  1609. $episodeID = $child['tvdbid'];
  1610. $episodeAirDate = $child['airdate'];
  1611. $episodeAirDateTime = explode(" ", $child['airs']);
  1612. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1613. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1614. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1615. if (new DateTime() < new DateTime($episodeAirDate)) {
  1616. $unaired = true;
  1617. }
  1618. $downloaded = "0";
  1619. if ($downloaded == "0" && isset($unaired)) {
  1620. $downloaded = "text-info";
  1621. } elseif ($downloaded == "1") {
  1622. $downloaded = "text-success";
  1623. } else {
  1624. $downloaded = "text-danger";
  1625. }
  1626. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1627. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1628. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1629. $fanart = "/plugins/images/cache/no-np.png";
  1630. if (file_exists($cacheFile)) {
  1631. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1632. unset($cacheFile);
  1633. }
  1634. $details = array(
  1635. "seasonCount" => "",
  1636. "status" => $child['show_status'],
  1637. "topTitle" => $seriesName,
  1638. "bottomTitle" => $bottomTitle,
  1639. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1640. "runtime" => "",
  1641. "image" => $fanart,
  1642. "ratings" => "",
  1643. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1644. "audioChannels" => "",
  1645. "audioCodec" => "",
  1646. "videoCodec" => "",
  1647. "size" => "",
  1648. "genres" => "",
  1649. );
  1650. array_push($gotCalendar, array(
  1651. "id" => "Sick-" . $number . "-Soon-" . $i,
  1652. "title" => $seriesName,
  1653. "start" => $episodeAirDate,
  1654. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1655. "imagetype" => "tv " . $downloaded,
  1656. "imagetypeFilter" => "tv",
  1657. "downloadFilter" => $downloaded,
  1658. "bgColor" => str_replace('text', 'bg', $downloaded),
  1659. "details" => $details,
  1660. ));
  1661. }
  1662. foreach ($array['data']['later'] as $child) {
  1663. $i++;
  1664. $seriesName = $child['show_name'];
  1665. $seriesID = $child['tvdbid'];
  1666. $episodeID = $child['tvdbid'];
  1667. $episodeAirDate = $child['airdate'];
  1668. $episodeAirDateTime = explode(" ", $child['airs']);
  1669. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1670. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1671. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1672. if (new DateTime() < new DateTime($episodeAirDate)) {
  1673. $unaired = true;
  1674. }
  1675. $downloaded = "0";
  1676. if ($downloaded == "0" && isset($unaired)) {
  1677. $downloaded = "text-info";
  1678. } elseif ($downloaded == "1") {
  1679. $downloaded = "text-success";
  1680. } else {
  1681. $downloaded = "text-danger";
  1682. }
  1683. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1684. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1685. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1686. $fanart = "/plugins/images/cache/no-np.png";
  1687. if (file_exists($cacheFile)) {
  1688. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1689. unset($cacheFile);
  1690. }
  1691. $details = array(
  1692. "seasonCount" => "",
  1693. "status" => $child['show_status'],
  1694. "topTitle" => $seriesName,
  1695. "bottomTitle" => $bottomTitle,
  1696. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1697. "runtime" => "",
  1698. "image" => $fanart,
  1699. "ratings" => "",
  1700. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1701. "audioChannels" => "",
  1702. "audioCodec" => "",
  1703. "videoCodec" => "",
  1704. "size" => "",
  1705. "genres" => "",
  1706. );
  1707. array_push($gotCalendar, array(
  1708. "id" => "Sick-" . $number . "-Later-" . $i,
  1709. "title" => $seriesName,
  1710. "start" => $episodeAirDate,
  1711. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1712. "imagetype" => "tv " . $downloaded,
  1713. "imagetypeFilter" => "tv",
  1714. "downloadFilter" => $downloaded,
  1715. "bgColor" => str_replace('text', 'bg', $downloaded),
  1716. "details" => $details,
  1717. ));
  1718. }
  1719. if ($i != 0) {
  1720. return $gotCalendar;
  1721. }
  1722. return false;
  1723. }
  1724. function getSickrageCalendarHistory($array, $number)
  1725. {
  1726. $array = json_decode($array, true);
  1727. $gotCalendar = array();
  1728. $i = 0;
  1729. foreach ($array['data'] as $child) {
  1730. $i++;
  1731. $seriesName = $child['show_name'];
  1732. $seriesID = $child['tvdbid'];
  1733. $episodeID = $child['tvdbid'];
  1734. $episodeAirDate = $child['date'];
  1735. $downloaded = "text-success";
  1736. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']);
  1737. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1738. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1739. $fanart = "/plugins/images/cache/no-np.png";
  1740. if (file_exists($cacheFile)) {
  1741. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1742. unset($cacheFile);
  1743. }
  1744. $details = array(
  1745. "seasonCount" => "",
  1746. "status" => $child['status'],
  1747. "topTitle" => $seriesName,
  1748. "bottomTitle" => $bottomTitle,
  1749. "overview" => '',
  1750. "runtime" => isset($child['series']['runtime']) ? $child['series']['runtime'] : 30,
  1751. "image" => $fanart,
  1752. "ratings" => isset($child['series']['ratings']['value']) ? $child['series']['ratings']['value'] : "unknown",
  1753. "videoQuality" => isset($child["quality"]) ? $child['quality'] : "unknown",
  1754. "audioChannels" => "",
  1755. "audioCodec" => "",
  1756. "videoCodec" => "",
  1757. "size" => "",
  1758. "genres" => "",
  1759. );
  1760. array_push($gotCalendar, array(
  1761. "id" => "Sick-" . $number . "-History-" . $i,
  1762. "title" => $seriesName,
  1763. "start" => $episodeAirDate,
  1764. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1765. "imagetype" => "tv " . $downloaded,
  1766. "imagetypeFilter" => "tv",
  1767. "downloadFilter" => $downloaded,
  1768. "bgColor" => str_replace('text', 'bg', $downloaded),
  1769. "details" => $details,
  1770. ));
  1771. }
  1772. if ($i != 0) {
  1773. return $gotCalendar;
  1774. }
  1775. return false;
  1776. }
  1777. function ombiAPI($array)
  1778. {
  1779. return ombiAction($array['data']['id'], $array['data']['action'], $array['data']['type'], $array['data']);
  1780. }
  1781. function ombiImport($type = null)
  1782. {
  1783. if (!empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && !empty($type)) {
  1784. try {
  1785. $url = qualifyURL($GLOBALS['ombiURL']);
  1786. $headers = array(
  1787. "Accept" => "application/json",
  1788. "Content-Type" => "application/json",
  1789. "Apikey" => $GLOBALS['ombiToken']
  1790. );
  1791. $options = (localURL($url)) ? array('verify' => false) : array();
  1792. switch ($type) {
  1793. case 'emby':
  1794. case 'emby_local':
  1795. case 'emby_connect':
  1796. case 'emby_all':
  1797. $response = Requests::post($url . "/api/v1/Job/embyuserimporter", $headers, $options);
  1798. break;
  1799. case 'plex':
  1800. $response = Requests::post($url . "/api/v1/Job/plexuserimporter", $headers, $options);
  1801. break;
  1802. default:
  1803. break;
  1804. }
  1805. if ($response->success) {
  1806. writeLog('success', 'OMBI Connect Function - Ran User Import', 'SYSTEM');
  1807. return true;
  1808. } else {
  1809. writeLog('error', 'OMBI Connect Function - Error: Connection Unsuccessful', 'SYSTEM');
  1810. return false;
  1811. }
  1812. } catch (Requests_Exception $e) {
  1813. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1814. return false;
  1815. };
  1816. }
  1817. return false;
  1818. }
  1819. function ombiAction($id, $action, $type, $fullArray = null)
  1820. {
  1821. if ($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])) {
  1822. $url = qualifyURL($GLOBALS['ombiURL']);
  1823. $headers = array(
  1824. "Accept" => "application/json",
  1825. "Content-Type" => "application/json",
  1826. "Apikey" => $GLOBALS['ombiToken']
  1827. );
  1828. $data = array(
  1829. 'id' => $id,
  1830. );
  1831. switch ($type) {
  1832. case 'season':
  1833. case 'tv':
  1834. $type = 'tv';
  1835. $add = array(
  1836. 'tvDbId' => $id,
  1837. 'requestAll' => ombiTVDefault('all'),
  1838. 'latestSeason' => ombiTVDefault('last'),
  1839. 'firstSeason' => ombiTVDefault('first')
  1840. );
  1841. break;
  1842. default:
  1843. $type = 'movie';
  1844. $add = array("theMovieDbId" => (int)$id);
  1845. break;
  1846. }
  1847. $success['head'] = $headers;
  1848. $success['act'] = $action;
  1849. $success['data'] = $data;
  1850. $success['add'] = $add;
  1851. $success['type'] = $type;
  1852. try {
  1853. $options = (localURL($url)) ? array('verify' => false) : array();
  1854. switch ($action) {
  1855. case 'add':
  1856. if (isset($_COOKIE['Auth'])) {
  1857. $headers = array(
  1858. "Accept" => "application/json",
  1859. "Content-Type" => "application/json",
  1860. "Authorization" => "Bearer " . $_COOKIE['Auth']
  1861. );
  1862. $success['head'] = $headers;
  1863. } else {
  1864. return false;
  1865. }
  1866. $response = Requests::post($url . "/api/v1/Request/" . $type, $headers, json_encode($add), $options);
  1867. break;
  1868. default:
  1869. if (qualifyRequest(1)) {
  1870. switch ($action) {
  1871. case 'approve':
  1872. $response = Requests::post($url . "/api/v1/Request/" . $type . "/approve", $headers, json_encode($data), $options);
  1873. break;
  1874. case 'available':
  1875. $response = Requests::post($url . "/api/v1/Request/" . $type . "/available", $headers, json_encode($data), $options);
  1876. break;
  1877. case 'unavailable':
  1878. $response = Requests::post($url . "/api/v1/Request/" . $type . "/unavailable", $headers, json_encode($data), $options);
  1879. break;
  1880. case 'deny':
  1881. $response = Requests::put($url . "/api/v1/Request/" . $type . "/deny", $headers, json_encode($data), $options);
  1882. break;
  1883. case 'delete':
  1884. $response = Requests::delete($url . "/api/v1/Request/" . $type . "/" . $id, $headers, $options);
  1885. break;
  1886. default:
  1887. return false;
  1888. }
  1889. }
  1890. break;
  1891. }
  1892. $success['api'] = $response;
  1893. $success['bd'] = $response->body;
  1894. $success['hd'] = $response->headers;
  1895. if ($response->success) {
  1896. $success['ok'] = true;
  1897. }
  1898. } catch (Requests_Exception $e) {
  1899. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1900. };
  1901. }
  1902. return isset($success['ok']) ? $success : false;
  1903. }
  1904. function getOmbiRequests($type = "both")
  1905. {
  1906. if ($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])) {
  1907. $url = qualifyURL($GLOBALS['ombiURL']);
  1908. $headers = array(
  1909. "Accept" => "application/json",
  1910. "Apikey" => $GLOBALS['ombiToken'],
  1911. );
  1912. $requests = array();
  1913. try {
  1914. $options = (localURL($url)) ? array('verify' => false) : array();
  1915. switch ($type) {
  1916. case 'movie':
  1917. $movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
  1918. break;
  1919. case 'tv':
  1920. $tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
  1921. break;
  1922. default:
  1923. $movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
  1924. $tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
  1925. break;
  1926. }
  1927. if ($movie->success || $tv->success) {
  1928. if (isset($movie)) {
  1929. $movie = json_decode($movie->body, true);
  1930. //$movie = array_reverse($movie);
  1931. foreach ($movie as $key => $value) {
  1932. $proceed = (($GLOBALS['ombiLimitUser']) && strtolower($GLOBALS['organizrUser']['username']) == strtolower($value['requestedUser']['userName'])) || (!$GLOBALS['ombiLimitUser']) || qualifyRequest(1) ? true : false;
  1933. if ($proceed) {
  1934. $requests[] = array(
  1935. 'test' => $value,
  1936. 'id' => $value['theMovieDbId'],
  1937. 'title' => $value['title'],
  1938. 'overview' => $value['overview'],
  1939. 'poster' => (isset($value['posterPath']) && $value['posterPath'] !== '') ? 'https://image.tmdb.org/t/p/w300/' . $value['posterPath'] : '',
  1940. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/' . $value['background'] : '',
  1941. 'approved' => $value['approved'],
  1942. 'available' => $value['available'],
  1943. 'denied' => $value['denied'],
  1944. 'deniedReason' => $value['deniedReason'],
  1945. 'user' => $value['requestedUser']['userName'],
  1946. 'userAlias' => $value['requestedUser']['userAlias'],
  1947. 'request_id' => $value['id'],
  1948. 'request_date' => $value['requestedDate'],
  1949. 'release_date' => $value['releaseDate'],
  1950. 'type' => 'movie',
  1951. 'icon' => 'mdi mdi-filmstrip',
  1952. 'color' => 'palette-Deep-Purple-900 bg white',
  1953. );
  1954. }
  1955. }
  1956. }
  1957. if (isset($tv) && (is_array($tv) || is_object($tv))) {
  1958. $tv = json_decode($tv->body, true);
  1959. foreach ($tv as $key => $value) {
  1960. if (count($value['childRequests']) > 0) {
  1961. $proceed = (($GLOBALS['ombiLimitUser']) && strtolower($GLOBALS['organizrUser']['username']) == strtolower($value['childRequests'][0]['requestedUser']['userName'])) || (!$GLOBALS['ombiLimitUser']) || qualifyRequest(1) ? true : false;
  1962. if ($proceed) {
  1963. $requests[] = array(
  1964. 'test' => $value,
  1965. 'id' => $value['tvDbId'],
  1966. 'title' => $value['title'],
  1967. 'overview' => $value['overview'],
  1968. 'poster' => $value['posterPath'],
  1969. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/' . $value['background'] : '',
  1970. 'approved' => $value['childRequests'][0]['approved'],
  1971. 'available' => $value['childRequests'][0]['available'],
  1972. 'denied' => $value['childRequests'][0]['denied'],
  1973. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  1974. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  1975. 'userAlias' => $value['childRequests'][0]['requestedUser']['userAlias'],
  1976. 'request_id' => $value['id'],
  1977. 'request_date' => $value['childRequests'][0]['requestedDate'],
  1978. 'release_date' => $value['releaseDate'],
  1979. 'type' => 'tv',
  1980. 'icon' => 'mdi mdi-television',
  1981. 'color' => 'grayish-blue-bg',
  1982. );
  1983. }
  1984. }
  1985. }
  1986. }
  1987. //sort here
  1988. usort($requests, function ($item1, $item2) {
  1989. if ($item1['request_date'] == $item2['request_date']) {
  1990. return 0;
  1991. }
  1992. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  1993. });
  1994. }
  1995. } catch (Requests_Exception $e) {
  1996. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1997. };
  1998. }
  1999. $api['content'] = isset($requests) ? $requests : false;
  2000. return $api;
  2001. }
  2002. function testAPIConnection($array)
  2003. {
  2004. switch ($array['data']['action']) {
  2005. case 'ombi':
  2006. if (!empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken'])) {
  2007. $url = qualifyURL($GLOBALS['ombiURL']);
  2008. $url = $url . "/api/v1/Status/info";
  2009. $headers = array(
  2010. "Accept" => "application/json",
  2011. "Content-Type" => "application/json",
  2012. "Apikey" => $GLOBALS['ombiToken']
  2013. );
  2014. try {
  2015. $options = (localURL($url)) ? array('verify' => false) : array();
  2016. $response = Requests::get($url, $headers, $options);
  2017. if ($response->success) {
  2018. return true;
  2019. } else {
  2020. return $response->body;
  2021. }
  2022. } catch (Requests_Exception $e) {
  2023. return $e->getMessage();
  2024. };
  2025. } else {
  2026. return 'URL and/or Token not setup';
  2027. }
  2028. break;
  2029. case 'plex':
  2030. if (!empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken'])) {
  2031. $url = qualifyURL($GLOBALS['plexURL']);
  2032. $url = $url . "/?X-Plex-Token=" . $GLOBALS['plexToken'];
  2033. try {
  2034. $options = (localURL($url)) ? array('verify' => false) : array();
  2035. $response = Requests::get($url, array(), $options);
  2036. libxml_use_internal_errors(true);
  2037. if ($response->success) {
  2038. return true;
  2039. }
  2040. } catch (Requests_Exception $e) {
  2041. return $e->getMessage();
  2042. };
  2043. } else {
  2044. return 'URL and/or Token not setup';
  2045. }
  2046. break;
  2047. case 'emby':
  2048. break;
  2049. case 'sonarr':
  2050. if (!empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
  2051. $sonarrs = array();
  2052. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  2053. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  2054. if (count($sonarrURLList) == count($sonarrTokenList)) {
  2055. foreach ($sonarrURLList as $key => $value) {
  2056. $sonarrs[$key] = array(
  2057. 'url' => $value,
  2058. 'token' => $sonarrTokenList[$key]
  2059. );
  2060. }
  2061. foreach ($sonarrs as $key => $value) {
  2062. try {
  2063. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  2064. $result = json_decode($sonarr->getSystemStatus(), true);
  2065. return (array_key_exists('error', $result)) ? $result['error']['msg'] : true;
  2066. } catch (Exception $e) {
  2067. return strip($e->getMessage());
  2068. }
  2069. }
  2070. }
  2071. } else {
  2072. return 'URL/s and/or Token/s not setup';
  2073. }
  2074. break;
  2075. case 'lidarr':
  2076. if (!empty($GLOBALS['lidarrURL']) && !empty($GLOBALS['lidarrToken'])) {
  2077. $sonarrs = array();
  2078. $sonarrURLList = explode(',', $GLOBALS['lidarrURL']);
  2079. $sonarrTokenList = explode(',', $GLOBALS['lidarrToken']);
  2080. if (count($sonarrURLList) == count($sonarrTokenList)) {
  2081. foreach ($sonarrURLList as $key => $value) {
  2082. $sonarrs[$key] = array(
  2083. 'url' => $value,
  2084. 'token' => $sonarrTokenList[$key]
  2085. );
  2086. }
  2087. foreach ($sonarrs as $key => $value) {
  2088. try {
  2089. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token'], true);
  2090. $result = json_decode($sonarr->getSystemStatus(), true);
  2091. return (array_key_exists('error', $result)) ? $result['error']['msg'] : true;
  2092. } catch (Exception $e) {
  2093. return $e->getMessage();
  2094. }
  2095. }
  2096. }
  2097. } else {
  2098. return 'URL/s and/or Token/s not setup';
  2099. }
  2100. break;
  2101. case 'radarr':
  2102. if (!empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
  2103. $sonarrs = array();
  2104. $sonarrURLList = explode(',', $GLOBALS['radarrURL']);
  2105. $sonarrTokenList = explode(',', $GLOBALS['radarrToken']);
  2106. if (count($sonarrURLList) == count($sonarrTokenList)) {
  2107. foreach ($sonarrURLList as $key => $value) {
  2108. $sonarrs[$key] = array(
  2109. 'url' => $value,
  2110. 'token' => $sonarrTokenList[$key]
  2111. );
  2112. }
  2113. foreach ($sonarrs as $key => $value) {
  2114. try {
  2115. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  2116. $result = json_decode($sonarr->getSystemStatus(), true);
  2117. return (array_key_exists('error', $result)) ? $result['error']['msg'] : true;
  2118. } catch (Exception $e) {
  2119. return $e->getMessage();
  2120. }
  2121. }
  2122. }
  2123. } else {
  2124. return 'URL/s and/or Token/s not setup';
  2125. }
  2126. break;
  2127. case 'sabnzbd':
  2128. if (!empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken'])) {
  2129. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  2130. $url = $url . '/api?mode=queue&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  2131. try {
  2132. $options = (localURL($url)) ? array('verify' => false) : array();
  2133. $response = Requests::get($url, array(), $options);
  2134. if ($response->success) {
  2135. return true;
  2136. }
  2137. } catch (Requests_Exception $e) {
  2138. return $e->getMessage();
  2139. };
  2140. } else {
  2141. return 'URL and/or Token not setup';
  2142. }
  2143. break;
  2144. case 'nzbget':
  2145. if (!empty($GLOBALS['nzbgetURL'])) {
  2146. $url = qualifyURL($GLOBALS['nzbgetURL']);
  2147. if (!empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  2148. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/listgroups';
  2149. } else {
  2150. $url = $url . '/jsonrpc/listgroups';
  2151. }
  2152. try {
  2153. $options = (localURL($url)) ? array('verify' => false) : array();
  2154. $response = Requests::get($url, array(), $options);
  2155. if ($response->success) {
  2156. return true;
  2157. }
  2158. } catch (Requests_Exception $e) {
  2159. return $e->getMessage();
  2160. };
  2161. } else {
  2162. return 'URL and/or Username/Password not setup';
  2163. }
  2164. break;
  2165. case 'deluge':
  2166. if (!empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword'])) {
  2167. try {
  2168. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  2169. $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');
  2170. return true;
  2171. } catch (Exception $e) {
  2172. return $e->getMessage();
  2173. }
  2174. } else {
  2175. return 'URL and/or Password not setup';
  2176. }
  2177. break;
  2178. case 'rtorrent':
  2179. if (!empty($GLOBALS['rTorrentURL'])) {
  2180. try {
  2181. $digest = (empty($GLOBALS['rTorrentURLOverride'])) ? qualifyURL($GLOBALS['rTorrentURL'], true) : qualifyURL(checkOverrideURL($GLOBALS['rTorrentURL'], $GLOBALS['rTorrentURLOverride']), true);
  2182. $passwordInclude = ($GLOBALS['rTorrentUsername'] != '' && $GLOBALS['rTorrentPassword'] != '') ? $GLOBALS['rTorrentUsername'] . ':' . decrypt($GLOBALS['rTorrentPassword']) . "@" : '';
  2183. $extraPath = (strpos($GLOBALS['rTorrentURL'], '.php') !== false) ? '' : '/RPC2';
  2184. $extraPath = (empty($GLOBALS['rTorrentURLOverride'])) ? $extraPath : '';
  2185. $url = $digest['scheme'] . '://' . $passwordInclude . $digest['host'] . $digest['port'] . $digest['path'] . $extraPath;
  2186. $options = (localURL($url)) ? array('verify' => false) : array();
  2187. $data = xmlrpc_encode_request("system.listMethods", null);
  2188. $response = Requests::post($url, array(), $data, $options);
  2189. if ($response->success) {
  2190. $methods = xmlrpc_decode(str_replace('i8>', 'i4>', $response->body));
  2191. if (count($methods) !== 0) {
  2192. return true;
  2193. }
  2194. }
  2195. return false;
  2196. } catch
  2197. (Requests_Exception $e) {
  2198. writeLog('error', 'rTorrent Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  2199. return $e->getMessage();
  2200. };
  2201. }
  2202. break;
  2203. default :
  2204. return false;
  2205. }
  2206. return false;
  2207. }