Browse Source

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

pull/992/merge
Ruud 13 years ago
parent
commit
e918e6b12f
  1. 5
      couchpotato/core/plugins/automation/main.py
  2. 4
      couchpotato/core/plugins/movie/main.py
  3. 9
      couchpotato/core/providers/automation/base.py
  4. 17
      couchpotato/core/providers/automation/imdb/main.py
  5. 15
      couchpotato/core/providers/automation/movies_io/main.py

5
couchpotato/core/plugins/automation/main.py

@ -24,8 +24,9 @@ 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)
movie_ids.append(added_movie['id']) if added_movie:
movie_ids.append(added_movie['id'])
Env.prop(prop_name, True) Env.prop(prop_name, True)
for movie_id in movie_ids: for movie_id in movie_ids:

4
couchpotato/core/plugins/movie/main.py

@ -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):
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)

9
couchpotato/core/providers/automation/base.py

@ -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

17
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.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):
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):
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

15
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.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):
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):
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):
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

Loading…
Cancel
Save