jackett.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. trait JackettHomepageItem
  3. {
  4. public function jackettSettingsArray()
  5. {
  6. return array(
  7. 'name' => 'Jackett',
  8. 'enabled' => true,
  9. 'image' => 'plugins/images/tabs/jackett.png',
  10. 'category' => 'Utility',
  11. 'settings' => array(
  12. 'Enable' => array(
  13. array(
  14. 'type' => 'switch',
  15. 'name' => 'homepageJackettEnabled',
  16. 'label' => 'Enable',
  17. 'value' => $this->config['homepageJackettEnabled']
  18. ),
  19. array(
  20. 'type' => 'select',
  21. 'name' => 'homepageJackettAuth',
  22. 'label' => 'Minimum Authentication',
  23. 'value' => $this->config['homepageJackettAuth'],
  24. 'options' => $this->groupOptions
  25. )
  26. ),
  27. 'Connection' => array(
  28. array(
  29. 'type' => 'input',
  30. 'name' => 'jackettURL',
  31. 'label' => 'URL',
  32. 'value' => $this->config['jackettURL'],
  33. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  34. 'placeholder' => 'http(s)://hostname:port'
  35. ),
  36. array(
  37. 'type' => 'password-alt',
  38. 'name' => 'jackettToken',
  39. 'label' => 'Token',
  40. 'value' => $this->config['jackettToken']
  41. )
  42. ),
  43. 'Options' => array(),
  44. )
  45. );
  46. }
  47. public function jackettHomepagePermissions($key = null)
  48. {
  49. $permissions = [
  50. 'main' => [
  51. 'enabled' => [
  52. 'homepageJackettEnabled'
  53. ],
  54. 'auth' => [
  55. 'homepageJackettAuth'
  56. ],
  57. 'not_empty' => [
  58. 'jackettURL',
  59. 'jackettToken'
  60. ]
  61. ]
  62. ];
  63. if (array_key_exists($key, $permissions)) {
  64. return $permissions[$key];
  65. } elseif ($key == 'all') {
  66. return $permissions;
  67. } else {
  68. return [];
  69. }
  70. }
  71. public function homepageOrderJackett()
  72. {
  73. if ($this->homepageItemPermissions($this->jackettHomepagePermissions('main'))) {
  74. return '
  75. <div id="' . __FUNCTION__ . '">
  76. <div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Jackett...</h2></div>
  77. <script>
  78. // Jackett
  79. homepageJackett();
  80. // End Jackett
  81. </script>
  82. </div>
  83. ';
  84. }
  85. }
  86. public function searchJackettIndexers($query = null)
  87. {
  88. if (!$this->homepageItemPermissions($this->jackettHomepagePermissions('main'), true)) {
  89. return false;
  90. }
  91. if (!$query) {
  92. $this->setAPIResponse('error', 'Query was not supplied', 422);
  93. return false;
  94. }
  95. $apiURL = $this->qualifyURL($this->config['jackettURL']);
  96. $endpoint = $apiURL . '/api/v2.0/indexers/all/results?apikey=' . $this->config['jackettToken'] . '&Query=' . urlencode($query);
  97. try {
  98. $headers = array();
  99. $options = array('timeout' => 120);
  100. $response = Requests::get($endpoint, $headers, $options);
  101. if ($response->success) {
  102. $apiData = json_decode($response->body, true);
  103. $api['content'] = $apiData;
  104. unset($apiData);
  105. }
  106. } catch (Requests_Exception $e) {
  107. $this->writeLog('error', 'Weather And Air Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  108. $this->setAPIResponse('error', $e->getMessage(), 500);
  109. return false;
  110. };
  111. $api['content'] = isset($api['content']) ? $api['content'] : false;
  112. $this->setAPIResponse('success', null, 200, $api);
  113. return $api;
  114. }
  115. }