Trakt.tv add password for protected api. fix #147
This commit is contained in:
@@ -59,6 +59,9 @@ def flattenList(l):
|
||||
def md5(text):
|
||||
return hashlib.md5(text).hexdigest()
|
||||
|
||||
def sha1(text):
|
||||
return hashlib.sha1(text).hexdigest()
|
||||
|
||||
def getExt(filename):
|
||||
return os.path.splitext(filename)[1][1:]
|
||||
|
||||
|
||||
@@ -25,6 +25,12 @@ config = [{
|
||||
'name': 'automation_username',
|
||||
'label': 'Username',
|
||||
},
|
||||
{
|
||||
'name': 'automation_password',
|
||||
'label': 'Password',
|
||||
'type': 'password',
|
||||
'description': 'When you have "Protect my data" checked <a href="http://trakt.tv/settings/account">on trakt</a>.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from couchpotato.core.helpers.variable import md5
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.variable import md5, sha1
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.providers.automation.base import Automation
|
||||
import base64
|
||||
import json
|
||||
|
||||
log = CPLog(__name__)
|
||||
@@ -13,6 +15,14 @@ class Trakt(Automation):
|
||||
'watchlist': 'user/watchlist/movies.json/%s/',
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
super(Trakt, self).__init__()
|
||||
|
||||
addEvent('setting.save.trakt.automation_password', self.sha1Password)
|
||||
|
||||
def sha1Password(self, value):
|
||||
return sha1(value) if value else ''
|
||||
|
||||
def getIMDBids(self):
|
||||
|
||||
if self.isDisabled():
|
||||
@@ -31,6 +41,13 @@ class Trakt(Automation):
|
||||
|
||||
def call(self, method_url):
|
||||
|
||||
if self.conf('automation_password'):
|
||||
headers = {
|
||||
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('automation_username'), self.conf('automation_password')))[:-1]
|
||||
}
|
||||
else:
|
||||
headers = {}
|
||||
|
||||
cache_key = 'trakt.%s' % md5(method_url)
|
||||
json_string = self.getCache(cache_key, self.urls['base'] + method_url)
|
||||
json_string = self.getCache(cache_key, self.urls['base'] + method_url, headers = headers)
|
||||
return json.loads(json_string)
|
||||
|
||||
Reference in New Issue
Block a user