'Deluge', 'enabled' => strpos('personal', $this->config['license']) !== false, 'image' => 'plugins/images/tabs/deluge.png', 'category' => 'Downloader', 'settingsArray' => __FUNCTION__ ]; if ($infoOnly) { return $homepageInformation; } $homepageSettings = array( 'settings' => array( 'custom' => '
Notice
  • Download Plugin
  • Open Deluge Web UI, go to "Preferences -> Plugins -> Install plugin" and choose egg file.
  • Activate WebAPI plugin
', 'Enable' => array( array( 'type' => 'switch', 'name' => 'homepageDelugeEnabled', 'label' => 'Enable', 'value' => $this->config['homepageDelugeEnabled'] ), array( 'type' => 'select', 'name' => 'homepageDelugeAuth', 'label' => 'Minimum Authentication', 'value' => $this->config['homepageDelugeAuth'], 'options' => $this->groupOptions ) ), 'Connection' => array( array( 'type' => 'input', 'name' => 'delugeURL', 'label' => 'URL', 'value' => $this->config['delugeURL'], 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.', 'placeholder' => 'http(s)://hostname:port' ), array( 'type' => 'password', 'name' => 'delugePassword', 'label' => 'Password', 'help' => 'Note that using a blank password might not work correctly.', 'value' => $this->config['delugePassword'] ) ), 'Misc Options' => array( array( 'type' => 'switch', 'name' => 'delugeHideSeeding', 'label' => 'Hide Seeding', 'value' => $this->config['delugeHideSeeding'] ), array( 'type' => 'switch', 'name' => 'delugeHideCompleted', 'label' => 'Hide Completed', 'value' => $this->config['delugeHideCompleted'] ), array( 'type' => 'select', 'name' => 'delugeRefresh', 'label' => 'Refresh Seconds', 'value' => $this->config['delugeRefresh'], 'options' => $this->timeOptions() ), array( 'type' => 'switch', 'name' => 'delugeCombine', 'label' => 'Add to Combined Downloader', 'value' => $this->config['delugeCombine'] ), ), 'Test Connection' => array( array( 'type' => 'blank', 'label' => 'Please Save before Testing. Note that using a blank password might not work correctly.' ), array( 'type' => 'button', 'label' => '', 'icon' => 'fa fa-flask', 'class' => 'pull-right', 'text' => 'Test Connection', 'attr' => 'onclick="testAPIConnection(\'deluge\')"' ), ) ) ); return array_merge($homepageInformation, $homepageSettings); } public function testConnectionDeluge() { if (empty($this->config['delugeURL'])) { $this->setAPIResponse('error', 'Deluge URL is not defined', 422); return false; } try { $deluge = new deluge($this->config['delugeURL'], $this->decrypt($this->config['delugePassword'])); $torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, hash, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate'); $this->setAPIResponse('success', 'API Connection succeeded', 200); return true; } catch (Exception $e) { $this->writeLog('error', 'NZBGet Connect Function - Error: ' . $e->getMessage(), 'SYSTEM'); $this->setAPIResponse('error', $e->getMessage(), 500); return false; } } public function delugeHomepagePermissions($key = null) { $permissions = [ 'main' => [ 'enabled' => [ 'homepageDelugeEnabled' ], 'auth' => [ 'homepageDelugeAuth' ], 'not_empty' => [ 'delugeURL' ] ] ]; if (array_key_exists($key, $permissions)) { return $permissions[$key]; } elseif ($key == 'all') { return $permissions; } else { return []; } } public function homepageOrderdeluge() { if ($this->homepageItemPermissions($this->delugeHomepagePermissions('main'))) { $loadingBox = ($this->config['delugeCombine']) ? '' : '

Loading Download Queue...

'; $builder = ($this->config['delugeCombine']) ? 'buildDownloaderCombined(\'deluge\');' : '$("#' . __FUNCTION__ . '").html(buildDownloader("deluge"));'; return '
' . $loadingBox . '
'; } } public function getDelugeHomepageQueue() { if (!$this->homepageItemPermissions($this->delugeHomepagePermissions('main'), true)) { return false; } try { $deluge = new deluge($this->config['delugeURL'], $this->decrypt($this->config['delugePassword'])); $torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, hash, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate'); foreach ($torrents as $key => $value) { $tempStatus = $this->delugeStatus($value->queue, $value->state, $value->progress); if ($tempStatus == 'Seeding' && $this->config['delugeHideSeeding']) { //do nothing } elseif ($tempStatus == 'Finished' && $this->config['delugeHideCompleted']) { //do nothing } else { $api['content']['queueItems'][] = $value; } } $api['content']['queueItems'] = (empty($api['content']['queueItems'])) ? [] : $api['content']['queueItems']; $api['content']['historyItems'] = false; } catch (Excecption $e) { $this->writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM'); $this->setAPIResponse('error', $e->getMessage(), 500); return false; } $api['content'] = isset($api['content']) ? $api['content'] : false; $this->setAPIResponse('success', null, 200, $api); return $api; } public function delugeStatus($queued, $status, $state) { if ($queued == '-1' && $state == '100' && ($status == 'Seeding' || $status == 'Queued' || $status == 'Paused')) { $state = 'Seeding'; } elseif ($state !== '100') { $state = 'Downloading'; } else { $state = 'Finished'; } return ($state) ? $state : $status; } }