Commit f472dcac authored by echel0n's avatar echel0n

Resolved issues with BTN Torrent provider.

parent f6fce276
......@@ -15,12 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <>.
import socket
import time
import xmlrpc.client
import json
import random
import sickrage
from sickrage.core import scene_exceptions, MainDB
......@@ -195,21 +191,24 @@ class BTNProvider(TorrentProvider):
return searches
def _api_call(self, params=None, results_per_page=300, offset=0):
parsed_json = {}
def _api_call(self, params=None, results_per_page=1000, offset=0):
response = {}
json_rpc = json.dumps({
"jsonrpc": "2.0",
"id": ''.join(random.sample('abcdefghijklmnopqrstuvwxyz0123456789', 8)),
"method": "getTorrents",
"params": [str(self.api_key), params or {}, str(results_per_page), str(offset)]
api = xmlrpc.client.Server(self.urls['api'] + '/')
parsed_json = api.getTorrents(self.api_key, params or {}, int(results_per_page), int(offset))
except xmlrpc.client.ProtocolError as e:
if e.errmsg == 'Call Limit Exceeded':"You have exceeded the limit of 150 calls per hour.")
elif e.errmsg == 'Invalid API Key':"Incorrect authentication credentials.")
else:"JSON-RPC protocol error while accessing provider. Error: {}".format(e))
except (socket.error, socket.timeout, ValueError) as e:
response =['api'], data=json_rpc, headers={'Content-Type': 'application/json-rpc'}).json()
if 'error' in response:
error = response["error"]
message = error["message"]
code = error["code"]"Error Code: {} :: Error Message: {}".format(code, message))
except Exception as e:"Error while accessing provider. Error: {}".format(e))
return parsed_json
return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment