12 changed files with 414 additions and 318 deletions
@ -1,158 +1,154 @@ |
|||||
|
/** @namespace config.defaultHost */ |
||||
$(document).ready(function(){ |
$(document).ready(function(){ |
||||
var loading = '<img src="' + sbRoot + '/images/loading16' + themeSpinner + '.gif" height="16" width="16" />'; |
|
||||
|
var loading = '<img src="' + sbRoot + '/images/loading16' + themeSpinner + '.gif" height="16" width="16" />'; |
||||
function toggle_torrent_title(){ |
|
||||
if ($('#use_torrents').prop('checked')) |
function toggleTorrentTitle() { |
||||
$('#no_torrents').show(); |
var noTorrent$ = $('#no_torrents'); |
||||
else |
if ($('#use_torrents').prop('checked')) |
||||
$('#no_torrents').hide(); |
noTorrent$.show(); |
||||
} |
else |
||||
|
noTorrent$.hide(); |
||||
$.fn.nzb_method_handler = function() { |
} |
||||
|
|
||||
var selectedProvider = $('#nzb_method :selected').val(), |
$.fn.nzbMethodHandler = function() { |
||||
blackhole_settings = '#blackhole_settings', |
|
||||
sabnzbd_settings = '#sabnzbd_settings', |
var selectedProvider = $('#nzb_method').find(':selected').val(), |
||||
testSABnzbd = '#testSABnzbd', |
blackholeSettings = '#blackhole-settings', |
||||
testSABnzbd_result = '#testSABnzbd_result', |
nzbgetSettings = '#nzbget-settings, #test-nzb-result, .nzbget', |
||||
nzbget_settings = '#nzbget_settings'; |
sabnzbdSettings = '#sabnzbd-settings, #test-nzb-result, .sabnzbd'; |
||||
|
|
||||
$(blackhole_settings).hide(); |
$('#test-sabnzbd-result').html('Click below to test'); |
||||
$(sabnzbd_settings).hide(); |
$([blackholeSettings, nzbgetSettings, sabnzbdSettings].join(',')).hide(); |
||||
$(testSABnzbd).hide(); |
|
||||
$(testSABnzbd_result).hide(); |
if ('blackhole' == selectedProvider) { |
||||
$(nzbget_settings).hide(); |
$(blackholeSettings).show(); |
||||
|
} else if ('nzbget' == selectedProvider) { |
||||
if ('blackhole' == selectedProvider) { |
$(nzbgetSettings).show(); |
||||
$(blackhole_settings).show(); |
} else { |
||||
} else if ('nzbget' == selectedProvider) { |
$(sabnzbdSettings).show(); |
||||
$(nzbget_settings).show(); |
} |
||||
} else { |
}; |
||||
$(sabnzbd_settings).show(); |
$('#nzb_method').change($(this).nzbMethodHandler); |
||||
$(testSABnzbd).show(); |
$(this).nzbMethodHandler(); |
||||
$(testSABnzbd_result).show(); |
|
||||
} |
$.fn.torrentMethodHandler = function() { |
||||
} |
|
||||
|
var selectedProvider = $('#torrent_method').find(':selected').val(), |
||||
$.fn.torrent_method_handler = function() { |
host = ' host:port', username = ' username', password = ' password', |
||||
|
label = ' label', |
||||
$('#options_torrent_clients').hide(); |
directory = ' directory', |
||||
$('#options_torrent_blackhole').hide(); |
client = '', |
||||
|
hideHostDesc = !1, hidePausedOption = !1, hideLabelOption = !1, hidePathBlank = !1, |
||||
var selectedProvider = $('#torrent_method :selected').val(), |
optionsBlackhole = '#options-torrent-blackhole', |
||||
host = ' host:port', |
optionsClients = '#options-torrent-clients', |
||||
username = ' username', |
optionsPanel = optionsBlackhole; |
||||
password = ' password', |
|
||||
label = ' label', |
$(optionsBlackhole).hide(); |
||||
directory = ' directory', |
$(optionsClients).hide(); |
||||
client = '', |
|
||||
option_panel = '#options_torrent_blackhole'; |
$('#test-torrent-result').html('Click below to test'); |
||||
|
$('.default-host').html(config.defaultHost[selectedProvider]); |
||||
if ('blackhole' != selectedProvider) { |
|
||||
var label_warning_deluge = '#label_warning_deluge', |
if ('blackhole' != selectedProvider) { |
||||
host_desc_rtorrent = '#host_desc_rtorrent', |
var labelWarningDeluge = '#label-warning-deluge', |
||||
host_desc_torrent = '#host_desc_torrent', |
hostDesc = '#host-desc-torrent', |
||||
torrent_verify_cert_option = '#torrent_verify_cert_option', |
hostDescDeluge = '#host-desc-deluge', |
||||
torrent_path_option = '#torrent_path_option', |
hostDescRtorrent = '#host-desc-rtorrent', |
||||
torrent_seed_time_option = '#torrent_seed_time_option', |
usernameOption = '#torrent-username-option', |
||||
torrent_high_bandwidth_option = '#torrent_high_bandwidth_option', |
verifyCertOption = '#torrent-verify-cert-option', |
||||
torrent_label_option = '#torrent_label_option', |
labelOption = '#torrent-label-option', |
||||
path_blank = '#path_blank', |
qBitTorrent = '.qbittorrent', |
||||
path_transmission = '#path_transmission', |
synology = '.synology', |
||||
path_synology = '#path_synology', |
transmission = '.transmission', |
||||
torrent_paused_option = '#torrent_paused_option'; |
pathOption = '#torrent-path-option', |
||||
|
pathBlank = '#path-blank', |
||||
$(label_warning_deluge).hide(); |
seedTimeOption = '#torrent-seed-time-option', |
||||
$(host_desc_rtorrent).hide(); |
pausedOption = '#torrent-paused-option', |
||||
$(host_desc_deluge).hide(); |
highBandwidthOption = '#torrent-high-bandwidth-option'; |
||||
$(host_desc_torrent).show(); |
|
||||
$(torrent_username_option).show(); |
$([labelWarningDeluge, hostDescDeluge, hostDescRtorrent, verifyCertOption, seedTimeOption, |
||||
$(torrent_verify_cert_option).hide(); |
highBandwidthOption, qBitTorrent, synology, transmission].join(',')).hide(); |
||||
$(torrent_path_option).show(); |
|
||||
$(torrent_path_option).find('.fileBrowser').show(); |
$([hostDesc, usernameOption, pathOption, labelOption, pathBlank, pausedOption].join(',')).show(); |
||||
$(torrent_seed_time_option).hide(); |
$(pathOption).find('.fileBrowser').show(); |
||||
$(torrent_high_bandwidth_option).hide(); |
|
||||
$(torrent_label_option).show(); |
switch (selectedProvider) { |
||||
$(path_blank).show(); |
case 'utorrent': |
||||
$(path_transmission).hide(); |
client = 'uTorrent'; |
||||
$(path_synology).hide(); |
$(pathOption).hide(); |
||||
$(torrent_paused_option).show(); |
$(seedTimeOption).show(); |
||||
|
break; |
||||
if ('utorrent' == selectedProvider) { |
case 'deluge': |
||||
client = 'uTorrent'; |
client = 'Deluge'; hideHostDesc = !0; |
||||
$(torrent_path_option).hide(); |
$(usernameOption).hide(); |
||||
$(torrent_seed_time_option).show(); |
$([hostDescDeluge, verifyCertOption, labelWarningDeluge].join(',')).show(); |
||||
} else if ('transmission' == selectedProvider){ |
break; |
||||
client = 'Transmission'; |
case 'transmission': |
||||
$(torrent_high_bandwidth_option).show(); |
client = 'Transmission'; hideLabelOption = !0; hidePathBlank = !0; |
||||
$(torrent_label_option).hide(); |
$([transmission, highBandwidthOption].join(',')).show(); |
||||
//$('#directory_title').text(client + directory);
|
break; |
||||
$(path_blank).hide(); |
case 'qbittorrent': |
||||
$(path_transmission).show(); |
// Setting Paused is buggy on qB, remove from use
|
||||
} else if ('deluge' == selectedProvider){ |
client = 'qBittorrent'; hidePausedOption = !0; hidePathBlank = !0; |
||||
client = 'Deluge'; |
$(qBitTorrent).show(); |
||||
$(torrent_verify_cert_option).show(); |
break; |
||||
$(label_warning_deluge).show(); |
case 'download_station': |
||||
$(host_desc_torrent).hide(); |
client = 'Synology DS'; hideLabelOption = !0; hidePausedOption = !0; |
||||
$(host_desc_deluge).show(); |
$(pathOption).find('.fileBrowser').hide(); |
||||
$(torrent_username_option).hide(); |
$(synology).show(); |
||||
//$('#directory_title').text(client + directory);
|
break; |
||||
} else if ('download_station' == selectedProvider){ |
case 'rtorrent': |
||||
client = 'Synology DS'; |
client = 'rTorrent'; hideHostDesc = !0; hidePausedOption = !0; |
||||
$(torrent_label_option).hide(); |
$(hostDescRtorrent).show(); |
||||
$('#torrent_paused_option').hide(); |
break; |
||||
$(torrent_path_option).find('.fileBrowser').hide(); |
} |
||||
//$('#directory_title').text(client + directory);
|
hideHostDesc && $(hostDesc).hide(); |
||||
$(path_synology).show(); |
hideLabelOption && $(labelOption).hide(); |
||||
} else if ('rtorrent' == selectedProvider){ |
hidePausedOption && $(pausedOption).hide(); |
||||
client = 'rTorrent'; |
hidePathBlank && $(pathBlank).hide(); |
||||
$(host_desc_torrent).hide(); |
$('#host-title').text(client + host); |
||||
$(host_desc_rtorrent).show(); |
$('#username-title').text(client + username); |
||||
$(torrent_paused_option).hide(); |
$('#password-title').text(client + password); |
||||
//$('#directory_title').text(client + directory);
|
$('#torrent-client').text(client); |
||||
} |
optionsPanel = optionsClients; |
||||
$('#host_title').text(client + host); |
} |
||||
$('#username_title').text(client + username); |
$(optionsPanel).show(); |
||||
$('#password_title').text(client + password); |
}; |
||||
$('#torrent_client').text(client); |
$('#torrent_method').change($(this).torrentMethodHandler); |
||||
option_panel = '#options_torrent_clients'; |
$(this).torrentMethodHandler(); |
||||
} |
|
||||
$(option_panel).show(); |
$('#use_torrents').click(function() { |
||||
} |
toggleTorrentTitle(); |
||||
|
}); |
||||
$('#nzb_method').change($(this).nzb_method_handler); |
|
||||
|
$.fn.testResult = function(data, test$) { |
||||
$(this).nzb_method_handler(); |
// endpoint changed so gracefully handle 404s until restarted
|
||||
|
$(test$).html(/404/.test(data) ? 'Test not found, a restart should fix' : data); |
||||
$('#testSABnzbd').click(function(){ |
}; |
||||
$('#testSABnzbd_result').html(loading); |
|
||||
var sab_host = $('#sab_host').val(); |
$('#test_torrent').click(function() { |
||||
var sab_username = $('#sab_username').val(); |
$('#test-torrent-result').html(loading); |
||||
var sab_password = $('#sab_password').val(); |
$.get(sbRoot + '/home/test_torrent', |
||||
var sab_apiKey = $('#sab_apikey').val(); |
{'torrent_method': $('#torrent_method').find(':selected').val(), 'host': $('#torrent_host').val(), |
||||
|
'username': $('#torrent_username').val(), 'password': $('#torrent_password').val()}, |
||||
$.get(sbRoot + '/home/testSABnzbd', {'host': sab_host, 'username': sab_username, 'password': sab_password, 'apikey': sab_apiKey}, |
function(data) { $(this).testResult(data, '#test-torrent-result'); }); |
||||
function (data){ $('#testSABnzbd_result').html(data); }); |
}); |
||||
}); |
|
||||
|
$('#test_nzbget').click(function() { |
||||
|
$('#test-nzb-result').html(loading); |
||||
$('#torrent_method').change($(this).torrent_method_handler); |
$.get(sbRoot + '/home/test_nzbget', |
||||
|
{'host': $('#nzbget_host').val(), 'use_https': $('#nzbget_use_https').prop('checked'), |
||||
$(this).torrent_method_handler(); |
'username': $('#nzbget_username').val(), 'password': $('#nzbget_password').val()}, |
||||
|
function(data) { $(this).testResult(data, '#test-nzb-result'); }); |
||||
$('#use_torrents').click(function(){ |
}); |
||||
toggle_torrent_title(); |
|
||||
}); |
$('#test_sabnzbd').click(function() { |
||||
|
$('#test-nzb-result').html(loading); |
||||
$('#test_torrent').click(function(){ |
$.get(sbRoot + '/home/test_sabnzbd', |
||||
$('#test_torrent_result').html(loading); |
{'host': $('#sab_host').val(), 'username': $('#sab_username').val(), |
||||
var torrent_method = $('#torrent_method :selected').val(); |
'password': $('#sab_password').val(), 'apikey': $('#sab_apikey').val()}, |
||||
var torrent_host = $('#torrent_host').val(); |
function(data) { $(this).testResult(data, '#test-nzb-result'); }); |
||||
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); }); |
|
||||
}); |
|
||||
|
|
||||
}); |
}); |
||||
|
@ -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