Private GIT

Skip to content
Snippets Groups Projects
Commit e918e6b1 authored by Ruud's avatar Ruud
Browse files

Check watchlist adds in automation plugin, not the providers. fix #838

parent b71f003a
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,8 @@ class Automation(Plugin): ...@@ -24,7 +24,8 @@ class Automation(Plugin):
prop_name = 'automation.added.%s' % imdb_id prop_name = 'automation.added.%s' % imdb_id
added = Env.prop(prop_name, default = False) added = Env.prop(prop_name, default = False)
if not added: if not added:
added_movie = fireEvent('movie.add', params = {'identifier': imdb_id}, force_readd = False, search_after = False, single = True) 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']) movie_ids.append(added_movie['id'])
Env.prop(prop_name, True) Env.prop(prop_name, True)
......
...@@ -283,7 +283,7 @@ class MoviePlugin(Plugin): ...@@ -283,7 +283,7 @@ class MoviePlugin(Plugin):
'movies': movies, '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'): if not params.get('identifier'):
msg = 'Can\'t add movie without imdb identifier.' msg = 'Can\'t add movie without imdb identifier.'
...@@ -303,7 +303,7 @@ class MoviePlugin(Plugin): ...@@ -303,7 +303,7 @@ class MoviePlugin(Plugin):
pass 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
status_active = fireEvent('status.add', 'active', single = True) status_active = fireEvent('status.add', 'active', single = True)
......
...@@ -28,9 +28,18 @@ class Automation(Plugin): ...@@ -28,9 +28,18 @@ class Automation(Plugin):
return self.getIMDBids() return self.getIMDBids()
def search(self, name, year = None, imdb_only = False): 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) result = fireEvent('movie.search', q = '%s %s' % (name, year if year else ''), limit = 1, merge = True)
if len(result) > 0: 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] return result[0].get('imdb') if imdb_only else result[0]
else: else:
return None return None
......
...@@ -2,9 +2,6 @@ from couchpotato.core.helpers.rss import RSS ...@@ -2,9 +2,6 @@ from couchpotato.core.helpers.rss import RSS
from couchpotato.core.helpers.variable import md5, getImdb from couchpotato.core.helpers.variable import md5, getImdb
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.providers.automation.base import Automation from couchpotato.core.providers.automation.base import Automation
from couchpotato.environment import Env
from dateutil.parser import parse
import time
import traceback import traceback
import xml.etree.ElementTree as XMLTree import xml.etree.ElementTree as XMLTree
...@@ -34,10 +31,6 @@ class IMDB(Automation, RSS): ...@@ -34,10 +31,6 @@ class IMDB(Automation, RSS):
log.error('This isn\'t the correct url.: %s', rss_url) log.error('This isn\'t the correct url.: %s', rss_url)
continue 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: try:
cache_key = 'imdb.rss.%s' % md5(rss_url) cache_key = 'imdb.rss.%s' % md5(rss_url)
...@@ -46,20 +39,10 @@ class IMDB(Automation, RSS): ...@@ -46,20 +39,10 @@ class IMDB(Automation, RSS):
rss_movies = self.getElements(data, 'channel/item') rss_movies = self.getElements(data, 'channel/item')
for movie in rss_movies: for movie in rss_movies:
created = int(time.mktime(parse(self.getTextElement(movie, "pubDate")).timetuple()))
imdb = getImdb(self.getTextElement(movie, "link")) 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) movies.append(imdb)
except: except:
log.error('Failed loading IMDB watchlist: %s %s', (rss_url, traceback.format_exc())) log.error('Failed loading IMDB watchlist: %s %s', (rss_url, traceback.format_exc()))
Env.prop(prop_name, last_movie_added)
return movies return movies
...@@ -3,10 +3,7 @@ from couchpotato.core.helpers.rss import RSS ...@@ -3,10 +3,7 @@ from couchpotato.core.helpers.rss import RSS
from couchpotato.core.helpers.variable import md5 from couchpotato.core.helpers.variable import md5
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.providers.automation.base import Automation from couchpotato.core.providers.automation.base import Automation
from couchpotato.environment import Env
from dateutil.parser import parse
from xml.etree.ElementTree import ParseError from xml.etree.ElementTree import ParseError
import time
import traceback import traceback
import xml.etree.ElementTree as XMLTree import xml.etree.ElementTree as XMLTree
...@@ -33,10 +30,6 @@ class MoviesIO(Automation, RSS): ...@@ -33,10 +30,6 @@ class MoviesIO(Automation, RSS):
if not enablers[index]: if not enablers[index]:
continue 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: try:
cache_key = 'imdb.rss.%s' % md5(rss_url) cache_key = 'imdb.rss.%s' % md5(rss_url)
...@@ -45,12 +38,6 @@ class MoviesIO(Automation, RSS): ...@@ -45,12 +38,6 @@ class MoviesIO(Automation, RSS):
rss_movies = self.getElements(data, 'channel/item') rss_movies = self.getElements(data, 'channel/item')
for movie in rss_movies: 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) nameyear = fireEvent('scanner.name_year', self.getTextElement(movie, "title"), single = True)
imdb = self.search(nameyear.get('name'), nameyear.get('year'), imdb_only = True) imdb = self.search(nameyear.get('name'), nameyear.get('year'), imdb_only = True)
...@@ -64,6 +51,4 @@ class MoviesIO(Automation, RSS): ...@@ -64,6 +51,4 @@ class MoviesIO(Automation, RSS):
except: except:
log.error('Failed loading Movies.io watchlist: %s %s', (rss_url, traceback.format_exc())) log.error('Failed loading Movies.io watchlist: %s %s', (rss_url, traceback.format_exc()))
Env.prop(prop_name, last_movie_added)
return movies return movies
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment