From f3887aaa4406d04f167a7522015818a8e3069263 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 25 Jan 2012 14:35:16 +0100 Subject: [PATCH] Automation base Working IMDB Watchlists --- .../core/plugins/automation/__init__.py | 6 ++++ couchpotato/core/plugins/automation/main.py | 20 +++++++++++ .../core/providers/automation/__init__.py | 0 couchpotato/core/providers/automation/base.py | 34 ++++++++++++++++++ .../core/providers/automation/cp/__init__.py | 26 ++++++++++++++ .../core/providers/automation/cp/main.py | 14 ++++++++ .../providers/automation/imdb/__init__.py | 26 ++++++++++++++ .../core/providers/automation/imdb/main.py | 36 +++++++++++++++++++ .../automation/kinepolis/__init__.py | 26 ++++++++++++++ .../providers/automation/kinepolis/main.py | 14 ++++++++ .../providers/automation/trakt/__init__.py | 23 ++++++++++++ .../core/providers/automation/trakt/main.py | 14 ++++++++ 12 files changed, 239 insertions(+) create mode 100644 couchpotato/core/plugins/automation/__init__.py create mode 100644 couchpotato/core/plugins/automation/main.py create mode 100644 couchpotato/core/providers/automation/__init__.py create mode 100644 couchpotato/core/providers/automation/base.py create mode 100644 couchpotato/core/providers/automation/cp/__init__.py create mode 100644 couchpotato/core/providers/automation/cp/main.py create mode 100644 couchpotato/core/providers/automation/imdb/__init__.py create mode 100644 couchpotato/core/providers/automation/imdb/main.py create mode 100644 couchpotato/core/providers/automation/kinepolis/__init__.py create mode 100644 couchpotato/core/providers/automation/kinepolis/main.py create mode 100644 couchpotato/core/providers/automation/trakt/__init__.py create mode 100644 couchpotato/core/providers/automation/trakt/main.py diff --git a/couchpotato/core/plugins/automation/__init__.py b/couchpotato/core/plugins/automation/__init__.py new file mode 100644 index 00000000..70daf05c --- /dev/null +++ b/couchpotato/core/plugins/automation/__init__.py @@ -0,0 +1,6 @@ +from .main import Automation + +def start(): + return Automation() + +config = [] diff --git a/couchpotato/core/plugins/automation/main.py b/couchpotato/core/plugins/automation/main.py new file mode 100644 index 00000000..64a4c51d --- /dev/null +++ b/couchpotato/core/plugins/automation/main.py @@ -0,0 +1,20 @@ +from couchpotato.core.event import addEvent, fireEvent +from couchpotato.core.logger import CPLog +from couchpotato.core.plugins.base import Plugin +from couchpotato.environment import Env + +log = CPLog(__name__) + + +class Automation(Plugin): + + def __init__(self): + + if not Env.setting('development'): + addEvent('app.load', self.addMovies) + + def addMovies(self): + + movies = fireEvent('automation.get_movies', merge = True) + for imdb_id in movies: + fireEvent('movie.add', params = {'identifier': imdb_id}, force_readd = False) diff --git a/couchpotato/core/providers/automation/__init__.py b/couchpotato/core/providers/automation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py new file mode 100644 index 00000000..d3a3541e --- /dev/null +++ b/couchpotato/core/providers/automation/base.py @@ -0,0 +1,34 @@ +from couchpotato.core.event import addEvent +from couchpotato.core.logger import CPLog +from couchpotato.core.plugins.base import Plugin +import time + +log = CPLog(__name__) + + +class Automation(Plugin): + + enabled_option = 'automation_enabled' + + interval = 86400 + last_checked = 0 + + def __init__(self): + addEvent('automation.get_movies', self._getMovies) + + def _getMovies(self): + + if not self.canCheck(): + log.debug('Just checked, skipping %s' % self.getName()) + return [] + + self.last_checked = time.time() + + return self.getIMDBids() + + + def getIMDBids(self): + return [] + + def canCheck(self): + return time.time() > self.last_checked + self.interval diff --git a/couchpotato/core/providers/automation/cp/__init__.py b/couchpotato/core/providers/automation/cp/__init__.py new file mode 100644 index 00000000..5493dff0 --- /dev/null +++ b/couchpotato/core/providers/automation/cp/__init__.py @@ -0,0 +1,26 @@ +from .main import CP + +def start(): + return CP() + +config = [{ + 'name': 'cp', + 'groups': [ + { + 'tab': 'automation', + 'name': 'couchpotato_automation', + 'label': 'CouchPotato', + 'description': 'Enable automatic movie adding from CouchPotato', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + { + 'name': 'automation_urls', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/cp/main.py b/couchpotato/core/providers/automation/cp/main.py new file mode 100644 index 00000000..24d69092 --- /dev/null +++ b/couchpotato/core/providers/automation/cp/main.py @@ -0,0 +1,14 @@ +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation + +log = CPLog(__name__) + + +class CP(Automation): + + def getMovies(self): + + if self.isDisabled(): + return + + return [] diff --git a/couchpotato/core/providers/automation/imdb/__init__.py b/couchpotato/core/providers/automation/imdb/__init__.py new file mode 100644 index 00000000..f6f75a35 --- /dev/null +++ b/couchpotato/core/providers/automation/imdb/__init__.py @@ -0,0 +1,26 @@ +from .main import IMDB + +def start(): + return IMDB() + +config = [{ + 'name': 'imdb', + 'groups': [ + { + 'tab': 'automation', + 'name': 'imdb_automation', + 'label': 'IMDB', + 'description': 'Enable automatic movie adding of IMDB watchlists', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + { + 'name': 'automation_urls', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/imdb/main.py b/couchpotato/core/providers/automation/imdb/main.py new file mode 100644 index 00000000..0b9bf7b8 --- /dev/null +++ b/couchpotato/core/providers/automation/imdb/main.py @@ -0,0 +1,36 @@ +from couchpotato.core.helpers.variable import md5, getImdb +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation +import StringIO +import csv +import traceback + +log = CPLog(__name__) + + +class IMDB(Automation): + + interval = 1800 + + def getIMDBids(self): + + if self.isDisabled(): + return + + movies = [] + + for csv_url in self.conf('automation_urls').split(','): + try: + cache_key = 'imdb_csv.%s' % md5(csv_url) + csv_data = self.getCache(cache_key, csv_url) + csv_reader = csv.reader(StringIO.StringIO(csv_data)) + csv_reader.next() + + for row in csv_reader: + imdb = getImdb(str(row)) + if imdb: + movies.append(imdb) + except: + log.error('Failed loading IMDB watchlist: %s %s' % (csv_url, traceback.format_exc())) + + return movies diff --git a/couchpotato/core/providers/automation/kinepolis/__init__.py b/couchpotato/core/providers/automation/kinepolis/__init__.py new file mode 100644 index 00000000..86bde021 --- /dev/null +++ b/couchpotato/core/providers/automation/kinepolis/__init__.py @@ -0,0 +1,26 @@ +from .main import Kinepolis + +def start(): + return Kinepolis() + +config = [{ + 'name': 'kinepolis', + 'groups': [ + { + 'tab': 'automation', + 'name': 'kinepolis_automation', + 'label': 'Kinepolis', + 'description': 'Enable automatic movie adding from Kinepolis', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + { + 'name': 'automation_urls', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/kinepolis/main.py b/couchpotato/core/providers/automation/kinepolis/main.py new file mode 100644 index 00000000..b88bb285 --- /dev/null +++ b/couchpotato/core/providers/automation/kinepolis/main.py @@ -0,0 +1,14 @@ +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation + +log = CPLog(__name__) + + +class Kinepolis(Automation): + + def getMovies(self): + + if self.isDisabled(): + return + + return [] diff --git a/couchpotato/core/providers/automation/trakt/__init__.py b/couchpotato/core/providers/automation/trakt/__init__.py new file mode 100644 index 00000000..50c20d77 --- /dev/null +++ b/couchpotato/core/providers/automation/trakt/__init__.py @@ -0,0 +1,23 @@ +from .main import Trakt + +def start(): + return Trakt() + +config = [{ + 'name': 'trakt', + 'groups': [ + { + 'tab': 'automation', + 'name': 'trakt_automation', + 'label': 'Trakt', + 'description': 'Enable automatic movie adding from Trakt', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/trakt/main.py b/couchpotato/core/providers/automation/trakt/main.py new file mode 100644 index 00000000..c8fded9e --- /dev/null +++ b/couchpotato/core/providers/automation/trakt/main.py @@ -0,0 +1,14 @@ +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation + +log = CPLog(__name__) + + +class Trakt(Automation): + + def getMovies(self): + + if self.isDisabled(): + return + + return []