Browse Source

Use existing Trakt auth settings and other cleanup

pull/1548/merge
Ruud 12 years ago
parent
commit
b82319cb54
  1. 6
      couchpotato/core/notifications/base.py
  2. 21
      couchpotato/core/notifications/trakt/__init__.py
  3. 23
      couchpotato/core/notifications/trakt/main.py

6
couchpotato/core/notifications/base.py

@ -2,13 +2,15 @@ from couchpotato.api import addApiView
from couchpotato.core.event import addEvent from couchpotato.core.event import addEvent
from couchpotato.core.helpers.request import jsonified from couchpotato.core.helpers.request import jsonified
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.providers.base import Provider
from couchpotato.environment import Env from couchpotato.environment import Env
log = CPLog(__name__) log = CPLog(__name__)
class Notification(Plugin): class Notification(Provider):
type = 'notification'
default_title = Env.get('appname') default_title = Env.get('appname')
test_message = 'ZOMG Lazors Pewpewpew!' test_message = 'ZOMG Lazors Pewpewpew!'

21
couchpotato/core/notifications/trakt/__init__.py

@ -8,9 +8,10 @@ config = [{
'groups': [ 'groups': [
{ {
'tab': 'notifications', 'tab': 'notifications',
'name': 'trakt_notification', 'list': 'notification_providers',
'name': 'trakt',
'label': 'Trakt', 'label': 'Trakt',
'description': 'add movies to your collection once downloaded', 'description': 'add movies to your collection once downloaded. Fill in your username and password in the <a href="../automation/">Automation Trakt settings</a>',
'options': [ 'options': [
{ {
'name': 'notification_enabled', 'name': 'notification_enabled',
@ -23,21 +24,7 @@ config = [{
'default': False, 'default': False,
'type': 'bool', 'type': 'bool',
}, },
{
'name': 'automation_api_key',
'label': 'Apikey',
},
{
'name': 'automation_username',
'label': 'Username',
},
{
'name': 'automation_password',
'label': 'Password',
'type': 'password',
'description': 'Required even if your account is unprotected.',
},
], ],
} }
], ],
}] }]

23
couchpotato/core/notifications/trakt/main.py

@ -1,14 +1,12 @@
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification from couchpotato.core.notifications.base import Notification
import json
import urllib2
log = CPLog(__name__) log = CPLog(__name__)
class Trakt(Notification): class Trakt(Notification):
urls = { urls = {
'base': 'http://api.trakt.tv/', 'base': 'http://api.trakt.tv/%s',
'library': 'movie/library/%s', 'library': 'movie/library/%s',
'unwatchlist': 'movie/unwatchlist/%s', 'unwatchlist': 'movie/unwatchlist/%s',
} }
@ -17,17 +15,17 @@ class Trakt(Notification):
def notify(self, message = '', data = {}, listener = None): def notify(self, message = '', data = {}, listener = None):
if self.isDisabled(): return if self.isDisabled(): return
if not data: return
post_data = { post_data = {
'username': self.conf('automation_username'), 'username': self.conf('automation_username'),
'password' : self.conf('automation_password'), 'password' : self.conf('automation_password'),
'movies': [ { 'movies': [{
'imdb_id': data['library']['identifier'], 'imdb_id': data['library']['identifier'],
'title': data['library']['titles'][0]['title'], 'title': data['library']['titles'][0]['title'],
'year': data['library']['year'] 'year': data['library']['year']
} ] }] if data else []
} }
result = False
result = self.call((self.urls['library'] % self.conf('automation_api_key')), post_data) result = self.call((self.urls['library'] % self.conf('automation_api_key')), post_data)
if self.conf('remove_watchlist_enabled'): if self.conf('remove_watchlist_enabled'):
result = result and self.call((self.urls['unwatchlist'] % self.conf('automation_api_key')), post_data) result = result and self.call((self.urls['unwatchlist'] % self.conf('automation_api_key')), post_data)
@ -35,14 +33,15 @@ class Trakt(Notification):
return result return result
def call(self, method_url, post_data): def call(self, method_url, post_data):
log.info('opening url: ' + self.urls['base'] + method_url + ', post: ' + str(post_data))
try: try:
response = urllib2.urlopen(self.urls['base'] + method_url, json.dumps(post_data)) response = self.getJsonData(self.urls['base'] % method_url, params = post_data, cache_timeout = 1)
if response: if response:
if json.load(response).get('status') == "success": if response.get('status') == "success":
log.info('Successfully called Trakt') log.info('Successfully called Trakt')
return True return True
except: except:
pass pass
log.error('Failed to call trakt, check your login.') log.error('Failed to call trakt, check your login.')
return False return False

Loading…
Cancel
Save