homepage-connect-functions.php 76 KB

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