qbit fixes

pull/1/head
DiMartinoXBMC 2016-01-13 15:49:39 +03:00
parent 2ad1b839b9
commit 30bc8e4d06
4 changed files with 796 additions and 647 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1258,7 +1258,7 @@ class Core:
if not hash: if not hash:
actions = [('start', self.localize('Start')), ('stop', self.localize('Stop')), actions = [('start', self.localize('Start')), ('stop', self.localize('Stop')),
('remove', self.localize('Remove')), ('remove', self.localize('Remove')),
('3', self.localize('High Priority All Files')), ('0', self.localize('Skip All Files')), ('3', self.localize('High Priority Files')), ('0', self.localize('Skip All Files')),
('removedata', self.localize('Remove with files'))] ('removedata', self.localize('Remove with files'))]
folder = True folder = True

View File

@ -1988,3 +1988,9 @@ def file_url(torrentFile):
torrentFile = urlparse.urljoin('file:', urllib.pathname2url(ensure_str(torrentFile))) torrentFile = urlparse.urljoin('file:', urllib.pathname2url(ensure_str(torrentFile)))
return torrentFile return torrentFile
def dump(obj):
for attr in dir(obj):
try:
log("'%s':'%s'," % (attr, getattr(obj, attr)))
except:
pass

View File

@ -13,7 +13,7 @@ import json
import itertools import itertools
from StringIO import StringIO from StringIO import StringIO
import gzip import gzip
from functions import log from functions import log, dump
import xbmc import xbmc
import xbmcgui import xbmcgui
@ -850,6 +850,7 @@ class qBittorrent:
self.url += url self.url += url
self.http = HTTP() self.http = HTTP()
self.cookie = self.get_auth()
def list(self): def list(self):
obj = self.action('/query/torrents') obj = self.action('/query/torrents')
@ -874,7 +875,8 @@ class qBittorrent:
'leech': r['num_leechs'], 'leech': r['num_leechs'],
'dir': r['save_path'] 'dir': r['save_path']
} }
#if len(r['files']) > 1: add['dir'] = os.path.join(r['save_path'], r['name']) flist = self.action('/query/propertiesFiles/'+r['hash'])
if len(flist) > 1: add['dir'] = os.path.join(r['save_path'], r['name'])
res.append(add) res.append(add)
return res return res
@ -981,7 +983,7 @@ class qBittorrent:
return True if res else None return True if res else None
def setprio_simple(self, id, prio, ind): def setprio_simple(self, id, prio, ind):
log(str((id, prio, ind))) #log(str((id, prio, ind)))
if prio == '3': prio = '7' if prio == '3': prio = '7'
params = {'hash':id, 'priority':prio, 'id': ind} params = {'hash':id, 'priority':prio, 'id': ind}
obj = self.action_post('/command/setFilePrio', params) obj = self.action_post('/command/setFilePrio', params)
@ -995,11 +997,7 @@ class qBittorrent:
self.setprio_simple(hash, action, ind) self.setprio_simple(hash, action, ind)
def action(self, uri, upload=None): def action(self, uri, upload=None):
cookie = self.get_auth() req = HTTPRequest(self.url + uri, headers={'Cookie': self.cookie})
if not cookie:
return None
req = HTTPRequest(self.url + uri, headers={'Cookie': cookie})
if upload: if upload:
req.upload = upload req.upload = upload
@ -1021,12 +1019,10 @@ class qBittorrent:
return obj return obj
def action_post(self, uri, params=None): def action_post(self, uri, params=None):
cookie = self.get_auth() response = self.http.fetch(self.url + uri, headers={'Cookie': self.cookie},
if not cookie: method='POST', params=params, gzip=True,)
return None
response = self.http.fetch(self.url + uri, headers={'Cookie': cookie}, method='POST', params=params, gzip=True)
#dump(response)
if response.error: if response.error:
return None return None
@ -1036,11 +1032,11 @@ class qBittorrent:
return response return response
def action_simple(self, action, id): def action_simple(self, action, id):
actions = {'start': '/command/resume', actions = {'start': ['/command/resume',{'hash':id,}],
'stop': '/command/pause', 'stop': ['/command/pause',{'hash':id,}],
'remove': '/command/delete', 'remove': ['/command/delete',{'hashes':id}],
'removedata': '/command/deletePerm'} 'removedata': ['/command/deletePerm',{'hashes':id}]}
obj = self.action_post(actions[action], {'hash':id}) obj = self.action_post(actions[action][0],actions[action][1])
return True if obj else None return True if obj else None
def get_auth(self): def get_auth(self):
@ -1080,7 +1076,7 @@ class Deluge:
if port: if port:
self.url += ':' + str(port) self.url += ':' + str(port)
self.url += url self.url += url
log(str(self.url)) #log(str(self.url))
self.http = HTTP() self.http = HTTP()
def get_info(self): def get_info(self):