From 30b7eca945c835f582cb45bb2dceba890242a3d9 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 25 Jan 2012 16:48:02 +0100 Subject: [PATCH] Trakt watchlist automation --- .../core/providers/automation/trakt/__init__.py | 10 ++++++++- .../core/providers/automation/trakt/main.py | 26 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/providers/automation/trakt/__init__.py b/couchpotato/core/providers/automation/trakt/__init__.py index 50c20d7..f1c30df 100644 --- a/couchpotato/core/providers/automation/trakt/__init__.py +++ b/couchpotato/core/providers/automation/trakt/__init__.py @@ -10,13 +10,21 @@ config = [{ 'tab': 'automation', 'name': 'trakt_automation', 'label': 'Trakt', - 'description': 'Enable automatic movie adding from Trakt', + 'description': 'from watchlist', 'options': [ { 'name': 'automation_enabled', 'default': False, 'type': 'enabler', }, + { + 'name': 'automation_api_key', + 'label': 'Apikey', + }, + { + 'name': 'automation_username', + 'label': 'Username', + }, ], }, ], diff --git a/couchpotato/core/providers/automation/trakt/main.py b/couchpotato/core/providers/automation/trakt/main.py index c8fded9..06a4872 100644 --- a/couchpotato/core/providers/automation/trakt/main.py +++ b/couchpotato/core/providers/automation/trakt/main.py @@ -1,14 +1,36 @@ +from couchpotato.core.helpers.variable import md5 from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation +import json log = CPLog(__name__) class Trakt(Automation): - def getMovies(self): + urls = { + 'base': 'http://api.trakt.tv/', + 'watchlist': 'user/watchlist/movies.json/%s/', + } + + def getIMDBids(self): if self.isDisabled(): return - return [] + movies = [] + for movie in self.getWatchlist(): + movies.append(movie.get('imdb_id')) + + return movies + + def getWatchlist(self): + method = (self.urls['watchlist'] % self.conf('automation_api_key')) + self.conf('automation_username') + return self.call(method) + + + def call(self, method_url): + + cache_key = 'trakt.%s' % md5(method_url) + json_string = self.getCache(cache_key, self.urls['base'] + method_url) + return json.loads(json_string)