Cleanup automation providers

This commit is contained in:
Ruud
2012-07-16 01:11:52 +02:00
parent b07a937fa7
commit ee21610bc3
4 changed files with 18 additions and 42 deletions
+7 -12
View File
@@ -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')
@@ -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):
@@ -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
@@ -9,7 +9,7 @@ config = [{
{
'tab': 'automation',
'name': 'moviesio',
'label': 'Movies.io',
'label': 'Movies.IO',
'description': 'Imports movies from <a href="http://movies.io">Movies.io</a> RSS watchlists',
'options': [
{