4
0

homepage-connect-functions.php 81 KB

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