1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-11-17 23:05:11 -05:00
SickRage/lib/trakt/__init__.py
echel0n 0d9fbc1ad7 Welcome to our SickBeard-TVRage Edition ...
This version of SickBeard uses both TVDB and TVRage to search and gather it's series data from allowing you to now have access to and download shows that you couldn't before because of being locked into only what TheTVDB had to offer.

Also this edition is based off the code we used in our XEM editon so it does come with scene numbering support as well as all the other features our XEM edition has to offer.

Please before using this with your existing database (sickbeard.db) please make a backup copy of it and delete any other database files such as cache.db and failed.db if present, we HIGHLY recommend starting out with no database files at all to make this a fresh start but the choice is at your own risk!

Enjoy!
2014-03-09 22:39:12 -07:00

59 lines
1.7 KiB
Python

import urllib2
from hashlib import sha1
try:
import json
except ImportError:
from lib import simplejson as json
def TraktCall(method, api, username, password, data = {}):
"""
A generic method for communicating with trakt. Uses the method and data provided along
with the auth info to send the command.
method: The URL to use at trakt, relative, no leading slash.
api: The API string to provide to trakt
username: The username to use when logging in
password: The unencrypted password to use when logging in
Returns: A boolean representing success
"""
#logger.log("trakt: Call method " + method, logger.DEBUG)
# if the API isn't given then it failed
if not api:
return None
# if the username isn't given then it failed
if not username:
return None
password = sha1(password).hexdigest()
# replace the API string with what we found
method = method.replace("%API%", api)
data["username"] = username
data["password"] = password
# take the URL params and make a json object out of them
encoded_data = json.dumps(data);
# request the URL from trakt and parse the result as json
try:
#logger.log("trakt: Calling method http://api.trakt.tv/" + method + ", with data" + encoded_data, logger.DEBUG)
stream = urllib2.urlopen("http://api.trakt.tv/" + method, encoded_data)
resp = stream.read()
resp = json.loads(resp)
if ("error" in resp):
raise Exception(resp["error"])
except (IOError):
#logger.log("trakt: Failed calling method", logger.ERROR)
return None
#logger.log("trakt: Failed calling method", logger.ERROR)
return resp