homepage-connect-functions.php 79 KB

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