diff --git a/couchpotato/core/plugins/automation/__init__.py b/couchpotato/core/plugins/automation/__init__.py index 70daf05c..8287cf0d 100644 --- a/couchpotato/core/plugins/automation/__init__.py +++ b/couchpotato/core/plugins/automation/__init__.py @@ -3,4 +3,34 @@ from .main import Automation def start(): return Automation() -config = [] +config = [{ + 'name': 'automation', + 'groups': [ + { + 'tab': 'automation', + 'name': 'automation', + 'label': 'Automation', + 'description': 'Enable automatic movie adding', + 'options': [ + { + 'name': 'year', + 'default': 2011, + 'Label': 'Minimal year', + 'type': 'int', + }, + { + 'name': 'votes', + 'default': 1000, + 'Label': 'Minimal votes', + 'type': 'int', + }, + { + 'name': 'rating', + 'default': 6.0, + 'Label': 'Minimal rating', + 'type': 'float', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py index d3a3541e..f2e94cec 100644 --- a/couchpotato/core/providers/automation/base.py +++ b/couchpotato/core/providers/automation/base.py @@ -1,6 +1,7 @@ -from couchpotato.core.event import addEvent +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 import time log = CPLog(__name__) @@ -26,6 +27,29 @@ class Automation(Plugin): return self.getIMDBids() + def search(self, name, year = None): + result = fireEvent('movie.search', q = '%s %s' % (name, year if year else ''), limit = 1, merge = True) + + if len(result) > 0: + return result[0].get('imdb') + else: + return None + + def isMinimal(self, identifier): + + movie = fireEvent('movie.info', identifier = identifier, merge = True) + + for minimal_type in ['year', 'rating', 'votes']: + type_value = movie.get(minimal_type, 0) + type_min = self.getMinimal(minimal_type) + if type_value < type_min: + log.info('%s to low for %s, need %s has %s' % (minimal_type, identifier, type_min, type_value)) + return False + + return True + + def getMinimal(self, min_type): + return Env.setting(min_type, 'automation') def getIMDBids(self): return []