homepage-connect-functions.php 87 KB

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