homepage-connect-functions.php 74 KB

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