homepage-connect-functions.php 80 KB

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