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 import Env
from couchpotato.api import addApiView from couchpotato.api import addApiView
from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.helpers.variable import cleanHost
from couchpotato.core.logger import CPLog 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 from couchpotato.core.media.movie.providers.automation.base import Automation
log = CPLog(__name__) log = CPLog(__name__)
class Trakt(Automation): class TraktBase(Provider):
client_id = '8a54ed7b5e1b56d874642770ad2e8b73e2d09d6e993c3a92b1e89690bb1c9014' 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 = { urls = {
'base': 'https://api-v2launch.trakt.tv/',
'watchlist': 'sync/watchlist/movies/', 'watchlist': 'sync/watchlist/movies/',
'oauth': 'https://api.couchpota.to/authorize/trakt/', 'oauth': 'https://api.couchpota.to/authorize/trakt/',
} }
@ -54,14 +72,3 @@ class Trakt(Automation):
log.debug('oauth_token is: %s', oauth_token) log.debug('oauth_token is: %s', oauth_token)
self.conf('automation_oauth_token', value = oauth_token) self.conf('automation_oauth_token', value = oauth_token)
return 'redirect', Env.get('web_base') + 'settings/automation/' 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.helpers.variable import getTitle, getIdentifier
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.media.movie.providers.automation.trakt.main import TraktBase
from couchpotato.core.notifications.base import Notification from couchpotato.core.notifications.base import Notification
log = CPLog(__name__) log = CPLog(__name__)
@ -7,13 +8,12 @@ log = CPLog(__name__)
autoload = 'Trakt' autoload = 'Trakt'
class Trakt(Notification): class Trakt(Notification, TraktBase):
urls = { urls = {
'base': 'http://api.trakt.tv/%s', 'library': 'sync/collection',
'library': 'movie/library/%s', 'unwatchlist': 'sync/watchlist/remove',
'unwatchlist': 'movie/unwatchlist/%s', 'test': 'sync/last_activities',
'test': 'account/test/%s',
} }
listen_to = ['movie.snatched'] listen_to = ['movie.snatched']
@ -23,49 +23,22 @@ class Trakt(Notification):
if not data: data = {} if not data: data = {}
if listener == 'test': if listener == 'test':
result = self.call((self.urls['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)
return result return result
else: else:
post_data = { post_data = {
'username': self.conf('automation_username'), 'movies': [{'ids': {'imdb': getIdentifier(data)}}] if data else []
'password': self.conf('automation_password'),
'movies': [{
'imdb_id': getIdentifier(data),
'title': getTitle(data),
'year': data['info']['year']
}] 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'): 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 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 = [{ config = [{
'name': 'trakt', 'name': 'trakt',
@ -75,7 +48,7 @@ config = [{
'list': 'notification_providers', 'list': 'notification_providers',
'name': 'trakt', 'name': 'trakt',
'label': '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': [ 'options': [
{ {
'name': 'notification_enabled', 'name': 'notification_enabled',

Loading…
Cancel
Save