Update all qBittorrent WebAPI paths for client v4.1.0+

This commit is contained in:
Clinton Hall 2019-08-18 11:58:44 +12:00 committed by GitHub
commit 0ee60f152a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,6 @@
import requests import requests
import json import json
class LoginRequired(Exception): class LoginRequired(Exception):
def __str__(self): def __str__(self):
return 'Please login first.' return 'Please login first.'
@ -15,7 +14,7 @@ class Client(object):
self.url = url self.url = url
session = requests.Session() session = requests.Session()
check_prefs = session.get(url+'query/preferences') check_prefs = session.get(url+'api/v2/app/preferences')
if check_prefs.status_code == 200: if check_prefs.status_code == 200:
self._is_authenticated = True self._is_authenticated = True
@ -24,9 +23,9 @@ class Client(object):
elif check_prefs.status_code == 404: elif check_prefs.status_code == 404:
self._is_authenticated = False self._is_authenticated = False
raise RuntimeError(""" raise RuntimeError("""
This wrapper only supports qBittorrent applications This wrapper only supports qBittorrent applications with
with version higher than 3.1.x. version higher than 4.1.0 (which implemented Web API v2.0).
Please use the latest qBittorrent release. Please use the latest qBittorrent release.
""") """)
else: else:
@ -35,10 +34,8 @@ class Client(object):
def _get(self, endpoint, **kwargs): def _get(self, endpoint, **kwargs):
""" """
Method to perform GET request on the API. Method to perform GET request on the API.
:param endpoint: Endpoint of the API. :param endpoint: Endpoint of the API.
:param kwargs: Other keyword arguments for requests. :param kwargs: Other keyword arguments for requests.
:return: Response of the GET request. :return: Response of the GET request.
""" """
return self._request(endpoint, 'get', **kwargs) return self._request(endpoint, 'get', **kwargs)
@ -46,11 +43,9 @@ class Client(object):
def _post(self, endpoint, data, **kwargs): def _post(self, endpoint, data, **kwargs):
""" """
Method to perform POST request on the API. Method to perform POST request on the API.
:param endpoint: Endpoint of the API. :param endpoint: Endpoint of the API.
:param data: POST DATA for the request. :param data: POST DATA for the request.
:param kwargs: Other keyword arguments for requests. :param kwargs: Other keyword arguments for requests.
:return: Response of the POST request. :return: Response of the POST request.
""" """
return self._request(endpoint, 'post', data, **kwargs) return self._request(endpoint, 'post', data, **kwargs)
@ -58,12 +53,10 @@ class Client(object):
def _request(self, endpoint, method, data=None, **kwargs): def _request(self, endpoint, method, data=None, **kwargs):
""" """
Method to hanle both GET and POST requests. Method to hanle both GET and POST requests.
:param endpoint: Endpoint of the API. :param endpoint: Endpoint of the API.
:param method: Method of HTTP request. :param method: Method of HTTP request.
:param data: POST DATA for the request. :param data: POST DATA for the request.
:param kwargs: Other keyword arguments. :param kwargs: Other keyword arguments.
:return: Response for the request. :return: Response for the request.
""" """
final_url = self.url + endpoint final_url = self.url + endpoint
@ -93,18 +86,15 @@ class Client(object):
def login(self, username='admin', password='admin'): def login(self, username='admin', password='admin'):
""" """
Method to authenticate the qBittorrent Client. Method to authenticate the qBittorrent Client.
Declares a class attribute named ``session`` which Declares a class attribute named ``session`` which
stores the authenticated session if the login is correct. stores the authenticated session if the login is correct.
Else, shows the login error. Else, shows the login error.
:param username: Username. :param username: Username.
:param password: Password. :param password: Password.
:return: Response to login request to the API. :return: Response to login request to the API.
""" """
self.session = requests.Session() self.session = requests.Session()
login = self.session.post(self.url+'login', login = self.session.post(self.url+'api/v2/auth/login',
data={'username': username, data={'username': username,
'password': password}) 'password': password})
if login.text == 'Ok.': if login.text == 'Ok.':
@ -116,7 +106,7 @@ class Client(object):
""" """
Logout the current session. Logout the current session.
""" """
response = self._get('logout') response = self._get('api/v2/auth/logout')
self._is_authenticated = False self._is_authenticated = False
return response return response
@ -125,39 +115,31 @@ class Client(object):
""" """
Get qBittorrent version. Get qBittorrent version.
""" """
return self._get('version/qbittorrent') return self._get('api/v2/app/version')
@property @property
def api_version(self): def api_version(self):
""" """
Get WEB API version. Get WEB API version.
""" """
return self._get('version/api') return self._get('api/v2/app/webapiVersion')
@property
def api_min_version(self):
"""
Get minimum WEB API version.
"""
return self._get('version/api_min')
def shutdown(self): def shutdown(self):
""" """
Shutdown qBittorrent. Shutdown qBittorrent.
""" """
return self._get('command/shutdown') return self._get('api/v2/app/shutdown')
def torrents(self, **filters): def torrents(self, **filters):
""" """
Returns a list of torrents matching the supplied filters. Returns a list of torrents matching the supplied filters.
:param filter: Current status of the torrents. :param filter: Current status of the torrents.
:param category: Fetch all torrents with the supplied label. :param category: Fetch all torrents with the supplied label.
:param sort: Sort torrents by. :param sort: Sort torrents by.
:param reverse: Enable reverse sorting. :param reverse: Enable reverse sorting.
:param limit: Limit the number of torrents returned. :param limit: Limit the number of torrents returned.
:param offset: Set offset (if less than 0, offset from end). :param offset: Set offset (if less than 0, offset from end).
:param hashes: Filter by hashes. Can contain multiple hashes separated by |.
:return: list() of torrent with matching filter. :return: list() of torrent with matching filter.
""" """
params = {} params = {}
@ -166,46 +148,42 @@ class Client(object):
name = 'filter' if name == 'status' else name name = 'filter' if name == 'status' else name
params[name] = value params[name] = value
return self._get('query/torrents', params=params) return self._get('api/v2/torrents/info', params=params)
def get_torrent(self, infohash): def get_torrent(self, infohash):
""" """
Get details of the torrent. Get details of the torrent.
:param infohash: INFO HASH of the torrent. :param infohash: INFO HASH of the torrent.
""" """
return self._get('query/propertiesGeneral/' + infohash.lower()) return self._get('api/v2/torrents/properties', params={'hash': infohash.lower()})
def get_torrent_trackers(self, infohash): def get_torrent_trackers(self, infohash):
""" """
Get trackers for the torrent. Get trackers for the torrent.
:param infohash: INFO HASH of the torrent. :param infohash: INFO HASH of the torrent.
""" """
return self._get('query/propertiesTrackers/' + infohash.lower()) return self._get('api/v2/torrents/trackers', params={'hash': infohash.lower()})
def get_torrent_webseeds(self, infohash): def get_torrent_webseeds(self, infohash):
""" """
Get webseeds for the torrent. Get webseeds for the torrent.
:param infohash: INFO HASH of the torrent. :param infohash: INFO HASH of the torrent.
""" """
return self._get('query/propertiesWebSeeds/' + infohash.lower()) return self._get('api/v2/torrents/webseeds', params={'hash': infohash.lower()})
def get_torrent_files(self, infohash): def get_torrent_files(self, infohash):
""" """
Get list of files for the torrent. Get list of files for the torrent.
:param infohash: INFO HASH of the torrent. :param infohash: INFO HASH of the torrent.
""" """
return self._get('query/propertiesFiles/' + infohash.lower()) return self._get('api/v2/torrents/files', params={'hash': infohash.lower()})
@property @property
def global_transfer_info(self): def global_transfer_info(self):
""" """
Get JSON data of the global transfer info of qBittorrent. Get JSON data of the global transfer info of qBittorrent.
""" """
return self._get('query/transferInfo') return self._get('api/v2/transfer/info')
@property @property
def preferences(self): def preferences(self):
@ -214,39 +192,27 @@ class Client(object):
Can also be used to assign individual preferences. Can also be used to assign individual preferences.
For setting multiple preferences at once, For setting multiple preferences at once,
see ``set_preferences`` method. see ``set_preferences`` method.
Note: Even if this is a ``property``, Note: Even if this is a ``property``,
to fetch the current preferences dict, you are required to fetch the current preferences dict, you are required
to call it like a bound method. to call it like a bound method.
Wrong:: Wrong::
qb.preferences qb.preferences
Right:: Right::
qb.preferences() qb.preferences()
""" """
prefs = self._get('query/preferences') prefs = self._get('api/v2/app/preferences')
class Proxy(Client): class Proxy(Client):
""" """
Proxy class to to allow assignment of individual preferences. Proxy class to to allow assignment of individual preferences.
this class overrides some methods to ease things. this class overrides some methods to ease things.
Because of this, settings can be assigned like:: Because of this, settings can be assigned like::
In [5]: prefs = qb.preferences() In [5]: prefs = qb.preferences()
In [6]: prefs['autorun_enabled'] In [6]: prefs['autorun_enabled']
Out[6]: True Out[6]: True
In [7]: prefs['autorun_enabled'] = False In [7]: prefs['autorun_enabled'] = False
In [8]: prefs['autorun_enabled'] In [8]: prefs['autorun_enabled']
Out[8]: False Out[8]: False
""" """
def __init__(self, url, prefs, auth, session): def __init__(self, url, prefs, auth, session):
@ -270,78 +236,74 @@ class Client(object):
def sync(self, rid=0): def sync(self, rid=0):
""" """
Sync the torrents by supplied LAST RESPONSE ID. Sync the torrents by supplied LAST RESPONSE ID.
Read more @ http://git.io/vEgXr Read more @ https://git.io/fxgB8
:param rid: Response ID of last request. :param rid: Response ID of last request.
""" """
return self._get('sync/maindata', params={'rid': rid}) return self._get('api/v2/sync/maindata', params={'rid': rid})
def download_from_link(self, link, **kwargs): def download_from_link(self, link, **kwargs):
""" """
Download torrent using a link. Download torrent using a link.
:param link: URL Link or list of. :param link: URL Link or list of.
:param savepath: Path to download the torrent. :param savepath: Path to download the torrent.
:param category: Label or Category of the torrent(s). :param category: Label or Category of the torrent(s).
:return: Empty JSON data. :return: Empty JSON data.
""" """
# old:new format # qBittorrent requires adds to be done with multipath/form-data
old_arg_map = {'save_path': 'savepath'} # , 'label': 'category'} # POST requests for both URLs and .torrent files. Info on this
# can be found here, and here:
# convert old option names to new option names # http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file
options = kwargs.copy() # http://docs.python-requests.org/en/master/user/advanced/#post-multiple-multipart-encoded-files
for old_arg, new_arg in old_arg_map.items(): if isinstance(link, list):
if options.get(old_arg) and not options.get(new_arg): links = '\n'.join(link)
options[new_arg] = options[old_arg] else:
links = link
options['urls'] = link torrent_data = {}
torrent_data['urls'] = (None, links)
# workaround to send multipart/formdata request for k, v in kwargs.iteritems():
# http://stackoverflow.com/a/23131823/4726598 torrent_data[k] = (None, v)
dummy_file = {'_dummy': (None, '_dummy')} return self._post('api/v2/torrents/add', data=None, files=torrent_data)
return self._post('command/download', data=options, files=dummy_file)
def download_from_file(self, file_buffer, **kwargs): def download_from_file(self, file_buffer, **kwargs):
""" """
Download torrent using a file. Download torrent using a file.
:param file_buffer: Single file() buffer or list of. :param file_buffer: Single file() buffer or list of.
:param save_path: Path to download the torrent. :param save_path: Path to download the torrent.
:param label: Label of the torrent(s). :param label: Label of the torrent(s).
:return: Empty JSON data. :return: Empty JSON data.
""" """
# qBittorrent requires adds to be done with multipath/form-data
# POST requests for both URLs and .torrent files. Info on this
# can be found here, and here:
# http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file
# http://docs.python-requests.org/en/master/user/advanced/#post-multiple-multipart-encoded-files
if isinstance(file_buffer, list): if isinstance(file_buffer, list):
torrent_files = {} torrent_data = []
for i, f in enumerate(file_buffer): for f in file_buffer:
torrent_files.update({'torrents%s' % i: f}) fname = f.name
torrent_data.append(('torrents', (fname, f)))
else: else:
torrent_files = {'torrents': file_buffer} fname = file_buffer.name
torrent_data = [('torrents', (fname, file_buffer))]
for k, v in kwargs.iteritems():
torrent_data.append((k, (None, v)))
data = kwargs.copy() return self._post('api/v2/torrents/add', data=None, files=torrent_data)
if data.get('save_path'):
data.update({'savepath': data['save_path']})
return self._post('command/upload', data=data, files=torrent_files)
def add_trackers(self, infohash, trackers): def add_trackers(self, infohash, trackers):
""" """
Add trackers to a torrent. Add trackers to a torrent.
:param infohash: INFO HASH of torrent. :param infohash: INFO HASH of torrent.
:param trackers: Trackers. :param trackers: Trackers.
""" """
data = {'hash': infohash.lower(), data = {'hash': infohash.lower(),
'urls': trackers} 'urls': trackers}
return self._post('command/addTrackers', data=data) return self._post('api/v2/torrents/addTrackers', data=data)
@staticmethod @staticmethod
def _process_infohash_list(infohash_list): def _process_infohash_list(infohash_list):
""" """
Method to convert the infohash_list to qBittorrent API friendly values. Method to convert the infohash_list to qBittorrent API friendly values.
:param infohash_list: List of infohash. :param infohash_list: List of infohash.
""" """
if isinstance(infohash_list, list): if isinstance(infohash_list, list):
@ -353,142 +315,122 @@ class Client(object):
def pause(self, infohash): def pause(self, infohash):
""" """
Pause a torrent. Pause a torrent.
:param infohash: INFO HASH of torrent. :param infohash: INFO HASH of torrent.
""" """
return self._post('command/pause', data={'hash': infohash.lower()}) return self._post('api/v2/torrents/pause', data={'hashes': infohash.lower()})
def pause_all(self): def pause_all(self):
""" """
Pause all torrents. Pause all torrents.
""" """
return self._get('command/pauseAll') return self._post('api/v2/torrents/pause', data={'hashes': 'all'})
def pause_multiple(self, infohash_list): def pause_multiple(self, infohash_list):
""" """
Pause multiple torrents. Pause multiple torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/pauseAll', data=data) return self._post('api/v2/torrents/pause', data=data)
def set_label(self, infohash_list, label):
"""
Set the label on multiple torrents.
IMPORTANT: OLD API method, kept as it is to avoid breaking stuffs.
:param infohash_list: Single or list() of infohashes.
"""
data = self._process_infohash_list(infohash_list)
data['label'] = label
return self._post('command/setLabel', data=data)
def set_category(self, infohash_list, category): def set_category(self, infohash_list, category):
""" """
Set the category on multiple torrents. Set the category on multiple torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
data['category'] = category data['category'] = category
return self._post('command/setCategory', data=data) return self._post('api/v2/torrents/setCategory', data=data)
def resume(self, infohash): def resume(self, infohash):
""" """
Resume a paused torrent. Resume a paused torrent.
:param infohash: INFO HASH of torrent. :param infohash: INFO HASH of torrent.
""" """
return self._post('command/resume', data={'hash': infohash.lower()}) return self._post('api/v2/torrents/resume', data={'hashes': infohash.lower()})
def resume_all(self): def resume_all(self):
""" """
Resume all torrents. Resume all torrents.
""" """
return self._get('command/resumeAll') return self._get('api/v2/torrents/resume', data={'hashes': 'all'})
def resume_multiple(self, infohash_list): def resume_multiple(self, infohash_list):
""" """
Resume multiple paused torrents. Resume multiple paused torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/resumeAll', data=data) return self._post('api/v2/torrents/resume', data=data)
def delete(self, infohash_list): def delete(self, infohash_list):
""" """
Delete torrents. Delete torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/delete', data=data) data['deleteFiles'] = 'false'
return self._post('api/v2/torrents/delete', data=data)
def delete_permanently(self, infohash_list): def delete_permanently(self, infohash_list):
""" """
Permanently delete torrents. Permanently delete torrents.
*** WARNING : This will instruct qBittorrent to delete files
*** from your hard disk. Use with caution.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/deletePerm', data=data) data['deleteFiles'] = 'true'
return self._post('api/v2/torrents/delete', data=data)
def recheck(self, infohash_list): def recheck(self, infohash_list):
""" """
Recheck torrents. Recheck torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/recheck', data=data) return self._post('api/v2/torrents/recheck', data=data)
def increase_priority(self, infohash_list): def increase_priority(self, infohash_list):
""" """
Increase priority of torrents. Increase priority of torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/increasePrio', data=data) return self._post('api/v2/torrents/increasePrio', data=data)
def decrease_priority(self, infohash_list): def decrease_priority(self, infohash_list):
""" """
Decrease priority of torrents. Decrease priority of torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/decreasePrio', data=data) return self._post('api/v2/torrents/decreasePrio', data=data)
def set_max_priority(self, infohash_list): def set_max_priority(self, infohash_list):
""" """
Set torrents to maximum priority level. Set torrents to maximum priority level.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/topPrio', data=data) return self._post('api/v2/torrents/topPrio', data=data)
def set_min_priority(self, infohash_list): def set_min_priority(self, infohash_list):
""" """
Set torrents to minimum priority level. Set torrents to minimum priority level.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/bottomPrio', data=data) return self._post('api/v2/torrents/bottomPrio', data=data)
def set_file_priority(self, infohash, file_id, priority): def set_file_priority(self, infohash, file_id, priority):
""" """
Set file of a torrent to a supplied priority level. Set file of a torrent to a supplied priority level.
:param infohash: INFO HASH of torrent. :param infohash: INFO HASH of torrent.
:param file_id: ID of the file to set priority. :param file_id: ID of the file to set priority.
:param priority: Priority level of the file. :param priority: Priority level of the file.
""" """
if priority not in [0, 1, 2, 7]: if priority not in [0, 1, 6, 7]:
raise ValueError("Invalid priority, refer WEB-UI docs for info.") raise ValueError("Invalid priority, refer WEB-UI docs for info.")
elif not isinstance(file_id, int): elif not isinstance(file_id, int):
raise TypeError("File ID must be an int") raise TypeError("File ID must be an int")
@ -497,7 +439,7 @@ class Client(object):
'id': file_id, 'id': file_id,
'priority': priority} 'priority': priority}
return self._post('command/setFilePrio', data=data) return self._post('api/v2/torrents/filePrio', data=data)
# Get-set global download and upload speed limits. # Get-set global download and upload speed limits.
@ -505,15 +447,14 @@ class Client(object):
""" """
Get global download speed limit. Get global download speed limit.
""" """
return self._get('command/getGlobalDlLimit') return self._get('api/v2/transfer/downloadLimit')
def set_global_download_limit(self, limit): def set_global_download_limit(self, limit):
""" """
Set global download speed limit. Set global download speed limit.
:param limit: Speed limit in bytes. :param limit: Speed limit in bytes.
""" """
return self._post('command/setGlobalDlLimit', data={'limit': limit}) return self._post('api/v2/transfer/setDownloadLimit', data={'limit': limit})
global_download_limit = property(get_global_download_limit, global_download_limit = property(get_global_download_limit,
set_global_download_limit) set_global_download_limit)
@ -522,15 +463,14 @@ class Client(object):
""" """
Get global upload speed limit. Get global upload speed limit.
""" """
return self._get('command/getGlobalUpLimit') return self._get('api/v2/transfer/uploadLimit')
def set_global_upload_limit(self, limit): def set_global_upload_limit(self, limit):
""" """
Set global upload speed limit. Set global upload speed limit.
:param limit: Speed limit in bytes. :param limit: Speed limit in bytes.
""" """
return self._post('command/setGlobalUpLimit', data={'limit': limit}) return self._post('api/v2/transfer/setUploadLimit', data={'limit': limit})
global_upload_limit = property(get_global_upload_limit, global_upload_limit = property(get_global_upload_limit,
set_global_upload_limit) set_global_upload_limit)
@ -539,61 +479,56 @@ class Client(object):
def get_torrent_download_limit(self, infohash_list): def get_torrent_download_limit(self, infohash_list):
""" """
Get download speed limit of the supplied torrents. Get download speed limit of the supplied torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/getTorrentsDlLimit', data=data) return self._post('api/v2/torrents/downloadLimit', data=data)
def set_torrent_download_limit(self, infohash_list, limit): def set_torrent_download_limit(self, infohash_list, limit):
""" """
Set download speed limit of the supplied torrents. Set download speed limit of the supplied torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
:param limit: Speed limit in bytes. :param limit: Speed limit in bytes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
data.update({'limit': limit}) data.update({'limit': limit})
return self._post('command/setTorrentsDlLimit', data=data) return self._post('api/v2/torrents/setDownloadLimit', data=data)
def get_torrent_upload_limit(self, infohash_list): def get_torrent_upload_limit(self, infohash_list):
""" """
Get upoload speed limit of the supplied torrents. Get upoload speed limit of the supplied torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/getTorrentsUpLimit', data=data) return self._post('api/v2/torrents/uploadLimit', data=data)
def set_torrent_upload_limit(self, infohash_list, limit): def set_torrent_upload_limit(self, infohash_list, limit):
""" """
Set upload speed limit of the supplied torrents. Set upload speed limit of the supplied torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
:param limit: Speed limit in bytes. :param limit: Speed limit in bytes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
data.update({'limit': limit}) data.update({'limit': limit})
return self._post('command/setTorrentsUpLimit', data=data) return self._post('api/v2/torrents/setUploadLimit', data=data)
# setting preferences # setting preferences
def set_preferences(self, **kwargs): def set_preferences(self, **kwargs):
""" """
Set preferences of qBittorrent. Set preferences of qBittorrent.
Read all possible preferences @ http://git.io/vEgDQ Read all possible preferences @ https://git.io/fx2Y9
:param kwargs: set preferences in kwargs form. :param kwargs: set preferences in kwargs form.
""" """
json_data = "json={}".format(json.dumps(kwargs)) json_data = "json={}".format(json.dumps(kwargs))
headers = {'content-type': 'application/x-www-form-urlencoded'} headers = {'content-type': 'application/x-www-form-urlencoded'}
return self._post('command/setPreferences', data=json_data, return self._post('api/v2/app/setPreferences', data=json_data,
headers=headers) headers=headers)
def get_alternative_speed_status(self): def get_alternative_speed_status(self):
""" """
Get Alternative speed limits. (1/0) Get Alternative speed limits. (1/0)
""" """
return self._get('command/alternativeSpeedLimitsEnabled') return self._get('api/v2/transfer/speedLimitsMode')
alternative_speed_status = property(get_alternative_speed_status) alternative_speed_status = property(get_alternative_speed_status)
@ -601,33 +536,30 @@ class Client(object):
""" """
Toggle alternative speed limits. Toggle alternative speed limits.
""" """
return self._get('command/toggleAlternativeSpeedLimits') return self._get('api/v2/transfer/toggleSpeedLimitsMode')
def toggle_sequential_download(self, infohash_list): def toggle_sequential_download(self, infohash_list):
""" """
Toggle sequential download in supplied torrents. Toggle sequential download in supplied torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/toggleSequentialDownload', data=data) return self._post('api/v2/torrents/toggleSequentialDownload', data=data)
def toggle_first_last_piece_priority(self, infohash_list): def toggle_first_last_piece_priority(self, infohash_list):
""" """
Toggle first/last piece priority of supplied torrents. Toggle first/last piece priority of supplied torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
return self._post('command/toggleFirstLastPiecePrio', data=data) return self._post('api/v2/torrents/toggleFirstLastPiecePrio', data=data)
def force_start(self, infohash_list, value=True): def force_start(self, infohash_list, value=True):
""" """
Force start selected torrents. Force start selected torrents.
:param infohash_list: Single or list() of infohashes. :param infohash_list: Single or list() of infohashes.
:param value: Force start value (bool) :param value: Force start value (bool)
""" """
data = self._process_infohash_list(infohash_list) data = self._process_infohash_list(infohash_list)
data.update({'value': json.dumps(value)}) data.update({'value': json.dumps(value)})
return self._post('command/setForceStart', data=data) return self._post('api/v2/torrents/setForceStart', data=data)