homepage-connect-functions.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /** @noinspection PhpUndefinedFieldInspection */
  3. trait HomepageConnectFunctions
  4. {
  5. public function csvHomepageUrlToken($url, $token)
  6. {
  7. $list = array();
  8. $urlList = explode(',', $url);
  9. $tokenList = explode(',', $token);
  10. foreach ($urlList as $key => $value) {
  11. if (isset($tokenList[$key])) {
  12. $list[$key] = array(
  13. 'url' => $this->qualifyURL($value),
  14. 'token' => $tokenList[$key]
  15. );
  16. }
  17. }
  18. return $list;
  19. }
  20. public function streamType($value)
  21. {
  22. if ($value == "transcode" || $value == "Transcode") {
  23. return "Transcode";
  24. } elseif ($value == "copy" || $value == "DirectStream") {
  25. return "Direct Stream";
  26. } elseif ($value == "directplay" || $value == "DirectPlay") {
  27. return "Direct Play";
  28. } else {
  29. return "Direct Play";
  30. }
  31. }
  32. public function getCacheImageSize($type)
  33. {
  34. switch ($type) {
  35. case 'height':
  36. case 'h':
  37. return round(300 * $this->config['cacheImageSize']);
  38. case 'width':
  39. case 'w':
  40. return round(200 * $this->config['cacheImageSize']);
  41. case 'nowPlayingHeight':
  42. case 'nph':
  43. return round(675 * $this->config['cacheImageSize']);
  44. case 'nowPlayingWidth':
  45. case 'npw':
  46. return round(1200 * $this->config['cacheImageSize']);
  47. }
  48. }
  49. public function ombiImport($type = null)
  50. {
  51. if (!empty($this->config['ombiURL']) && !empty($this->config['ombiToken']) && !empty($type)) {
  52. try {
  53. $url = $this->qualifyURL($this->config['ombiURL']);
  54. $headers = array(
  55. "Accept" => "application/json",
  56. "Content-Type" => "application/json",
  57. "Apikey" => $this->config['ombiToken']
  58. );
  59. $options = ($this->localURL($url)) ? array('verify' => false) : array();
  60. switch ($type) {
  61. case 'emby':
  62. case 'emby_local':
  63. case 'emby_connect':
  64. case 'emby_all':
  65. $response = Requests::post($url . "/api/v1/Job/embyuserimporter", $headers, $options);
  66. break;
  67. case 'plex':
  68. $response = Requests::post($url . "/api/v1/Job/plexuserimporter", $headers, $options);
  69. break;
  70. default:
  71. return false;
  72. break;
  73. }
  74. if ($response->success) {
  75. $this->setLoggerChannel('Ombi')->info('Ran User Import');
  76. return true;
  77. } else {
  78. $this->setLoggerChannel('Ombi')->warning('Unsuccessful connection');
  79. return false;
  80. }
  81. } catch (Requests_Exception $e) {
  82. $this->setLoggerChannel('Ombi')->error($e);
  83. return false;
  84. }
  85. }
  86. return false;
  87. }
  88. }