homepage-connect-functions.php 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  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. if (!empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  637. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/listgroups';
  638. } else {
  639. $url = $url . '/jsonrpc/listgroups';
  640. }
  641. try {
  642. $options = (localURL($url)) ? array('verify' => false) : array();
  643. $response = Requests::get($url, array(), $options);
  644. if ($response->success) {
  645. $api['content']['queueItems'] = json_decode($response->body, true);
  646. }
  647. } catch (Requests_Exception $e) {
  648. writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  649. };
  650. $url = qualifyURL($GLOBALS['nzbgetURL']);
  651. if (!empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  652. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/history';
  653. } else {
  654. $url = $url . '/jsonrpc/history';
  655. }
  656. try {
  657. $options = (localURL($url)) ? array('verify' => false) : array();
  658. $response = Requests::get($url, array(), $options);
  659. if ($response->success) {
  660. $api['content']['historyItems'] = json_decode($response->body, true);
  661. }
  662. } catch (Requests_Exception $e) {
  663. writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  664. };
  665. $api['content'] = isset($api['content']) ? $api['content'] : false;
  666. return $api;
  667. }
  668. return false;
  669. }
  670. function transmissionConnect()
  671. {
  672. if ($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])) {
  673. $digest = qualifyURL($GLOBALS['transmissionURL'], true);
  674. $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'] . ':' . decrypt($GLOBALS['transmissionPassword']) . "@" : '';
  675. $url = $digest['scheme'] . '://' . $passwordInclude . $digest['host'] . $digest['port'] . $digest['path'] . '/rpc';
  676. try {
  677. $options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false) : array();
  678. $response = Requests::get($url, array(), $options);
  679. if ($response->headers['x-transmission-session-id']) {
  680. $headers = array(
  681. 'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
  682. 'Content-Type' => 'application/json'
  683. );
  684. $data = array(
  685. 'method' => 'torrent-get',
  686. 'arguments' => array(
  687. 'fields' => array(
  688. "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir", "errorString"
  689. ),
  690. ),
  691. 'tags' => ''
  692. );
  693. $response = Requests::post($url, $headers, json_encode($data), $options);
  694. if ($response->success) {
  695. $torrentList = json_decode($response->body, true)['arguments']['torrents'];
  696. if ($GLOBALS['transmissionHideSeeding'] || $GLOBALS['transmissionHideCompleted']) {
  697. $filter = array();
  698. $torrents['arguments']['torrents'] = array();
  699. if ($GLOBALS['transmissionHideSeeding']) {
  700. array_push($filter, 6, 5);
  701. }
  702. if ($GLOBALS['transmissionHideCompleted']) {
  703. array_push($filter, 0);
  704. }
  705. foreach ($torrentList as $key => $value) {
  706. if (!in_array($value['status'], $filter)) {
  707. $torrents['arguments']['torrents'][] = $value;
  708. }
  709. }
  710. } else {
  711. $torrents = json_decode($response->body, true);
  712. }
  713. $api['content']['queueItems'] = $torrents;
  714. $api['content']['historyItems'] = false;
  715. }
  716. } else {
  717. writeLog('error', 'Transmission Connect Function - Error: Could not get session ID', 'SYSTEM');
  718. }
  719. } catch (Requests_Exception $e) {
  720. writeLog('error', 'Transmission Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  721. };
  722. $api['content'] = isset($api['content']) ? $api['content'] : false;
  723. return $api;
  724. }
  725. return false;
  726. }
  727. function qBittorrentConnect()
  728. {
  729. if ($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])) {
  730. $digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
  731. $data = array('username' => $GLOBALS['qBittorrentUsername'], 'password' => decrypt($GLOBALS['qBittorrentPassword']));
  732. $url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/login';
  733. try {
  734. $options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false) : array();
  735. $response = Requests::post($url, array(), $data, $options);
  736. $reflection = new ReflectionClass($response->cookies);
  737. $cookie = $reflection->getProperty("cookies");
  738. $cookie->setAccessible(true);
  739. $cookie = $cookie->getValue($response->cookies);
  740. if ($cookie) {
  741. $headers = array(
  742. 'Cookie' => 'SID=' . $cookie['SID']->value
  743. );
  744. $reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
  745. $url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/query/torrents?sort=' . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
  746. $response = Requests::get($url, $headers, $options);
  747. if ($response) {
  748. $torrentList = json_decode($response->body, true);
  749. if ($GLOBALS['qBittorrentHideSeeding'] || $GLOBALS['qBittorrentHideCompleted']) {
  750. $filter = array();
  751. $torrents['arguments']['torrents'] = array();
  752. if ($GLOBALS['qBittorrentHideSeeding']) {
  753. array_push($filter, 'uploading', 'stalledUP', 'queuedUP');
  754. }
  755. if ($GLOBALS['qBittorrentHideCompleted']) {
  756. array_push($filter, 'pausedUP');
  757. }
  758. foreach ($torrentList as $key => $value) {
  759. if (!in_array($value['state'], $filter)) {
  760. $torrents['arguments']['torrents'][] = $value;
  761. }
  762. }
  763. } else {
  764. $torrents['arguments']['torrents'] = json_decode($response->body, true);
  765. }
  766. $api['content']['queueItems'] = $torrents;
  767. $api['content']['historyItems'] = false;
  768. }
  769. } else {
  770. writeLog('error', 'qBittorrent Connect Function - Error: Could not get session ID', 'SYSTEM');
  771. }
  772. } catch (Requests_Exception $e) {
  773. writeLog('error', 'qBittorrent Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  774. };
  775. $api['content'] = isset($api['content']) ? $api['content'] : false;
  776. return $api;
  777. }
  778. return false;
  779. }
  780. function delugeConnect()
  781. {
  782. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  783. try {
  784. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  785. $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');
  786. if ($GLOBALS['delugeHideSeeding'] || $GLOBALS['delugeHideCompleted']) {
  787. $filter = array();
  788. if ($GLOBALS['delugeHideSeeding']) {
  789. array_push($filter, 'Seeding', 'Uploading', 'queuedUP');
  790. }
  791. if ($GLOBALS['delugeHideCompleted']) {
  792. array_push($filter, 'Seeding', 'Completed');
  793. }
  794. //prettyPrint($torrents);
  795. foreach ($torrents as $key => $value) {
  796. if (!in_array($value->state, $filter)) {
  797. $api['content']['queueItems'][] = $value;
  798. }
  799. }
  800. } else {
  801. $api['content']['queueItems'] = $torrents;
  802. }
  803. $api['content']['queueItems'] = (empty($api['content']['queueItems'])) ? [] : $api['content']['queueItems'];
  804. $api['content']['historyItems'] = false;
  805. } catch (Excecption $e) {
  806. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  807. }
  808. }
  809. $api['content'] = isset($api['content']) ? $api['content'] : false;
  810. return $api;
  811. }
  812. function getCalendar()
  813. {
  814. $startDate = date('Y-m-d', strtotime("-" . $GLOBALS['calendarStart'] . " days"));
  815. $endDate = date('Y-m-d', strtotime("+" . $GLOBALS['calendarEnd'] . " days"));
  816. $icalCalendarSources = array();
  817. $calendarItems = array();
  818. // SONARR CONNECT
  819. if ($GLOBALS['homepageSonarrEnabled'] && qualifyRequest($GLOBALS['homepageSonarrAuth']) && !empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
  820. $sonarrs = array();
  821. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  822. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  823. if (count($sonarrURLList) == count($sonarrTokenList)) {
  824. foreach ($sonarrURLList as $key => $value) {
  825. $sonarrs[$key] = array(
  826. 'url' => $value,
  827. 'token' => $sonarrTokenList[$key]
  828. );
  829. }
  830. foreach ($sonarrs as $key => $value) {
  831. try {
  832. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  833. $sonarrCalendar = getSonarrCalendar($sonarr->getCalendar($startDate, $endDate), $key);
  834. } catch (Exception $e) {
  835. writeLog('error', 'Sonarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  836. }
  837. if (!empty($sonarrCalendar)) {
  838. $calendarItems = array_merge($calendarItems, $sonarrCalendar);
  839. }
  840. }
  841. }
  842. }
  843. // RADARR CONNECT
  844. if ($GLOBALS['homepageRadarrEnabled'] && qualifyRequest($GLOBALS['homepageRadarrAuth']) && !empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
  845. $radarrs = array();
  846. $radarrURLList = explode(',', $GLOBALS['radarrURL']);
  847. $radarrTokenList = explode(',', $GLOBALS['radarrToken']);
  848. if (count($radarrURLList) == count($radarrTokenList)) {
  849. foreach ($radarrURLList as $key => $value) {
  850. $radarrs[$key] = array(
  851. 'url' => $value,
  852. 'token' => $radarrTokenList[$key]
  853. );
  854. }
  855. foreach ($radarrs as $key => $value) {
  856. try {
  857. $radarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  858. $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate), $key, $value['url']);
  859. } catch (Exception $e) {
  860. writeLog('error', 'Radarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  861. }
  862. if (!empty($radarrCalendar)) {
  863. $calendarItems = array_merge($calendarItems, $radarrCalendar);
  864. }
  865. }
  866. }
  867. }
  868. // SICKRAGE/BEARD/MEDUSA CONNECT
  869. if ($GLOBALS['homepageSickrageEnabled'] && qualifyRequest($GLOBALS['homepageSickrageAuth']) && !empty($GLOBALS['sickrageURL']) && !empty($GLOBALS['sickrageToken'])) {
  870. $sicks = array();
  871. $sickURLList = explode(',', $GLOBALS['sickrageURL']);
  872. $sickTokenList = explode(',', $GLOBALS['sickrageToken']);
  873. if (count($sickURLList) == count($sickTokenList)) {
  874. foreach ($sickURLList as $key => $value) {
  875. $sicks[$key] = array(
  876. 'url' => $value,
  877. 'token' => $sickTokenList[$key]
  878. );
  879. }
  880. foreach ($sicks as $key => $value) {
  881. try {
  882. $sickrage = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
  883. $sickrageFuture = getSickrageCalendarWanted($sickrage->future(), $key);
  884. $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100", "downloaded"), $key);
  885. if (!empty($sickrageFuture)) {
  886. $calendarItems = array_merge($calendarItems, $sickrageFuture);
  887. }
  888. if (!empty($sickrageHistory)) {
  889. $calendarItems = array_merge($calendarItems, $sickrageHistory);
  890. }
  891. } catch (Exception $e) {
  892. writeLog('error', 'Sickrage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  893. }
  894. }
  895. }
  896. }
  897. // COUCHPOTATO CONNECT
  898. if ($GLOBALS['homepageCouchpotatoEnabled'] && qualifyRequest($GLOBALS['homepageCouchpotatoAuth']) && !empty($GLOBALS['couchpotatoURL']) && !empty($GLOBALS['couchpotatoToken'])) {
  899. $couchs = array();
  900. $couchpotatoURLList = explode(',', $GLOBALS['couchpotatoURL']);
  901. $couchpotatoTokenList = explode(',', $GLOBALS['couchpotatoToken']);
  902. if (count($couchpotatoURLList) == count($couchpotatoTokenList)) {
  903. foreach ($couchpotatoURLList as $key => $value) {
  904. $couchs[$key] = array(
  905. 'url' => $value,
  906. 'token' => $couchpotatoTokenList[$key]
  907. );
  908. }
  909. foreach ($couchs as $key => $value) {
  910. try {
  911. $couchpotato = new Kryptonit3\CouchPotato\CouchPotato($value['url'], $value['token']);
  912. $couchCalendar = getCouchCalendar($couchpotato->getMediaList(), $key);
  913. if (!empty($couchCalendar)) {
  914. $calendarItems = array_merge($calendarItems, $couchCalendar);
  915. }
  916. } catch (Exception $e) {
  917. writeLog('error', 'Sickrage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  918. }
  919. }
  920. }
  921. }
  922. // iCal URL
  923. if ($GLOBALS['homepageCalendarEnabled'] && qualifyRequest($GLOBALS['homepageCalendarAuth']) && !empty($GLOBALS['calendariCal'])) {
  924. $calendars = array();
  925. $calendarURLList = explode(',', $GLOBALS['calendariCal']);
  926. $icalEvents = array();
  927. foreach ($calendarURLList as $key => $value) {
  928. $icsEvents = getIcsEventsAsArray($value);
  929. if (isset($icsEvents) && !empty($icsEvents)) {
  930. $timeZone = trim($icsEvents [1] ['X-WR-TIMEZONE']);
  931. unset($icsEvents [1]);
  932. foreach ($icsEvents as $icsEvent) {
  933. if (isset($icsEvent['DTSTART']) && isset($icsEvent['DTEND']) && isset($icsEvent['SUMMARY'])) {
  934. /* Getting start date and time */
  935. $start = isset($icsEvent ['DTSTART;VALUE=DATE']) ? $icsEvent ['DTSTART;VALUE=DATE'] : $icsEvent ['DTSTART'];
  936. /* Converting to datetime and apply the timezone to get proper date time */
  937. $startDt = new DateTime ($start);
  938. $startDt->setTimeZone(new DateTimezone ($timeZone));
  939. $startDate = $startDt->format(DateTime::ATOM);
  940. /* Getting end date with time */
  941. $end = isset($icsEvent ['DTEND;VALUE=DATE']) ? $icsEvent ['DTEND;VALUE=DATE'] : $icsEvent ['DTEND'];
  942. $endDt = new DateTime ($end);
  943. $endDate = $endDt->format(DateTime::ATOM);
  944. if (new DateTime() < $endDt) {
  945. $extraClass = 'text-info';
  946. } else {
  947. $extraClass = 'text-success';
  948. }
  949. /* Getting the name of event */
  950. $eventName = $icsEvent['SUMMARY'];
  951. $icalEvents[] = array(
  952. 'title' => $eventName,
  953. 'imagetype' => 'calendar-o text-warning text-custom-calendar ' . $extraClass,
  954. 'className' => 'bg-calendar calendar-item bg-custom-calendar',
  955. 'start' => $startDate,
  956. 'end' => $endDate
  957. );
  958. }
  959. }
  960. }
  961. }
  962. $calendarSources['ical'] = $icalEvents;
  963. }
  964. $calendarSources['events'] = $calendarItems;
  965. return ($calendarSources) ? $calendarSources : false;
  966. }
  967. function getSonarrCalendar($array, $number)
  968. {
  969. $array = json_decode($array, true);
  970. $gotCalendar = array();
  971. $i = 0;
  972. foreach ($array as $child) {
  973. $i++;
  974. $seriesName = $child['series']['title'];
  975. $seriesID = $child['series']['tvdbId'];
  976. $episodeID = $child['series']['tvdbId'];
  977. $monitored = $child['monitored'];
  978. if (!isset($episodeID)) {
  979. $episodeID = "";
  980. }
  981. //$episodeName = htmlentities($child['title'], ENT_QUOTES);
  982. if ($child['episodeNumber'] == "1") {
  983. $episodePremier = "true";
  984. } else {
  985. $episodePremier = "false";
  986. }
  987. $episodeAirDate = $child['airDateUtc'];
  988. $episodeAirDate = strtotime($episodeAirDate);
  989. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  990. if (new DateTime() < new DateTime($episodeAirDate)) {
  991. $unaired = true;
  992. }
  993. $downloaded = $child['hasFile'];
  994. if ($downloaded == "0" && isset($unaired) && $episodePremier == "true") {
  995. $downloaded = "text-primary animated flash";
  996. } elseif ($downloaded == "0" && isset($unaired) && $monitored == "0") {
  997. $downloaded = "text-dark";
  998. } elseif ($downloaded == "0" && isset($unaired)) {
  999. $downloaded = "text-info";
  1000. } elseif ($downloaded == "1") {
  1001. $downloaded = "text-success";
  1002. } else {
  1003. $downloaded = "text-danger";
  1004. }
  1005. $fanart = "/plugins/images/cache/no-np.png";
  1006. foreach ($child['series']['images'] as $image) {
  1007. if ($image['coverType'] == "fanart") {
  1008. $fanart = $image['url'];
  1009. }
  1010. }
  1011. if ($fanart !== "/plugins/images/cache/no-np.png") {
  1012. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1013. $imageURL = $fanart;
  1014. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1015. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1016. if (!file_exists($cacheFile)) {
  1017. cacheImage($imageURL, $seriesID);
  1018. unset($imageURL);
  1019. unset($cacheFile);
  1020. }
  1021. }
  1022. $bottomTitle = 'S' . sprintf("%02d", $child['seasonNumber']) . 'E' . sprintf("%02d", $child['episodeNumber']) . ' - ' . $child['title'];
  1023. $details = array(
  1024. "seasonCount" => $child['series']['seasonCount'],
  1025. "status" => $child['series']['status'],
  1026. "topTitle" => $seriesName,
  1027. "bottomTitle" => $bottomTitle,
  1028. "overview" => isset($child['overview']) ? $child['overview'] : '',
  1029. "runtime" => $child['series']['runtime'],
  1030. "image" => $fanart,
  1031. "ratings" => $child['series']['ratings']['value'],
  1032. "videoQuality" => $child["hasFile"] ? $child['episodeFile']['quality']['quality']['name'] : "unknown",
  1033. "audioChannels" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioChannels'] : "unknown",
  1034. "audioCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioCodec'] : "unknown",
  1035. "videoCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['videoCodec'] : "unknown",
  1036. "size" => $child["hasFile"] ? $child['episodeFile']['size'] : "unknown",
  1037. "genres" => $child['series']['genres'],
  1038. );
  1039. array_push($gotCalendar, array(
  1040. "id" => "Sonarr-" . $number . "-" . $i,
  1041. "title" => $seriesName,
  1042. "start" => $child['airDateUtc'],
  1043. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1044. "imagetype" => "tv " . $downloaded,
  1045. "details" => $details
  1046. ));
  1047. }
  1048. if ($i != 0) {
  1049. return $gotCalendar;
  1050. }
  1051. return false;
  1052. }
  1053. function getRadarrCalendar($array, $number, $url)
  1054. {
  1055. $array = json_decode($array, true);
  1056. $gotCalendar = array();
  1057. $i = 0;
  1058. foreach ($array as $child) {
  1059. if (isset($child['physicalRelease'])) {
  1060. $i++;
  1061. $movieName = $child['title'];
  1062. $movieID = $child['tmdbId'];
  1063. if (!isset($movieID)) {
  1064. $movieID = "";
  1065. }
  1066. $physicalRelease = $child['physicalRelease'];
  1067. $physicalRelease = strtotime($physicalRelease);
  1068. $physicalRelease = date("Y-m-d", $physicalRelease);
  1069. if (new DateTime() < new DateTime($physicalRelease)) {
  1070. $notReleased = "true";
  1071. } else {
  1072. $notReleased = "false";
  1073. }
  1074. $downloaded = $child['hasFile'];
  1075. if ($downloaded == "0" && $notReleased == "true") {
  1076. $downloaded = "text-info";
  1077. } elseif ($downloaded == "1") {
  1078. $downloaded = "text-success";
  1079. } else {
  1080. $downloaded = "text-danger";
  1081. }
  1082. $banner = "/plugins/images/cache/no-np.png";
  1083. foreach ($child['images'] as $image) {
  1084. if ($image['coverType'] == "banner") {
  1085. $url = rtrim($url, '/'); //remove trailing slash
  1086. $imageUrl = $image['url'];
  1087. $urlParts = explode("/", $url);
  1088. $imageParts = explode("/", $image['url']);
  1089. if ($imageParts[1] == end($urlParts)) {
  1090. unset($imageParts[1]);
  1091. $imageUrl = implode("/", $imageParts);
  1092. }
  1093. $banner = $url . $imageUrl;
  1094. }
  1095. }
  1096. if ($banner !== "/plugins/images/cache/no-np.png") {
  1097. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1098. $imageURL = $banner;
  1099. $cacheFile = $cacheDirectory . $movieID . '.jpg';
  1100. $banner = 'plugins/images/cache/' . $movieID . '.jpg';
  1101. if (!file_exists($cacheFile)) {
  1102. cacheImage($imageURL, $movieID);
  1103. unset($imageURL);
  1104. unset($cacheFile);
  1105. }
  1106. }
  1107. $alternativeTitles = "";
  1108. foreach ($child['alternativeTitles'] as $alternative) {
  1109. $alternativeTitles .= $alternative['title'] . ', ';
  1110. }
  1111. $alternativeTitles = empty($child['alternativeTitles']) ? "" : substr($alternativeTitles, 0, -2);
  1112. $details = array(
  1113. "topTitle" => $movieName,
  1114. "bottomTitle" => $alternativeTitles,
  1115. "status" => $child['status'],
  1116. "overview" => $child['overview'],
  1117. "runtime" => $child['runtime'],
  1118. "image" => $banner,
  1119. "ratings" => $child['ratings']['value'],
  1120. "videoQuality" => $child["hasFile"] ? $child['movieFile']['quality']['quality']['name'] : "unknown",
  1121. "audioChannels" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioChannels'] : "unknown",
  1122. "audioCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioFormat'] : "unknown",
  1123. "videoCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['videoCodec'] : "unknown",
  1124. "size" => $child["hasFile"] ? $child['movieFile']['size'] : "unknown",
  1125. "genres" => $child['genres'],
  1126. );
  1127. array_push($gotCalendar, array(
  1128. "id" => "Radarr-" . $number . "-" . $i,
  1129. "title" => $movieName,
  1130. "start" => $physicalRelease,
  1131. "className" => "bg-calendar movieID--" . $movieID,
  1132. "imagetype" => "film " . $downloaded,
  1133. "details" => $details
  1134. ));
  1135. }
  1136. }
  1137. if ($i != 0) {
  1138. return $gotCalendar;
  1139. }
  1140. return false;
  1141. }
  1142. function getCouchCalendar($array, $number)
  1143. {
  1144. $api = json_decode($array, true);
  1145. $gotCalendar = array();
  1146. $i = 0;
  1147. foreach ($api['movies'] as $child) {
  1148. if ($child['status'] == "active" || $child['status'] == "done") {
  1149. $i++;
  1150. $movieName = $child['info']['original_title'];
  1151. $movieID = $child['info']['tmdb_id'];
  1152. if (!isset($movieID)) {
  1153. $movieID = "";
  1154. }
  1155. $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
  1156. $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
  1157. $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
  1158. $physicalRelease = strtotime($physicalRelease);
  1159. $physicalRelease = date("Y-m-d", $physicalRelease);
  1160. if (new DateTime() < new DateTime($physicalRelease)) {
  1161. $notReleased = "true";
  1162. } else {
  1163. $notReleased = "false";
  1164. }
  1165. $downloaded = ($child['status'] == "active") ? "0" : "1";
  1166. if ($downloaded == "0" && $notReleased == "true") {
  1167. $downloaded = "text-info";
  1168. } elseif ($downloaded == "1") {
  1169. $downloaded = "text-success";
  1170. } else {
  1171. $downloaded = "text-danger";
  1172. }
  1173. if (!empty($child['info']['images']['backdrop_original'])) {
  1174. $banner = $child['info']['images']['backdrop_original'][0];
  1175. } elseif (!empty($child['info']['images']['backdrop'])) {
  1176. $banner = $child['info']['images']['backdrop_original'][0];
  1177. } else {
  1178. $banner = "/plugins/images/cache/no-np.png";
  1179. }
  1180. if ($banner !== "/plugins/images/cache/no-np.png") {
  1181. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1182. $imageURL = $banner;
  1183. $cacheFile = $cacheDirectory . $movieID . '.jpg';
  1184. $banner = 'plugins/images/cache/' . $movieID . '.jpg';
  1185. if (!file_exists($cacheFile)) {
  1186. cacheImage($imageURL, $movieID);
  1187. unset($imageURL);
  1188. unset($cacheFile);
  1189. }
  1190. }
  1191. $hasFile = (!empty($child['releases']) && !empty($child['releases'][0]['files']['movie']));
  1192. $details = array(
  1193. "topTitle" => $movieName,
  1194. "bottomTitle" => $child['info']['tagline'],
  1195. "status" => $child['status'],
  1196. "overview" => $child['info']['plot'],
  1197. "runtime" => $child['info']['runtime'],
  1198. "image" => $banner,
  1199. "ratings" => isset($child['info']['rating']['imdb'][0]) ? $child['info']['rating']['imdb'][0] : '',
  1200. "videoQuality" => $hasFile ? $child['releases'][0]['quality'] : "unknown",
  1201. "audioChannels" => "",
  1202. "audioCodec" => "",
  1203. "videoCodec" => "",
  1204. "genres" => $child['info']['genres'],
  1205. );
  1206. array_push($gotCalendar, array(
  1207. "id" => "CouchPotato-" . $number . "-" . $i,
  1208. "title" => $movieName,
  1209. "start" => $physicalRelease,
  1210. "className" => "bg-calendar calendar-item movieID--" . $movieID,
  1211. "imagetype" => "film " . $downloaded,
  1212. "details" => $details
  1213. ));
  1214. }
  1215. }
  1216. if ($i != 0) {
  1217. return $gotCalendar;
  1218. }
  1219. return false;
  1220. }
  1221. function getSickrageCalendarWanted($array, $number)
  1222. {
  1223. $array = json_decode($array, true);
  1224. $gotCalendar = array();
  1225. $i = 0;
  1226. foreach ($array['data']['missed'] as $child) {
  1227. $i++;
  1228. $seriesName = $child['show_name'];
  1229. $seriesID = $child['tvdbid'];
  1230. $episodeID = $child['tvdbid'];
  1231. $episodeAirDate = $child['airdate'];
  1232. $episodeAirDateTime = explode(" ", $child['airs']);
  1233. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1234. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1235. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1236. if (new DateTime() < new DateTime($episodeAirDate)) {
  1237. $unaired = true;
  1238. }
  1239. $downloaded = "0";
  1240. if ($downloaded == "0" && isset($unaired)) {
  1241. $downloaded = "text-info";
  1242. } elseif ($downloaded == "1") {
  1243. $downloaded = "text-success";
  1244. } else {
  1245. $downloaded = "text-danger";
  1246. }
  1247. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1248. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1249. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1250. $fanart = "/plugins/images/cache/no-np.png";
  1251. if (file_exists($cacheFile)) {
  1252. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1253. unset($cacheFile);
  1254. }
  1255. $details = array(
  1256. "seasonCount" => "",
  1257. "status" => $child['show_status'],
  1258. "topTitle" => $seriesName,
  1259. "bottomTitle" => $bottomTitle,
  1260. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1261. "runtime" => "",
  1262. "image" => $fanart,
  1263. "ratings" => "",
  1264. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1265. "audioChannels" => "",
  1266. "audioCodec" => "",
  1267. "videoCodec" => "",
  1268. "size" => "",
  1269. "genres" => "",
  1270. );
  1271. array_push($gotCalendar, array(
  1272. "id" => "Sick-" . $number . "-Miss-" . $i,
  1273. "title" => $seriesName,
  1274. "start" => $episodeAirDate,
  1275. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1276. "imagetype" => "tv " . $downloaded,
  1277. "details" => $details,
  1278. ));
  1279. }
  1280. foreach ($array['data']['today'] as $child) {
  1281. $i++;
  1282. $seriesName = $child['show_name'];
  1283. $seriesID = $child['tvdbid'];
  1284. $episodeID = $child['tvdbid'];
  1285. $episodeAirDate = $child['airdate'];
  1286. $episodeAirDateTime = explode(" ", $child['airs']);
  1287. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1288. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1289. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1290. if (new DateTime() < new DateTime($episodeAirDate)) {
  1291. $unaired = true;
  1292. }
  1293. $downloaded = "0";
  1294. if ($downloaded == "0" && isset($unaired)) {
  1295. $downloaded = "text-info";
  1296. } elseif ($downloaded == "1") {
  1297. $downloaded = "text-success";
  1298. } else {
  1299. $downloaded = "text-danger";
  1300. }
  1301. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1302. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1303. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1304. $fanart = "/plugins/images/cache/no-np.png";
  1305. if (file_exists($cacheFile)) {
  1306. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1307. unset($cacheFile);
  1308. }
  1309. $details = array(
  1310. "seasonCount" => "",
  1311. "status" => $child['show_status'],
  1312. "topTitle" => $seriesName,
  1313. "bottomTitle" => $bottomTitle,
  1314. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1315. "runtime" => "",
  1316. "image" => $fanart,
  1317. "ratings" => "",
  1318. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1319. "audioChannels" => "",
  1320. "audioCodec" => "",
  1321. "videoCodec" => "",
  1322. "size" => "",
  1323. "genres" => "",
  1324. );
  1325. array_push($gotCalendar, array(
  1326. "id" => "Sick-" . $number . "-Today-" . $i,
  1327. "title" => $seriesName,
  1328. "start" => $episodeAirDate,
  1329. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1330. "imagetype" => "tv " . $downloaded,
  1331. "details" => $details,
  1332. ));
  1333. }
  1334. foreach ($array['data']['soon'] as $child) {
  1335. $i++;
  1336. $seriesName = $child['show_name'];
  1337. $seriesID = $child['tvdbid'];
  1338. $episodeID = $child['tvdbid'];
  1339. $episodeAirDate = $child['airdate'];
  1340. $episodeAirDateTime = explode(" ", $child['airs']);
  1341. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1342. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1343. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1344. if (new DateTime() < new DateTime($episodeAirDate)) {
  1345. $unaired = true;
  1346. }
  1347. $downloaded = "0";
  1348. if ($downloaded == "0" && isset($unaired)) {
  1349. $downloaded = "text-info";
  1350. } elseif ($downloaded == "1") {
  1351. $downloaded = "text-success";
  1352. } else {
  1353. $downloaded = "text-danger";
  1354. }
  1355. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1356. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1357. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1358. $fanart = "/plugins/images/cache/no-np.png";
  1359. if (file_exists($cacheFile)) {
  1360. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1361. unset($cacheFile);
  1362. }
  1363. $details = array(
  1364. "seasonCount" => "",
  1365. "status" => $child['show_status'],
  1366. "topTitle" => $seriesName,
  1367. "bottomTitle" => $bottomTitle,
  1368. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1369. "runtime" => "",
  1370. "image" => $fanart,
  1371. "ratings" => "",
  1372. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1373. "audioChannels" => "",
  1374. "audioCodec" => "",
  1375. "videoCodec" => "",
  1376. "size" => "",
  1377. "genres" => "",
  1378. );
  1379. array_push($gotCalendar, array(
  1380. "id" => "Sick-" . $number . "-Soon-" . $i,
  1381. "title" => $seriesName,
  1382. "start" => $episodeAirDate,
  1383. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1384. "imagetype" => "tv " . $downloaded,
  1385. "details" => $details,
  1386. ));
  1387. }
  1388. foreach ($array['data']['later'] as $child) {
  1389. $i++;
  1390. $seriesName = $child['show_name'];
  1391. $seriesID = $child['tvdbid'];
  1392. $episodeID = $child['tvdbid'];
  1393. $episodeAirDate = $child['airdate'];
  1394. $episodeAirDateTime = explode(" ", $child['airs']);
  1395. $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
  1396. $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
  1397. $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
  1398. if (new DateTime() < new DateTime($episodeAirDate)) {
  1399. $unaired = true;
  1400. }
  1401. $downloaded = "0";
  1402. if ($downloaded == "0" && isset($unaired)) {
  1403. $downloaded = "text-info";
  1404. } elseif ($downloaded == "1") {
  1405. $downloaded = "text-success";
  1406. } else {
  1407. $downloaded = "text-danger";
  1408. }
  1409. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
  1410. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1411. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1412. $fanart = "/plugins/images/cache/no-np.png";
  1413. if (file_exists($cacheFile)) {
  1414. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1415. unset($cacheFile);
  1416. }
  1417. $details = array(
  1418. "seasonCount" => "",
  1419. "status" => $child['show_status'],
  1420. "topTitle" => $seriesName,
  1421. "bottomTitle" => $bottomTitle,
  1422. "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
  1423. "runtime" => "",
  1424. "image" => $fanart,
  1425. "ratings" => "",
  1426. "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
  1427. "audioChannels" => "",
  1428. "audioCodec" => "",
  1429. "videoCodec" => "",
  1430. "size" => "",
  1431. "genres" => "",
  1432. );
  1433. array_push($gotCalendar, array(
  1434. "id" => "Sick-" . $number . "-Later-" . $i,
  1435. "title" => $seriesName,
  1436. "start" => $episodeAirDate,
  1437. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1438. "imagetype" => "tv " . $downloaded,
  1439. "details" => $details,
  1440. ));
  1441. }
  1442. if ($i != 0) {
  1443. return $gotCalendar;
  1444. }
  1445. return false;
  1446. }
  1447. function getSickrageCalendarHistory($array, $number)
  1448. {
  1449. $array = json_decode($array, true);
  1450. $gotCalendar = array();
  1451. $i = 0;
  1452. foreach ($array['data'] as $child) {
  1453. $i++;
  1454. $seriesName = $child['show_name'];
  1455. $seriesID = $child['tvdbid'];
  1456. $episodeID = $child['tvdbid'];
  1457. $episodeAirDate = $child['date'];
  1458. $downloaded = "text-success";
  1459. $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']);
  1460. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1461. $cacheFile = $cacheDirectory . $seriesID . '.jpg';
  1462. $fanart = "/plugins/images/cache/no-np.png";
  1463. if (file_exists($cacheFile)) {
  1464. $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
  1465. unset($cacheFile);
  1466. }
  1467. $details = array(
  1468. "seasonCount" => "",
  1469. "status" => $child['status'],
  1470. "topTitle" => $seriesName,
  1471. "bottomTitle" => $bottomTitle,
  1472. "overview" => '',
  1473. "runtime" => $child['series']['runtime'],
  1474. "image" => $fanart,
  1475. "ratings" => $child['series']['ratings']['value'],
  1476. "videoQuality" => isset($child["quality"]) ? $child['quality'] : "unknown",
  1477. "audioChannels" => "",
  1478. "audioCodec" => "",
  1479. "videoCodec" => "",
  1480. "size" => "",
  1481. "genres" => "",
  1482. );
  1483. array_push($gotCalendar, array(
  1484. "id" => "Sick-" . $number . "-History-" . $i,
  1485. "title" => $seriesName,
  1486. "start" => $episodeAirDate,
  1487. "className" => "bg-calendar calendar-item tvID--" . $episodeID,
  1488. "imagetype" => "tv " . $downloaded,
  1489. "details" => $details,
  1490. ));
  1491. }
  1492. if ($i != 0) {
  1493. return $gotCalendar;
  1494. }
  1495. return false;
  1496. }
  1497. function ombiAPI($array)
  1498. {
  1499. return ombiAction($array['data']['id'], $array['data']['action'], $array['data']['type']);
  1500. }
  1501. function ombiImport($type = null)
  1502. {
  1503. if (!empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && !empty($type)) {
  1504. try {
  1505. $url = qualifyURL($GLOBALS['ombiURL']);
  1506. $headers = array(
  1507. "Accept" => "application/json",
  1508. "Content-Type" => "application/json",
  1509. "Apikey" => $GLOBALS['ombiToken']
  1510. );
  1511. $options = (localURL($url)) ? array('verify' => false) : array();
  1512. switch ($type) {
  1513. case 'emby':
  1514. $response = Requests::get($url . "/api/v1/Job/embyuserimporter", $headers, $options);
  1515. break;
  1516. case 'plex':
  1517. $response = Requests::get($url . "/api/v1/Job/plexuserimporter", $headers, $options);
  1518. break;
  1519. default:
  1520. break;
  1521. }
  1522. if ($response->success) {
  1523. writeLog('success', 'OMBI Connect Function - Ran User Import', 'SYSTEM');
  1524. return true;
  1525. }
  1526. } catch (Requests_Exception $e) {
  1527. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1528. };
  1529. }
  1530. return false;
  1531. }
  1532. function ombiAction($id, $action, $type)
  1533. {
  1534. if ($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])) {
  1535. $url = qualifyURL($GLOBALS['ombiURL']);
  1536. $headers = array(
  1537. "Accept" => "application/json",
  1538. "Content-Type" => "application/json",
  1539. "Apikey" => $GLOBALS['ombiToken']
  1540. );
  1541. $data = array(
  1542. 'id' => $id,
  1543. );
  1544. switch ($type) {
  1545. case 'season':
  1546. case 'tv':
  1547. $type = 'tv';
  1548. $add = array(
  1549. 'tvDbId' => $id,
  1550. 'requestAll' => true,
  1551. 'latestSeason' => true,
  1552. 'firstSeason' => true
  1553. );
  1554. break;
  1555. default:
  1556. $type = 'movie';
  1557. $add = array("theMovieDbId" => (int)$id);
  1558. break;
  1559. }
  1560. $success['head'] = $headers;
  1561. $success['act'] = $action;
  1562. $success['data'] = $data;
  1563. $success['add'] = $add;
  1564. $success['type'] = $type;
  1565. try {
  1566. $options = (localURL($url)) ? array('verify' => false) : array();
  1567. switch ($action) {
  1568. case 'add':
  1569. if (isset($_COOKIE['Auth'])) {
  1570. $headers = array(
  1571. "Accept" => "application/json",
  1572. "Content-Type" => "application/json",
  1573. "Authorization" => "Bearer " . $_COOKIE['Auth']
  1574. );
  1575. $success['head'] = $headers;
  1576. } else {
  1577. return false;
  1578. }
  1579. $response = Requests::post($url . "/api/v1/Request/" . $type, $headers, json_encode($add), $options);
  1580. break;
  1581. default:
  1582. if (qualifyRequest(1)) {
  1583. switch ($action) {
  1584. case 'approve':
  1585. $response = Requests::post($url . "/api/v1/Request/" . $type . "/approve", $headers, json_encode($data), $options);
  1586. break;
  1587. case 'available':
  1588. $response = Requests::post($url . "/api/v1/Request/" . $type . "/available", $headers, json_encode($data), $options);
  1589. break;
  1590. case 'unavailable':
  1591. $response = Requests::post($url . "/api/v1/Request/" . $type . "/unavailable", $headers, json_encode($data), $options);
  1592. break;
  1593. case 'deny':
  1594. $response = Requests::put($url . "/api/v1/Request/" . $type . "/deny", $headers, json_encode($data), $options);
  1595. break;
  1596. case 'delete':
  1597. $response = Requests::delete($url . "/api/v1/Request/" . $type . "/" . $id, $headers, $options);
  1598. break;
  1599. default:
  1600. return false;
  1601. }
  1602. }
  1603. break;
  1604. }
  1605. $success['api'] = $response;
  1606. $success['bd'] = $response->body;
  1607. $success['hd'] = $response->headers;
  1608. if ($response->success) {
  1609. $success['ok'] = true;
  1610. }
  1611. } catch (Requests_Exception $e) {
  1612. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1613. };
  1614. }
  1615. return isset($success['ok']) ? $success : false;
  1616. }
  1617. function getOmbiRequests($type = "both")
  1618. {
  1619. if ($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])) {
  1620. $url = qualifyURL($GLOBALS['ombiURL']);
  1621. $headers = array(
  1622. "Accept" => "application/json",
  1623. "Apikey" => $GLOBALS['ombiToken'],
  1624. );
  1625. $requests = array();
  1626. try {
  1627. $options = (localURL($url)) ? array('verify' => false) : array();
  1628. switch ($type) {
  1629. case 'movie':
  1630. $movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
  1631. break;
  1632. case 'tv':
  1633. $tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
  1634. break;
  1635. default:
  1636. $movie = Requests::get($url . "/api/v1/Request/movie", $headers, $options);
  1637. $tv = Requests::get($url . "/api/v1/Request/tv", $headers, $options);
  1638. break;
  1639. }
  1640. if ($movie->success || $tv->success) {
  1641. if (isset($movie)) {
  1642. $movie = json_decode($movie->body, true);
  1643. //$movie = array_reverse($movie);
  1644. foreach ($movie as $key => $value) {
  1645. $requests[] = array(
  1646. 'test' => $value,
  1647. 'id' => $value['theMovieDbId'],
  1648. 'title' => $value['title'],
  1649. 'overview' => $value['overview'],
  1650. 'poster' => (isset($value['posterPath']) && $value['posterPath'] !== '') ? 'https://image.tmdb.org/t/p/w300/' . $value['posterPath'] : '',
  1651. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/' . $value['background'] : '',
  1652. 'approved' => $value['approved'],
  1653. 'available' => $value['available'],
  1654. 'denied' => $value['denied'],
  1655. 'deniedReason' => $value['deniedReason'],
  1656. 'user' => $value['requestedUser']['userName'],
  1657. 'request_id' => $value['id'],
  1658. 'request_date' => $value['requestedDate'],
  1659. 'release_date' => $value['releaseDate'],
  1660. 'type' => 'movie',
  1661. 'icon' => 'mdi mdi-filmstrip',
  1662. 'color' => 'palette-Deep-Purple-900 bg white',
  1663. );
  1664. }
  1665. }
  1666. if (isset($tv) && (is_array($tv) || is_object($tv))) {
  1667. $tv = json_decode($tv->body, true);
  1668. foreach ($tv as $key => $value) {
  1669. if (is_array($value['childRequests'][0])) {
  1670. $requests[] = array(
  1671. 'test' => $value,
  1672. 'id' => $value['tvDbId'],
  1673. 'title' => $value['title'],
  1674. 'overview' => $value['overview'],
  1675. 'poster' => $value['posterPath'],
  1676. 'background' => (isset($value['background']) && $value['background'] !== '') ? 'https://image.tmdb.org/t/p/w1280/' . $value['background'] : '',
  1677. 'approved' => $value['childRequests'][0]['approved'],
  1678. 'available' => $value['childRequests'][0]['available'],
  1679. 'denied' => $value['childRequests'][0]['denied'],
  1680. 'deniedReason' => $value['childRequests'][0]['deniedReason'],
  1681. 'user' => $value['childRequests'][0]['requestedUser']['userName'],
  1682. 'request_id' => $value['id'],
  1683. 'request_date' => $value['childRequests'][0]['requestedDate'],
  1684. 'release_date' => $value['releaseDate'],
  1685. 'type' => 'tv',
  1686. 'icon' => 'mdi mdi-television',
  1687. 'color' => 'grayish-blue-bg',
  1688. );
  1689. }
  1690. }
  1691. }
  1692. //sort here
  1693. usort($requests, function ($item1, $item2) {
  1694. if ($item1['request_date'] == $item2['request_date']) {
  1695. return 0;
  1696. }
  1697. return $item1['request_date'] > $item2['request_date'] ? -1 : 1;
  1698. });
  1699. }
  1700. } catch (Requests_Exception $e) {
  1701. writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1702. };
  1703. }
  1704. $api['content'] = isset($requests) ? $requests : false;
  1705. return $api;
  1706. }
  1707. function testAPIConnection($array)
  1708. {
  1709. switch ($array['data']['action']) {
  1710. case 'plex':
  1711. if (!empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken'])) {
  1712. $url = qualifyURL($GLOBALS['plexURL']);
  1713. $url = $url . "/?X-Plex-Token=" . $GLOBALS['plexToken'];
  1714. try {
  1715. $options = (localURL($url)) ? array('verify' => false) : array();
  1716. $response = Requests::get($url, array(), $options);
  1717. libxml_use_internal_errors(true);
  1718. if ($response->success) {
  1719. return true;
  1720. }
  1721. } catch (Requests_Exception $e) {
  1722. return $e->getMessage();
  1723. };
  1724. } else {
  1725. return 'URL and/or Token not setup';
  1726. }
  1727. break;
  1728. case 'emby':
  1729. break;
  1730. case 'sonarr':
  1731. if (!empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])) {
  1732. $sonarrs = array();
  1733. $sonarrURLList = explode(',', $GLOBALS['sonarrURL']);
  1734. $sonarrTokenList = explode(',', $GLOBALS['sonarrToken']);
  1735. if (count($sonarrURLList) == count($sonarrTokenList)) {
  1736. foreach ($sonarrURLList as $key => $value) {
  1737. $sonarrs[$key] = array(
  1738. 'url' => $value,
  1739. 'token' => $sonarrTokenList[$key]
  1740. );
  1741. }
  1742. foreach ($sonarrs as $key => $value) {
  1743. try {
  1744. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  1745. $sonarr->getSystemStatus();
  1746. return true;
  1747. } catch (Exception $e) {
  1748. return $e->getMessage();
  1749. }
  1750. }
  1751. }
  1752. } else {
  1753. return 'URL/s and/or Token/s not setup';
  1754. }
  1755. break;
  1756. case 'radarr':
  1757. if (!empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
  1758. $sonarrs = array();
  1759. $sonarrURLList = explode(',', $GLOBALS['radarrURL']);
  1760. $sonarrTokenList = explode(',', $GLOBALS['radarrToken']);
  1761. if (count($sonarrURLList) == count($sonarrTokenList)) {
  1762. foreach ($sonarrURLList as $key => $value) {
  1763. $sonarrs[$key] = array(
  1764. 'url' => $value,
  1765. 'token' => $sonarrTokenList[$key]
  1766. );
  1767. }
  1768. foreach ($sonarrs as $key => $value) {
  1769. try {
  1770. $sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
  1771. $sonarr->getSystemStatus();
  1772. return true;
  1773. } catch (Exception $e) {
  1774. return $e->getMessage();
  1775. }
  1776. }
  1777. }
  1778. } else {
  1779. return 'URL/s and/or Token/s not setup';
  1780. }
  1781. break;
  1782. case 'sabnzbd':
  1783. if (!empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken'])) {
  1784. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1785. $url = $url . '/api?mode=queue&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1786. try {
  1787. $options = (localURL($url)) ? array('verify' => false) : array();
  1788. $response = Requests::get($url, array(), $options);
  1789. if ($response->success) {
  1790. return true;
  1791. }
  1792. } catch (Requests_Exception $e) {
  1793. return $e->getMessage();
  1794. };
  1795. } else {
  1796. return 'URL and/or Token not setup';
  1797. }
  1798. break;
  1799. case 'nzbget':
  1800. if (!empty($GLOBALS['nzbgetURL'])) {
  1801. $url = qualifyURL($GLOBALS['nzbgetURL']);
  1802. if (!empty($GLOBALS['nzbgetUsername']) && !empty($GLOBALS['nzbgetPassword'])) {
  1803. $url = $url . '/' . $GLOBALS['nzbgetUsername'] . ':' . decrypt($GLOBALS['nzbgetPassword']) . '/jsonrpc/listgroups';
  1804. } else {
  1805. $url = $url . '/jsonrpc/listgroups';
  1806. }
  1807. try {
  1808. $options = (localURL($url)) ? array('verify' => false) : array();
  1809. $response = Requests::get($url, array(), $options);
  1810. if ($response->success) {
  1811. return true;
  1812. }
  1813. } catch (Requests_Exception $e) {
  1814. return $e->getMessage();
  1815. };
  1816. } else {
  1817. return 'URL and/or Username/Password not setup';
  1818. }
  1819. break;
  1820. case 'deluge':
  1821. if (!empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword'])) {
  1822. try {
  1823. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1824. $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');
  1825. return true;
  1826. } catch (\Excecption $e) {
  1827. return $e->getMessage();
  1828. }
  1829. } else {
  1830. return 'URL and/or Password not setup';
  1831. }
  1832. break;
  1833. default :
  1834. return false;
  1835. }
  1836. return false;
  1837. }