homepage-connect-functions.php 68 KB

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