Added test connection button for uTorrent
This commit is contained in:
1 parent
b47a94852a
commit
964ed5f497
4 files changed
+101
No files matched your search
@@ -49,6 +49,7 @@ class ClientScript(Plugin):
|
|||||||
'scripts/page/settings.js',
|
'scripts/page/settings.js',
|
||||||
'scripts/page/about.js',
|
'scripts/page/about.js',
|
||||||
'scripts/page/manage.js',
|
'scripts/page/manage.js',
|
||||||
|
'scripts/misc/downloaders.js',
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from base64 import b32decode, b16encode
|
from base64 import b32decode, b16encode
|
||||||
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import addEvent
|
from couchpotato.core.event import addEvent
|
||||||
from couchpotato.core.helpers.variable import mergeDicts
|
from couchpotato.core.helpers.variable import mergeDicts
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
@@ -14,6 +15,7 @@ class Downloader(Provider):
|
|||||||
protocol = []
|
protocol = []
|
||||||
http_time_between_calls = 0
|
http_time_between_calls = 0
|
||||||
status_support = True
|
status_support = True
|
||||||
|
testable = False
|
||||||
|
|
||||||
torrent_sources = [
|
torrent_sources = [
|
||||||
'http://torrage.com/torrent/%s.torrent',
|
'http://torrage.com/torrent/%s.torrent',
|
||||||
@@ -42,6 +44,8 @@ class Downloader(Provider):
|
|||||||
addEvent('download.remove_failed', self._removeFailed)
|
addEvent('download.remove_failed', self._removeFailed)
|
||||||
addEvent('download.pause', self._pause)
|
addEvent('download.pause', self._pause)
|
||||||
addEvent('download.process_complete', self._processComplete)
|
addEvent('download.process_complete', self._processComplete)
|
||||||
|
addApiView('download.%s.is_testable' % self.getName().lower(), self.isTestable)
|
||||||
|
addApiView('download.%s.test' % self.getName().lower(), self._test)
|
||||||
|
|
||||||
def getEnabledProtocol(self):
|
def getEnabledProtocol(self):
|
||||||
for download_protocol in self.protocol:
|
for download_protocol in self.protocol:
|
||||||
@@ -158,6 +162,15 @@ class Downloader(Provider):
|
|||||||
(d_manual and manual or d_manual is False) and \
|
(d_manual and manual or d_manual is False) and \
|
||||||
(not data or self.isCorrectProtocol(data.get('protocol')))
|
(not data or self.isCorrectProtocol(data.get('protocol')))
|
||||||
|
|
||||||
|
def isTestable(self):
|
||||||
|
return {'success': self.testable}
|
||||||
|
|
||||||
|
def _test(self):
|
||||||
|
return {'success': self.test()}
|
||||||
|
|
||||||
|
def test(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def _pause(self, release_download, pause = True):
|
def _pause(self, release_download, pause = True):
|
||||||
if self.isDisabled(manual = True, data = {}):
|
if self.isDisabled(manual = True, data = {}):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from base64 import b16encode, b32decode
|
from base64 import b16encode, b32decode
|
||||||
from bencode import bencode as benc, bdecode
|
from bencode import bencode as benc, bdecode
|
||||||
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.downloaders.base import Downloader, ReleaseDownloadList
|
from couchpotato.core.downloaders.base import Downloader, ReleaseDownloadList
|
||||||
from couchpotato.core.helpers.encoding import isInt, ss, sp
|
from couchpotato.core.helpers.encoding import isInt, ss, sp
|
||||||
from couchpotato.core.helpers.variable import tryInt, tryFloat, cleanHost
|
from couchpotato.core.helpers.variable import tryInt, tryFloat, cleanHost
|
||||||
@@ -24,6 +25,7 @@ class uTorrent(Downloader):
|
|||||||
|
|
||||||
protocol = ['torrent', 'torrent_magnet']
|
protocol = ['torrent', 'torrent_magnet']
|
||||||
utorrent_api = None
|
utorrent_api = None
|
||||||
|
testable = True
|
||||||
status_flags = {
|
status_flags = {
|
||||||
'STARTED' : 1,
|
'STARTED' : 1,
|
||||||
'CHECKING' : 2,
|
'CHECKING' : 2,
|
||||||
@@ -46,6 +48,11 @@ class uTorrent(Downloader):
|
|||||||
|
|
||||||
return self.utorrent_api
|
return self.utorrent_api
|
||||||
|
|
||||||
|
def test(self):
|
||||||
|
if self.connect() and self.utorrent_api.get_status():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def download(self, data = None, media = None, filedata = None):
|
def download(self, data = None, media = None, filedata = None):
|
||||||
if not media: media = {}
|
if not media: media = {}
|
||||||
if not data: data = {}
|
if not data: data = {}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
var DownloadersBase = new Class({
|
||||||
|
|
||||||
|
Implements: [Events],
|
||||||
|
|
||||||
|
initialize: function(){
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// Add test buttons to settings page
|
||||||
|
App.addEvent('load', self.addTestButtons.bind(self));
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
// Downloaders setting tests
|
||||||
|
addTestButtons: function(){
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var setting_page = App.getPage('Settings');
|
||||||
|
setting_page.addEvent('create', function(){
|
||||||
|
Object.each(setting_page.tabs.downloaders.groups, self.addTestButton.bind(self))
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
addTestButton: function(fieldset, plugin_name){
|
||||||
|
var self = this,
|
||||||
|
button_name = self.testButtonName(fieldset);
|
||||||
|
|
||||||
|
if(button_name.contains('Downloaders')) return;
|
||||||
|
|
||||||
|
Api.request('download.'+plugin_name+'.is_testable', {
|
||||||
|
'onComplete': function(json){
|
||||||
|
if(json.success){
|
||||||
|
// Only add test button if downloader is testable
|
||||||
|
new Element('.ctrlHolder.test_button').adopt(
|
||||||
|
new Element('a.button', {
|
||||||
|
'text': button_name,
|
||||||
|
'events': {
|
||||||
|
'click': function(){
|
||||||
|
var button = fieldset.getElement('.test_button .button');
|
||||||
|
button.set('text', 'Connecting...');
|
||||||
|
|
||||||
|
Api.request('download.'+plugin_name+'.test', {
|
||||||
|
'onComplete': function(json){
|
||||||
|
|
||||||
|
button.set('text', button_name);
|
||||||
|
|
||||||
|
if(json.success){
|
||||||
|
var message = new Element('span.success', {
|
||||||
|
'text': 'Connection successful'
|
||||||
|
}).inject(button, 'after')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var message = new Element('span.failed', {
|
||||||
|
'text': 'Connection failed. Check logs for details.'
|
||||||
|
}).inject(button, 'after')
|
||||||
|
}
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
message.destroy();
|
||||||
|
}).delay(3000)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
).inject(fieldset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
testButtonName: function(fieldset){
|
||||||
|
var name = String(fieldset.getElement('h2').innerHTML).substring(0,String(fieldset.getElement('h2').innerHTML).indexOf("<span"));
|
||||||
|
return 'Test '+name;
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
window.Downloaders = new DownloadersBase();
|
||||||
Reference in new issue
Block a user