From 2cb6ddfe9a89757915c5722221e090d2b43cc12a Mon Sep 17 00:00:00 2001 From: mano3m <-> Date: Sat, 16 Mar 2013 14:29:33 +0100 Subject: [PATCH] Add automation genre checking With this commit you can set requirements to the genres of movie automation downloading. Required sets e.g. Action&Crime and/or ignored sets e.g. Romance&Comedy. --- .../core/plugins/automation/__init__.py | 14 ++++++++++++ couchpotato/core/providers/automation/base.py | 22 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/plugins/automation/__init__.py b/couchpotato/core/plugins/automation/__init__.py index b7b1ab28..baff29c4 100644 --- a/couchpotato/core/plugins/automation/__init__.py +++ b/couchpotato/core/plugins/automation/__init__.py @@ -36,6 +36,20 @@ config = [{ 'unit': 'hours', 'description': 'hours', }, + { + 'name': 'required_genres', + 'label': 'Required Genres', + 'default': '', + 'placeholder': 'Example: Action, Crime & Drama', + 'description': 'Ignore movies that don\'t contain at least one set of genres. Sets are separated by "," and each word within a set must be separated with "&"' + }, + { + 'name': 'ignored_genres', + 'label': 'Ignored Genres', + 'default': '', + 'placeholder': 'Example: Horror, Comedy & Drama & Romance', + 'description': 'Ignore movies that contain at least one set of genres. Sets are separated by "," and each word within a set must be separated with "&"' + }, ], }, ], diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py index 8d08f913..6aef58a1 100644 --- a/couchpotato/core/providers/automation/base.py +++ b/couchpotato/core/providers/automation/base.py @@ -2,6 +2,7 @@ from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.logger import CPLog from couchpotato.core.providers.base import Provider from couchpotato.environment import Env +from couchpotato.core.helpers.variable import splitString import time log = CPLog(__name__) @@ -59,7 +60,26 @@ class Automation(Provider): type_value = movie.get(minimal_type, 0) type_min = self.getMinimal(minimal_type) if type_value < type_min: - log.info('%s too low for %s, need %s has %s', (minimal_type, movie['imdb'], type_min, type_value)) + log.info('%s too low for %s, need %s has %s', (minimal_type, movie['original_title'], type_min, type_value)) + return False + + movie_genres = [genre.lower() for genre in movie['genres']] + required_genres = splitString(self.getMinimal('required_genres').lower()) + ignored_genres = splitString(self.getMinimal('ignored_genres').lower()) + + req_match = 0 + for req_set in required_genres: + req = splitString(req_set, '&') + req_match += len(list(set(movie_genres) & set(req))) == len(req) + + if self.getMinimal('required_genres') and req_match == 0: + log.info2("Required genre(s) missing for %s" % movie['original_title']) + return False + + for ign_set in ignored_genres: + ign = splitString(ign_set, '&') + if len(list(set(movie_genres) & set(ign))) == len(ign): + log.info2("%s has blacklisted genre(s): %s" % (movie['original_title'], ign)) return False return True