homepage-connect-functions.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if (count($urlList) == count($tokenList)) {
  11. foreach ($urlList as $key => $value) {
  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 300 * $this->config['cacheImageSize'];
  38. case 'width':
  39. case 'w':
  40. return 200 * $this->config['cacheImageSize'];
  41. case 'nowPlayingHeight':
  42. case 'nph':
  43. return 675 * $this->config['cacheImageSize'];
  44. case 'nowPlayingWidth':
  45. case 'npw':
  46. return 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" => $GLOBALS['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->writeLog('success', 'OMBI Connect Function - Ran User Import', 'SYSTEM');
  76. return true;
  77. } else {
  78. $this->writeLog('error', 'OMBI Connect Function - Error: Connection Unsuccessful', 'SYSTEM');
  79. return false;
  80. }
  81. } catch (Requests_Exception $e) {
  82. $this->writeLog('error', 'OMBI Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  83. return false;
  84. }
  85. }
  86. return false;
  87. }
  88. }