From b4bccc9be218469c8fb787e574eed3c5c577f8d5 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 28 Sep 2013 23:41:15 +0200 Subject: [PATCH] Flixter automation support Thanks @mikedm139 --- .../providers/automation/flixster/__init__.py | 34 +++++++++++++ .../providers/automation/flixster/main.py | 48 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 couchpotato/core/providers/automation/flixster/__init__.py create mode 100644 couchpotato/core/providers/automation/flixster/main.py diff --git a/couchpotato/core/providers/automation/flixster/__init__.py b/couchpotato/core/providers/automation/flixster/__init__.py new file mode 100644 index 00000000..1c6c4590 --- /dev/null +++ b/couchpotato/core/providers/automation/flixster/__init__.py @@ -0,0 +1,34 @@ +from .main import Flixster + +def start(): + return Flixster() + +config = [{ + 'name': 'flixster', + 'groups': [ + { + 'tab': 'automation', + 'list': 'watchlist_providers', + 'name': 'flixster_automation', + 'label': 'Flixster', + 'description': 'Import movies from any public Flixster watchlist', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + { + 'name': 'automation_ids_use', + 'label': 'Use', + }, + { + 'name': 'automation_ids', + 'label': 'User ID', + 'type': 'combined', + 'combine': ['automation_ids_use', 'automation_ids'], + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/flixster/main.py b/couchpotato/core/providers/automation/flixster/main.py new file mode 100644 index 00000000..46dcfba3 --- /dev/null +++ b/couchpotato/core/providers/automation/flixster/main.py @@ -0,0 +1,48 @@ +from couchpotato.core.helpers.variable import tryInt, splitString +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation +import json + +log = CPLog(__name__) + + +class Flixster(Automation): + + url = 'http://www.flixster.com/api/users/%s/movies/ratings?scoreTypes=wts' + + interval = 60 + + def getIMDBids(self): + + ids = splitString(self.conf('automation_ids')) + + if len(ids) == 0: + return [] + + movies = [] + + for movie in self.getWatchlist(): + imdb_id = self.search(movie.get('title'), movie.get('year'), imdb_only = True) + movies.append(imdb_id) + + return movies + + def getWatchlist(self): + + enablers = [tryInt(x) for x in splitString(self.conf('automation_ids_use'))] + ids = splitString(self.conf('automation_ids')) + + index = -1 + movies = [] + for user_id in ids: + + index += 1 + if not enablers[index]: + continue + + data = json.loads(self.getHTMLData(self.url % user_id)) + + for movie in data: + movies.append({'title': movie['movie']['title'], 'year': movie['movie']['year'] }) + + return movies