jackett.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 searchJackettIndexers($query = null)
  48. {
  49. if (!$this->config['homepageJackettEnabled']) {
  50. $this->setAPIResponse('error', 'Jackett homepage item is not enabled', 409);
  51. return false;
  52. }
  53. if (!$this->qualifyRequest($this->config['homepageJackettAuth'])) {
  54. $this->setAPIResponse('error', 'User not approved to view this homepage item', 401);
  55. return false;
  56. }
  57. if (empty($this->config['jackettURL']) || empty($this->config['jackettToken'])) {
  58. $this->setAPIResponse('error', 'Jackett URL and/or Token were not defined', 422);
  59. return false;
  60. }
  61. if (!$query) {
  62. $this->setAPIResponse('error', 'Query was not supplied', 422);
  63. return false;
  64. }
  65. $apiURL = $this->qualifyURL($this->config['jackettURL']);
  66. $endpoint = $apiURL . '/api/v2.0/indexers/all/results?apikey=' . $this->config['jackettToken'] . '&Query=' . urlencode($query);
  67. try {
  68. $headers = array();
  69. $options = array('timeout' => 60);
  70. $response = Requests::get($endpoint, $headers, $options);
  71. if ($response->success) {
  72. $apiData = json_decode($response->body, true);
  73. $api['content'] = $apiData;
  74. unset($apiData);
  75. }
  76. } catch (Requests_Exception $e) {
  77. $this->writeLog('error', 'Weather And Air Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  78. $this->setAPIResponse('error', $e->getMessage(), 500);
  79. return false;
  80. };
  81. $api['content'] = isset($api['content']) ? $api['content'] : false;
  82. $this->setAPIResponse('success', null, 200, $api);
  83. return $api;
  84. }
  85. }