Browse Source

Trakt notifications fix

pull/4942/head
Ruud 10 years ago
parent
commit
2f29ba2795
  1. 33
      couchpotato/core/media/movie/providers/automation/trakt/main.py
  2. 47
      couchpotato/core/notifications/trakt.py

33
couchpotato/core/media/movie/providers/automation/trakt/main.py

@ -1,19 +1,37 @@
import json
from couchpotato import Env
from couchpotato.api import addApiView
from couchpotato.core.helpers.variable import cleanHost
from couchpotato.core.logger import CPLog
from couchpotato.core.media._base.providers.base import Provider
from couchpotato.core.media.movie.providers.automation.base import Automation
log = CPLog(__name__)
class Trakt(Automation):
class TraktBase(Provider):
client_id = '8a54ed7b5e1b56d874642770ad2e8b73e2d09d6e993c3a92b1e89690bb1c9014'
api_url = 'https://api-v2launch.trakt.tv/'
def call(self, method_url, post_data = None):
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer %s' % self.conf('automation_oauth_token'),
'trakt-api-version': 2,
'trakt-api-key': self.client_id,
}
post_data = json.dumps(post_data)
data = self.getJsonData(self.api_url + method_url, data = post_data or {}, headers = headers)
return data if data else []
class Trakt(Automation, TraktBase):
urls = {
'base': 'https://api-v2launch.trakt.tv/',
'watchlist': 'sync/watchlist/movies/',
'oauth': 'https://api.couchpota.to/authorize/trakt/',
}
@ -54,14 +72,3 @@ class Trakt(Automation):
log.debug('oauth_token is: %s', oauth_token)
self.conf('automation_oauth_token', value = oauth_token)
return 'redirect', Env.get('web_base') + 'settings/automation/'
def call(self, method_url):
headers = {
'Authorization': 'Bearer %s' % self.conf('automation_oauth_token'),
'trakt-api-version': 2,
'trakt-api-key': self.client_id,
}
data = self.getJsonData(self.urls['base'] + method_url, headers = headers)
return data if data else []

47
couchpotato/core/notifications/trakt.py

@ -1,5 +1,6 @@
from couchpotato.core.helpers.variable import getTitle, getIdentifier
from couchpotato.core.logger import CPLog
from couchpotato.core.media.movie.providers.automation.trakt.main import TraktBase
from couchpotato.core.notifications.base import Notification
log = CPLog(__name__)
@ -7,13 +8,12 @@ log = CPLog(__name__)
autoload = 'Trakt'
class Trakt(Notification):
class Trakt(Notification, TraktBase):
urls = {
'base': 'http://api.trakt.tv/%s',
'library': 'movie/library/%s',
'unwatchlist': 'movie/unwatchlist/%s',
'test': 'account/test/%s',
'library': 'sync/collection',
'unwatchlist': 'sync/watchlist/remove',
'test': 'sync/last_activities',
}
listen_to = ['movie.snatched']
@ -23,49 +23,22 @@ class Trakt(Notification):
if not data: data = {}
if listener == 'test':
post_data = {
'username': self.conf('automation_username'),
'password': self.conf('automation_password'),
}
result = self.call((self.urls['test'] % self.conf('automation_api_key')), post_data)
result = self.call((self.urls['test']))
return result
else:
post_data = {
'username': self.conf('automation_username'),
'password': self.conf('automation_password'),
'movies': [{
'imdb_id': getIdentifier(data),
'title': getTitle(data),
'year': data['info']['year']
}] if data else []
'movies': [{'ids': {'imdb': getIdentifier(data)}}] if data else []
}
result = self.call((self.urls['library'] % self.conf('automation_api_key')), post_data)
result = self.call((self.urls['library']), post_data)
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']), post_data)
return result
def call(self, method_url, post_data):
try:
response = self.getJsonData(self.urls['base'] % method_url, data = post_data, cache_timeout = 1)
if response:
if response.get('status') == "success":
log.info('Successfully called Trakt')
return True
except:
pass
log.error('Failed to call trakt, check your login.')
return False
config = [{
'name': 'trakt',
@ -75,7 +48,7 @@ config = [{
'list': 'notification_providers',
'name': 'trakt',
'label': 'Trakt',
'description': 'add movies to your collection once downloaded. Fill in your username and password in the <a href="../automation/">Automation Trakt settings</a>',
'description': 'add movies to your collection once downloaded. Connect your account in <a href="../automation/">Automation Trakt settings</a>',
'options': [
{
'name': 'notification_enabled',

Loading…
Cancel
Save