12 changed files with 414 additions and 318 deletions
@ -1,158 +1,154 @@ |
|||
/** @namespace config.defaultHost */ |
|||
$(document).ready(function(){ |
|||
var loading = '<img src="' + sbRoot + '/images/loading16' + themeSpinner + '.gif" height="16" width="16" />'; |
|||
|
|||
function toggle_torrent_title(){ |
|||
if ($('#use_torrents').prop('checked')) |
|||
$('#no_torrents').show(); |
|||
else |
|||
$('#no_torrents').hide(); |
|||
} |
|||
|
|||
$.fn.nzb_method_handler = function() { |
|||
|
|||
var selectedProvider = $('#nzb_method :selected').val(), |
|||
blackhole_settings = '#blackhole_settings', |
|||
sabnzbd_settings = '#sabnzbd_settings', |
|||
testSABnzbd = '#testSABnzbd', |
|||
testSABnzbd_result = '#testSABnzbd_result', |
|||
nzbget_settings = '#nzbget_settings'; |
|||
|
|||
$(blackhole_settings).hide(); |
|||
$(sabnzbd_settings).hide(); |
|||
$(testSABnzbd).hide(); |
|||
$(testSABnzbd_result).hide(); |
|||
$(nzbget_settings).hide(); |
|||
|
|||
if ('blackhole' == selectedProvider) { |
|||
$(blackhole_settings).show(); |
|||
} else if ('nzbget' == selectedProvider) { |
|||
$(nzbget_settings).show(); |
|||
} else { |
|||
$(sabnzbd_settings).show(); |
|||
$(testSABnzbd).show(); |
|||
$(testSABnzbd_result).show(); |
|||
} |
|||
} |
|||
|
|||
$.fn.torrent_method_handler = function() { |
|||
|
|||
$('#options_torrent_clients').hide(); |
|||
$('#options_torrent_blackhole').hide(); |
|||
|
|||
var selectedProvider = $('#torrent_method :selected').val(), |
|||
host = ' host:port', |
|||
username = ' username', |
|||
password = ' password', |
|||
label = ' label', |
|||
directory = ' directory', |
|||
client = '', |
|||
option_panel = '#options_torrent_blackhole'; |
|||
|
|||
if ('blackhole' != selectedProvider) { |
|||
var label_warning_deluge = '#label_warning_deluge', |
|||
host_desc_rtorrent = '#host_desc_rtorrent', |
|||
host_desc_torrent = '#host_desc_torrent', |
|||
torrent_verify_cert_option = '#torrent_verify_cert_option', |
|||
torrent_path_option = '#torrent_path_option', |
|||
torrent_seed_time_option = '#torrent_seed_time_option', |
|||
torrent_high_bandwidth_option = '#torrent_high_bandwidth_option', |
|||
torrent_label_option = '#torrent_label_option', |
|||
path_blank = '#path_blank', |
|||
path_transmission = '#path_transmission', |
|||
path_synology = '#path_synology', |
|||
torrent_paused_option = '#torrent_paused_option'; |
|||
|
|||
$(label_warning_deluge).hide(); |
|||
$(host_desc_rtorrent).hide(); |
|||
$(host_desc_deluge).hide(); |
|||
$(host_desc_torrent).show(); |
|||
$(torrent_username_option).show(); |
|||
$(torrent_verify_cert_option).hide(); |
|||
$(torrent_path_option).show(); |
|||
$(torrent_path_option).find('.fileBrowser').show(); |
|||
$(torrent_seed_time_option).hide(); |
|||
$(torrent_high_bandwidth_option).hide(); |
|||
$(torrent_label_option).show(); |
|||
$(path_blank).show(); |
|||
$(path_transmission).hide(); |
|||
$(path_synology).hide(); |
|||
$(torrent_paused_option).show(); |
|||
|
|||
if ('utorrent' == selectedProvider) { |
|||
client = 'uTorrent'; |
|||
$(torrent_path_option).hide(); |
|||
$(torrent_seed_time_option).show(); |
|||
} else if ('transmission' == selectedProvider){ |
|||
client = 'Transmission'; |
|||
$(torrent_high_bandwidth_option).show(); |
|||
$(torrent_label_option).hide(); |
|||
//$('#directory_title').text(client + directory);
|
|||
$(path_blank).hide(); |
|||
$(path_transmission).show(); |
|||
} else if ('deluge' == selectedProvider){ |
|||
client = 'Deluge'; |
|||
$(torrent_verify_cert_option).show(); |
|||
$(label_warning_deluge).show(); |
|||
$(host_desc_torrent).hide(); |
|||
$(host_desc_deluge).show(); |
|||
$(torrent_username_option).hide(); |
|||
//$('#directory_title').text(client + directory);
|
|||
} else if ('download_station' == selectedProvider){ |
|||
client = 'Synology DS'; |
|||
$(torrent_label_option).hide(); |
|||
$('#torrent_paused_option').hide(); |
|||
$(torrent_path_option).find('.fileBrowser').hide(); |
|||
//$('#directory_title').text(client + directory);
|
|||
$(path_synology).show(); |
|||
} else if ('rtorrent' == selectedProvider){ |
|||
client = 'rTorrent'; |
|||
$(host_desc_torrent).hide(); |
|||
$(host_desc_rtorrent).show(); |
|||
$(torrent_paused_option).hide(); |
|||
//$('#directory_title').text(client + directory);
|
|||
} |
|||
$('#host_title').text(client + host); |
|||
$('#username_title').text(client + username); |
|||
$('#password_title').text(client + password); |
|||
$('#torrent_client').text(client); |
|||
option_panel = '#options_torrent_clients'; |
|||
} |
|||
$(option_panel).show(); |
|||
} |
|||
|
|||
$('#nzb_method').change($(this).nzb_method_handler); |
|||
|
|||
$(this).nzb_method_handler(); |
|||
|
|||
$('#testSABnzbd').click(function(){ |
|||
$('#testSABnzbd_result').html(loading); |
|||
var sab_host = $('#sab_host').val(); |
|||
var sab_username = $('#sab_username').val(); |
|||
var sab_password = $('#sab_password').val(); |
|||
var sab_apiKey = $('#sab_apikey').val(); |
|||
|
|||
$.get(sbRoot + '/home/testSABnzbd', {'host': sab_host, 'username': sab_username, 'password': sab_password, 'apikey': sab_apiKey}, |
|||
function (data){ $('#testSABnzbd_result').html(data); }); |
|||
}); |
|||
|
|||
|
|||
$('#torrent_method').change($(this).torrent_method_handler); |
|||
|
|||
$(this).torrent_method_handler(); |
|||
|
|||
$('#use_torrents').click(function(){ |
|||
toggle_torrent_title(); |
|||
}); |
|||
|
|||
$('#test_torrent').click(function(){ |
|||
$('#test_torrent_result').html(loading); |
|||
var torrent_method = $('#torrent_method :selected').val(); |
|||
var torrent_host = $('#torrent_host').val(); |
|||
var torrent_username = $('#torrent_username').val(); |
|||
var torrent_password = $('#torrent_password').val(); |
|||
|
|||
$.get(sbRoot + '/home/testTorrent', {'torrent_method': torrent_method, 'host': torrent_host, 'username': torrent_username, 'password': torrent_password}, |
|||
function (data){ $('#test_torrent_result').html(data); }); |
|||
}); |
|||
|
|||
var loading = '<img src="' + sbRoot + '/images/loading16' + themeSpinner + '.gif" height="16" width="16" />'; |
|||
|
|||
function toggleTorrentTitle() { |
|||
var noTorrent$ = $('#no_torrents'); |
|||
if ($('#use_torrents').prop('checked')) |
|||
noTorrent$.show(); |
|||
else |
|||
noTorrent$.hide(); |
|||
} |
|||
|
|||
$.fn.nzbMethodHandler = function() { |
|||
|
|||
var selectedProvider = $('#nzb_method').find(':selected').val(), |
|||
blackholeSettings = '#blackhole-settings', |
|||
nzbgetSettings = '#nzbget-settings, #test-nzb-result, .nzbget', |
|||
sabnzbdSettings = '#sabnzbd-settings, #test-nzb-result, .sabnzbd'; |
|||
|
|||
$('#test-sabnzbd-result').html('Click below to test'); |
|||
$([blackholeSettings, nzbgetSettings, sabnzbdSettings].join(',')).hide(); |
|||
|
|||
if ('blackhole' == selectedProvider) { |
|||
$(blackholeSettings).show(); |
|||
} else if ('nzbget' == selectedProvider) { |
|||
$(nzbgetSettings).show(); |
|||
} else { |
|||
$(sabnzbdSettings).show(); |
|||
} |
|||
}; |
|||
$('#nzb_method').change($(this).nzbMethodHandler); |
|||
$(this).nzbMethodHandler(); |
|||
|
|||
$.fn.torrentMethodHandler = function() { |
|||
|
|||
var selectedProvider = $('#torrent_method').find(':selected').val(), |
|||
host = ' host:port', username = ' username', password = ' password', |
|||
label = ' label', |
|||
directory = ' directory', |
|||
client = '', |
|||
hideHostDesc = !1, hidePausedOption = !1, hideLabelOption = !1, hidePathBlank = !1, |
|||
optionsBlackhole = '#options-torrent-blackhole', |
|||
optionsClients = '#options-torrent-clients', |
|||
optionsPanel = optionsBlackhole; |
|||
|
|||
$(optionsBlackhole).hide(); |
|||
$(optionsClients).hide(); |
|||
|
|||
$('#test-torrent-result').html('Click below to test'); |
|||
$('.default-host').html(config.defaultHost[selectedProvider]); |
|||
|
|||
if ('blackhole' != selectedProvider) { |
|||
var labelWarningDeluge = '#label-warning-deluge', |
|||
hostDesc = '#host-desc-torrent', |
|||
hostDescDeluge = '#host-desc-deluge', |
|||
hostDescRtorrent = '#host-desc-rtorrent', |
|||
usernameOption = '#torrent-username-option', |
|||
verifyCertOption = '#torrent-verify-cert-option', |
|||
labelOption = '#torrent-label-option', |
|||
qBitTorrent = '.qbittorrent', |
|||
synology = '.synology', |
|||
transmission = '.transmission', |
|||
pathOption = '#torrent-path-option', |
|||
pathBlank = '#path-blank', |
|||
seedTimeOption = '#torrent-seed-time-option', |
|||
pausedOption = '#torrent-paused-option', |
|||
highBandwidthOption = '#torrent-high-bandwidth-option'; |
|||
|
|||
$([labelWarningDeluge, hostDescDeluge, hostDescRtorrent, verifyCertOption, seedTimeOption, |
|||
highBandwidthOption, qBitTorrent, synology, transmission].join(',')).hide(); |
|||
|
|||
$([hostDesc, usernameOption, pathOption, labelOption, pathBlank, pausedOption].join(',')).show(); |
|||
$(pathOption).find('.fileBrowser').show(); |
|||
|
|||
switch (selectedProvider) { |
|||
case 'utorrent': |
|||
client = 'uTorrent'; |
|||
$(pathOption).hide(); |
|||
$(seedTimeOption).show(); |
|||
break; |
|||
case 'deluge': |
|||
client = 'Deluge'; hideHostDesc = !0; |
|||
$(usernameOption).hide(); |
|||
$([hostDescDeluge, verifyCertOption, labelWarningDeluge].join(',')).show(); |
|||
break; |
|||
case 'transmission': |
|||
client = 'Transmission'; hideLabelOption = !0; hidePathBlank = !0; |
|||
$([transmission, highBandwidthOption].join(',')).show(); |
|||
break; |
|||
case 'qbittorrent': |
|||
// Setting Paused is buggy on qB, remove from use
|
|||
client = 'qBittorrent'; hidePausedOption = !0; hidePathBlank = !0; |
|||
$(qBitTorrent).show(); |
|||
break; |
|||
case 'download_station': |
|||
client = 'Synology DS'; hideLabelOption = !0; hidePausedOption = !0; |
|||
$(pathOption).find('.fileBrowser').hide(); |
|||
$(synology).show(); |
|||
break; |
|||
case 'rtorrent': |
|||
client = 'rTorrent'; hideHostDesc = !0; hidePausedOption = !0; |
|||
$(hostDescRtorrent).show(); |
|||
break; |
|||
} |
|||
hideHostDesc && $(hostDesc).hide(); |
|||
hideLabelOption && $(labelOption).hide(); |
|||
hidePausedOption && $(pausedOption).hide(); |
|||
hidePathBlank && $(pathBlank).hide(); |
|||
$('#host-title').text(client + host); |
|||
$('#username-title').text(client + username); |
|||
$('#password-title').text(client + password); |
|||
$('#torrent-client').text(client); |
|||
optionsPanel = optionsClients; |
|||
} |
|||
$(optionsPanel).show(); |
|||
}; |
|||
$('#torrent_method').change($(this).torrentMethodHandler); |
|||
$(this).torrentMethodHandler(); |
|||
|
|||
$('#use_torrents').click(function() { |
|||
toggleTorrentTitle(); |
|||
}); |
|||
|
|||
$.fn.testResult = function(data, test$) { |
|||
// endpoint changed so gracefully handle 404s until restarted
|
|||
$(test$).html(/404/.test(data) ? 'Test not found, a restart should fix' : data); |
|||
}; |
|||
|
|||
$('#test_torrent').click(function() { |
|||
$('#test-torrent-result').html(loading); |
|||
$.get(sbRoot + '/home/test_torrent', |
|||
{'torrent_method': $('#torrent_method').find(':selected').val(), 'host': $('#torrent_host').val(), |
|||
'username': $('#torrent_username').val(), 'password': $('#torrent_password').val()}, |
|||
function(data) { $(this).testResult(data, '#test-torrent-result'); }); |
|||
}); |
|||
|
|||
$('#test_nzbget').click(function() { |
|||
$('#test-nzb-result').html(loading); |
|||
$.get(sbRoot + '/home/test_nzbget', |
|||
{'host': $('#nzbget_host').val(), 'use_https': $('#nzbget_use_https').prop('checked'), |
|||
'username': $('#nzbget_username').val(), 'password': $('#nzbget_password').val()}, |
|||
function(data) { $(this).testResult(data, '#test-nzb-result'); }); |
|||
}); |
|||
|
|||
$('#test_sabnzbd').click(function() { |
|||
$('#test-nzb-result').html(loading); |
|||
$.get(sbRoot + '/home/test_sabnzbd', |
|||
{'host': $('#sab_host').val(), 'username': $('#sab_username').val(), |
|||
'password': $('#sab_password').val(), 'apikey': $('#sab_apikey').val()}, |
|||
function(data) { $(this).testResult(data, '#test-nzb-result'); }); |
|||
}); |
|||
|
|||
}); |
|||
|
@ -0,0 +1,74 @@ |
|||
# |
|||
# This file is part of SickGear. |
|||
# |
|||
# SickGear is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation, either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# SickGear is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with SickGear. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
from sickbeard import helpers, TORRENT_LABEL, TORRENT_PATH |
|||
from sickbeard.clients.generic import GenericClient |
|||
|
|||
|
|||
class QbittorrentAPI(GenericClient): |
|||
def __init__(self, host=None, username=None, password=None): |
|||
|
|||
super(QbittorrentAPI, self).__init__('qBittorrent', host, username, password) |
|||
|
|||
self.url = self.host |
|||
|
|||
def _get_auth(self): |
|||
|
|||
self.auth = (6 < self.api_version() and |
|||
'Ok' in helpers.getURL('%slogin' % self.host, session=self.session, |
|||
post_data={'username': self.username, 'password': self.password})) |
|||
return self.auth |
|||
|
|||
def api_version(self): |
|||
|
|||
return helpers.tryInt(helpers.getURL('%sversion/api' % self.host, session=self.session)) |
|||
|
|||
def _post_api(self, cmd='', **kwargs): |
|||
|
|||
return '' == helpers.getURL('%scommand/%s' % (self.host, cmd), session=self.session, **kwargs) |
|||
|
|||
def _add_torrent(self, cmd, **kwargs): |
|||
|
|||
label = TORRENT_LABEL.replace(' ', '_') |
|||
label_dict = {'label': label, 'category': label, 'savepath': TORRENT_PATH} |
|||
if 'post_data' in kwargs: |
|||
kwargs['post_data'].update(label_dict) |
|||
else: |
|||
kwargs.update({'post_data': label_dict}) |
|||
return self._post_api(cmd, **kwargs) |
|||
|
|||
def _add_torrent_uri(self, result): |
|||
|
|||
return self._add_torrent('download', post_data={'urls': result.url}) |
|||
|
|||
def _add_torrent_file(self, result): |
|||
|
|||
return self._add_torrent('upload', files={'torrents': ('%s.torrent' % result.name, result.content)}) |
|||
|
|||
### |
|||
# An issue in qB can lead to actions being ignored during the initial period after a file is added. |
|||
# Therefore, actions that need to be applied to existing items will be disabled unless fixed. |
|||
### |
|||
# def _set_torrent_priority(self, result): |
|||
# |
|||
# return self._post_api('%screasePrio' % ('de', 'in')[1 == result.priority], post_data={'hashes': result.hash}) |
|||
|
|||
# def _set_torrent_pause(self, result): |
|||
# |
|||
# return self._post_api(('resume', 'pause')[sickbeard.TORRENT_PAUSED], post_data={'hash': result.hash}) |
|||
|
|||
|
|||
api = QbittorrentAPI() |
Loading…
Reference in new issue