From e918e6b12faae7c2a9f0b02d586a6b22b95f0aeb Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 23 Oct 2012 00:20:04 +0200 Subject: [PATCH] Check watchlist adds in automation plugin, not the providers. fix #838 --- couchpotato/core/plugins/automation/main.py | 5 +++-- couchpotato/core/plugins/movie/main.py | 4 ++-- couchpotato/core/providers/automation/base.py | 9 +++++++++ couchpotato/core/providers/automation/imdb/main.py | 17 ----------------- couchpotato/core/providers/automation/movies_io/main.py | 15 --------------- 5 files changed, 14 insertions(+), 36 deletions(-) diff --git a/couchpotato/core/plugins/automation/main.py b/couchpotato/core/plugins/automation/main.py index 9ac9d22..f4ede40 100644 --- a/couchpotato/core/plugins/automation/main.py +++ b/couchpotato/core/plugins/automation/main.py @@ -24,8 +24,9 @@ class Automation(Plugin): prop_name = 'automation.added.%s' % imdb_id added = Env.prop(prop_name, default = False) if not added: - added_movie = fireEvent('movie.add', params = {'identifier': imdb_id}, force_readd = False, search_after = False, single = True) - movie_ids.append(added_movie['id']) + added_movie = fireEvent('movie.add', params = {'identifier': imdb_id}, force_readd = False, search_after = False, update_library = True, single = True) + if added_movie: + movie_ids.append(added_movie['id']) Env.prop(prop_name, True) for movie_id in movie_ids: diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index 821eea1..8b0761c 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -283,7 +283,7 @@ class MoviePlugin(Plugin): 'movies': movies, }) - def add(self, params = {}, force_readd = True, search_after = True): + def add(self, params = {}, force_readd = True, search_after = True, update_library = False): if not params.get('identifier'): msg = 'Can\'t add movie without imdb identifier.' @@ -303,7 +303,7 @@ class MoviePlugin(Plugin): pass - library = fireEvent('library.add', single = True, attrs = params, update_after = False) + library = fireEvent('library.add', single = True, attrs = params, update_after = update_library) # Status status_active = fireEvent('status.add', 'active', single = True) diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py index d3af263..9f86ad1 100644 --- a/couchpotato/core/providers/automation/base.py +++ b/couchpotato/core/providers/automation/base.py @@ -28,9 +28,18 @@ class Automation(Plugin): return self.getIMDBids() def search(self, name, year = None, imdb_only = False): + + prop_name = 'automation.cached.%s.%s' % (name, year) + cached_imdb = Env.prop(prop_name, default = False) + if cached_imdb and imdb_only: + return cached_imdb + result = fireEvent('movie.search', q = '%s %s' % (name, year if year else ''), limit = 1, merge = True) if len(result) > 0: + if imdb_only and result[0].get('imdb'): + Env.prop(prop_name, result[0].get('imdb')) + return result[0].get('imdb') if imdb_only else result[0] else: return None diff --git a/couchpotato/core/providers/automation/imdb/main.py b/couchpotato/core/providers/automation/imdb/main.py index 6b8cbf7..a4511b4 100644 --- a/couchpotato/core/providers/automation/imdb/main.py +++ b/couchpotato/core/providers/automation/imdb/main.py @@ -2,9 +2,6 @@ from couchpotato.core.helpers.rss import RSS from couchpotato.core.helpers.variable import md5, getImdb from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation -from couchpotato.environment import Env -from dateutil.parser import parse -import time import traceback import xml.etree.ElementTree as XMLTree @@ -34,10 +31,6 @@ class IMDB(Automation, RSS): log.error('This isn\'t the correct url.: %s', rss_url) continue - prop_name = 'automation.imdb.last_update.%s' % md5(rss_url) - last_update = float(Env.prop(prop_name, default = 0)) - - last_movie_added = 0 try: cache_key = 'imdb.rss.%s' % md5(rss_url) @@ -46,20 +39,10 @@ class IMDB(Automation, RSS): rss_movies = self.getElements(data, 'channel/item') for movie in rss_movies: - created = int(time.mktime(parse(self.getTextElement(movie, "pubDate")).timetuple())) imdb = getImdb(self.getTextElement(movie, "link")) - - if created > last_movie_added: - last_movie_added = created - - if not imdb or created <= last_update: - continue - movies.append(imdb) except: log.error('Failed loading IMDB watchlist: %s %s', (rss_url, traceback.format_exc())) - Env.prop(prop_name, last_movie_added) - return movies diff --git a/couchpotato/core/providers/automation/movies_io/main.py b/couchpotato/core/providers/automation/movies_io/main.py index 3a5a2f0..5875a4d 100644 --- a/couchpotato/core/providers/automation/movies_io/main.py +++ b/couchpotato/core/providers/automation/movies_io/main.py @@ -3,10 +3,7 @@ from couchpotato.core.helpers.rss import RSS from couchpotato.core.helpers.variable import md5 from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation -from couchpotato.environment import Env -from dateutil.parser import parse from xml.etree.ElementTree import ParseError -import time import traceback import xml.etree.ElementTree as XMLTree @@ -33,10 +30,6 @@ class MoviesIO(Automation, RSS): if not enablers[index]: continue - prop_name = 'automation.moviesio.last_update.%s' % md5(rss_url) - last_update = float(Env.prop(prop_name, default = 0)) - - last_movie_added = 0 try: cache_key = 'imdb.rss.%s' % md5(rss_url) @@ -45,12 +38,6 @@ class MoviesIO(Automation, RSS): rss_movies = self.getElements(data, 'channel/item') for movie in rss_movies: - created = int(time.mktime(parse(self.getTextElement(movie, "pubDate")).timetuple())) - - if created > last_movie_added: - last_movie_added = created - if created <= last_update: - continue nameyear = fireEvent('scanner.name_year', self.getTextElement(movie, "title"), single = True) imdb = self.search(nameyear.get('name'), nameyear.get('year'), imdb_only = True) @@ -64,6 +51,4 @@ class MoviesIO(Automation, RSS): except: log.error('Failed loading Movies.io watchlist: %s %s', (rss_url, traceback.format_exc())) - Env.prop(prop_name, last_movie_added) - return movies