From ee21610bc3aba941d8c2c83911a75417176f379c Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 16 Jul 2012 01:11:52 +0200 Subject: [PATCH] Cleanup automation providers --- couchpotato/core/providers/automation/base.py | 19 +++++-------- .../core/providers/automation/bluray/main.py | 28 ++++--------------- .../providers/automation/kinepolis/main.py | 11 +++----- .../automation/movies_io/__init__.py | 2 +- 4 files changed, 18 insertions(+), 42 deletions(-) diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py index df04b13b..d3af2632 100644 --- a/couchpotato/core/providers/automation/base.py +++ b/couchpotato/core/providers/automation/base.py @@ -27,36 +27,31 @@ class Automation(Plugin): return self.getIMDBids() - def search(self, name, year = None): + def search(self, name, year = None, imdb_only = False): 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') + return result[0].get('imdb') if imdb_only else result[0] else: return None def isMinimalMovie(self, movie): + if not movie.get('rating'): + return False + if movie['rating'] and movie['rating'].get('imdb'): movie['votes'] = movie['rating']['imdb'][1] movie['rating'] = movie['rating']['imdb'][0] - identifier = movie['imdb'] + 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 too low for %s, need %s has %s', (minimal_type, identifier, type_min, type_value)) + log.info('%s too low for %s, need %s has %s', (minimal_type, movie['imdb'], type_min, type_value)) return False return True - def getIMDBFromTitle(self, name, year = None): - result = fireEvent('movie.search', q = '%s %s' % (name, year), limit = 1, merge = True) - - if len(result) > 0: - return result[0] - else: - return None - def getMinimal(self, min_type): return Env.setting(min_type, 'automation') diff --git a/couchpotato/core/providers/automation/bluray/main.py b/couchpotato/core/providers/automation/bluray/main.py index c6d82ebf..20f733b7 100644 --- a/couchpotato/core/providers/automation/bluray/main.py +++ b/couchpotato/core/providers/automation/bluray/main.py @@ -1,5 +1,5 @@ from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import md5 +from couchpotato.core.helpers.variable import md5, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation from couchpotato.environment import Env @@ -19,8 +19,6 @@ class Bluray(Automation, RSS): return movies = [] - RSSMovie = {'name': 'placeholder', 'year' : 'placeholder'} - RSSMovies = [] cache_key = 'bluray.%s' % md5(self.rss_url) rss_data = self.getCache(cache_key, self.rss_url) @@ -30,30 +28,16 @@ class Bluray(Automation, RSS): rss_movies = self.getElements(data, 'channel/item') for movie in rss_movies: - RSSMovie['name'] = self.getTextElement(movie, "title").lower().split("blu-ray")[0].strip("(").rstrip() - RSSMovie['year'] = self.getTextElement(movie, "description").split("|")[1].strip("(").strip() + name = self.getTextElement(movie, "title").lower().split("blu-ray")[0].strip("(").rstrip() + year = self.getTextElement(movie, "description").split("|")[1].strip("(").strip() - if not RSSMovie['name'].find("/") == -1: # make sure it is not a double movie release + if not name.find("/") == -1: # make sure it is not a double movie release continue - if int(RSSMovie['year']) < Env.setting('year', 'automation'): #do year filtering + if tryInt(year) < self.getMinimal('year'): continue - for test in RSSMovies: - if test.values() == RSSMovie.values(): # make sure we did not already include it... - break - else: - log.info('Release found: %s.' % RSSMovie) - RSSMovies.append(RSSMovie.copy()) - - if not RSSMovies: - log.info('No movies found.') - return - - log.debug("Applying IMDB filter to found movies...") - - for RSSMovie in RSSMovies: - imdb = self.getIMDBFromTitle(RSSMovie['name'] + ' ' + RSSMovie['year']) + imdb = self.search(name, year) if imdb: if self.isMinimalMovie(imdb): diff --git a/couchpotato/core/providers/automation/kinepolis/main.py b/couchpotato/core/providers/automation/kinepolis/main.py index 031bb444..f6633af7 100644 --- a/couchpotato/core/providers/automation/kinepolis/main.py +++ b/couchpotato/core/providers/automation/kinepolis/main.py @@ -19,7 +19,6 @@ class Kinepolis(Automation, RSS): return movies = [] - RSSMovie = {'name': 'placeholder', 'year' : 'placeholder'} cache_key = 'kinepolis.%s' % md5(self.rss_url) rss_data = self.getCache(cache_key, self.rss_url) @@ -29,14 +28,12 @@ class Kinepolis(Automation, RSS): rss_movies = self.getElements(data, 'channel/item') for movie in rss_movies: - RSSMovie['name'] = self.getTextElement(movie, "title") - currentYear = datetime.datetime.now().strftime("%Y") - RSSMovie['year'] = currentYear + name = self.getTextElement(movie, "title") + year = datetime.datetime.now().strftime("%Y") - log.debug('Release found: %s.', RSSMovie) - imdb = self.getIMDBFromTitle(RSSMovie['name'], RSSMovie['year']) + imdb = self.search(name, year) - if imdb: + if imdb and self.isMinimalMovie(imdb): movies.append(imdb['imdb']) return movies diff --git a/couchpotato/core/providers/automation/movies_io/__init__.py b/couchpotato/core/providers/automation/movies_io/__init__.py index 0f998f6b..5d997e9a 100644 --- a/couchpotato/core/providers/automation/movies_io/__init__.py +++ b/couchpotato/core/providers/automation/movies_io/__init__.py @@ -9,7 +9,7 @@ config = [{ { 'tab': 'automation', 'name': 'moviesio', - 'label': 'Movies.io', + 'label': 'Movies.IO', 'description': 'Imports movies from Movies.io RSS watchlists', 'options': [ {