From 1c668451aab2cb142e2905b309be56f1f09c9589 Mon Sep 17 00:00:00 2001 From: bwq Date: Fri, 22 Jun 2012 04:27:22 +0200 Subject: [PATCH 1/2] * base.py: now gets the proper rating and votes, added new function that gets an imdb movie object for a given title * automation/bluray: added a new automation provider that gets info from blu-ray.com * imdbapi: added new event so we can search just the imdb api (only one that supplies the information necessary for automation providers since it has imdb votes and rating) --- couchpotato/core/providers/automation/base.py | 27 ++++++++- .../core/providers/automation/bluray/__init__.py | 23 ++++++++ .../core/providers/automation/bluray/main.py | 66 ++++++++++++++++++++++ couchpotato/core/providers/movie/imdbapi/main.py | 1 + 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 couchpotato/core/providers/automation/bluray/__init__.py create mode 100644 couchpotato/core/providers/automation/bluray/main.py diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py index 71ed988..d43b5c8 100644 --- a/couchpotato/core/providers/automation/base.py +++ b/couchpotato/core/providers/automation/base.py @@ -2,6 +2,7 @@ from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env +from couchpotato.core.helpers.encoding import simplifyString import time log = CPLog(__name__) @@ -36,18 +37,38 @@ class Automation(Plugin): return None def isMinimal(self, identifier): - movie = fireEvent('movie.info', identifier = identifier, merge = True) - + return self.isMinimalMovie(movie) + + def isMinimalMovie(self, movie): + if movie['rating']: + rating = movie['rating']['imdb'][0] + 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 to 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, identifier, type_min, type_value)) return False return True + def getIMDBFromTitle(self, title): + cache_key = u'%s/%s' % (__name__, simplifyString(title)) + movies = Env.get('cache').get(cache_key) + + if not movies: + movies = fireEvent('movie.searchimdb', q = title, merge = True) + Env.get('cache').set(cache_key, movies) + + try: + return movies[0] + + except: + log.info("No results for " + title) + def getMinimal(self, min_type): return Env.setting(min_type, 'automation') diff --git a/couchpotato/core/providers/automation/bluray/__init__.py b/couchpotato/core/providers/automation/bluray/__init__.py new file mode 100644 index 0000000..5eabba3 --- /dev/null +++ b/couchpotato/core/providers/automation/bluray/__init__.py @@ -0,0 +1,23 @@ +from .main import Bluray + +def start(): + return Bluray() + +config = [{ + 'name': 'bluray', + 'groups': [ + { + 'tab': 'automation', + 'name': 'bluray_automation', + 'label': 'Blu-ray.com', + 'description': 'imports movies from blu-ray.com', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + ], + }, + ], +}] \ No newline at end of file diff --git a/couchpotato/core/providers/automation/bluray/main.py b/couchpotato/core/providers/automation/bluray/main.py new file mode 100644 index 0000000..bdee5d5 --- /dev/null +++ b/couchpotato/core/providers/automation/bluray/main.py @@ -0,0 +1,66 @@ +from couchpotato.core.helpers.rss import RSS +from couchpotato.core.helpers.variable import md5, getImdb, cleanHost +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation +from couchpotato.environment import Env +from urllib import quote_plus +import traceback +import xml.etree.ElementTree as XMLTree +import json + +log = CPLog(__name__) + + +class Bluray(Automation, RSS): + + interval = 1800 + rss_url = 'http://www.blu-ray.com/rss/newreleasesfeed.xml' + + def getIMDBids(self): + + if self.isDisabled(): + 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) + data = XMLTree.fromstring(rss_data) + + if data: + 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() + + if not RSSMovie['name'].find("/") == -1: # make sure it is not a double movie release + continue + + if int(RSSMovie['year']) < Env.setting('year', 'automation'): #do year filtering + 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.info("Applying IMDB filter to found movies...") + + for RSSMovie in RSSMovies: + log.debug('Searching for "%s".' % RSSMovie) + imdb = self.getIMDBFromTitle(RSSMovie['name'] + ' ' + RSSMovie['year']) + + if imdb: + if self.isMinimalMovie(imdb): + movies.append(imdb['imdb']) + + return movies \ No newline at end of file diff --git a/couchpotato/core/providers/movie/imdbapi/main.py b/couchpotato/core/providers/movie/imdbapi/main.py index ad3f78f..d8d6574 100644 --- a/couchpotato/core/providers/movie/imdbapi/main.py +++ b/couchpotato/core/providers/movie/imdbapi/main.py @@ -21,6 +21,7 @@ class IMDBAPI(MovieProvider): def __init__(self): addEvent('movie.search', self.search) + addEvent('movie.searchimdb', self.search) addEvent('movie.info', self.getInfo) def search(self, q, limit = 12): From b6b219abfd5bbc488a82e8dd7de2de5f5bb62d46 Mon Sep 17 00:00:00 2001 From: bwq Date: Fri, 22 Jun 2012 04:44:28 +0200 Subject: [PATCH 2/2] * Added Kinepolis automation provider (uses optimized search code from the blu-ray.com commit) * Optimized imports --- .../core/providers/automation/bluray/main.py | 4 +- .../providers/automation/kinepolis/__init__.py | 23 +++++++++++ .../core/providers/automation/kinepolis/main.py | 46 ++++++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 couchpotato/core/providers/automation/kinepolis/__init__.py create mode 100644 couchpotato/core/providers/automation/kinepolis/main.py diff --git a/couchpotato/core/providers/automation/bluray/main.py b/couchpotato/core/providers/automation/bluray/main.py index bdee5d5..2dec9fc 100644 --- a/couchpotato/core/providers/automation/bluray/main.py +++ b/couchpotato/core/providers/automation/bluray/main.py @@ -1,9 +1,8 @@ from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import md5, getImdb, cleanHost +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 urllib import quote_plus import traceback import xml.etree.ElementTree as XMLTree import json @@ -56,7 +55,6 @@ class Bluray(Automation, RSS): log.info("Applying IMDB filter to found movies...") for RSSMovie in RSSMovies: - log.debug('Searching for "%s".' % RSSMovie) imdb = self.getIMDBFromTitle(RSSMovie['name'] + ' ' + RSSMovie['year']) if imdb: diff --git a/couchpotato/core/providers/automation/kinepolis/__init__.py b/couchpotato/core/providers/automation/kinepolis/__init__.py new file mode 100644 index 0000000..6590e13 --- /dev/null +++ b/couchpotato/core/providers/automation/kinepolis/__init__.py @@ -0,0 +1,23 @@ +from .main import Kinepolis + +def start(): + return Kinepolis() + +config = [{ + 'name': 'kinepolis', + 'groups': [ + { + 'tab': 'automation', + 'name': 'kinepolis_automation', + 'label': 'Kinepolis', + 'description': 'imports movies from the current top 10 of kinepolis', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + ], + }, + ], +}] \ No newline at end of file diff --git a/couchpotato/core/providers/automation/kinepolis/main.py b/couchpotato/core/providers/automation/kinepolis/main.py new file mode 100644 index 0000000..3b1905b --- /dev/null +++ b/couchpotato/core/providers/automation/kinepolis/main.py @@ -0,0 +1,46 @@ +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 +import time +import traceback +import xml.etree.ElementTree as XMLTree +import datetime + +log = CPLog(__name__) + + +class Kinepolis(Automation, RSS): + + interval = 1800 + rss_url = 'http://kinepolis.be/nl/top10-box-office/feed' + + def getIMDBids(self): + + if self.isDisabled(): + return + + movies = [] + RSSMovie = {'name': 'placeholder', 'year' : 'placeholder'} + + cache_key = 'kinepolis.%s' % md5(self.rss_url) + rss_data = self.getCache(cache_key, self.rss_url) + data = XMLTree.fromstring(rss_data) + + if data: + 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 + + log.info('Release found: %s.' % RSSMovie) + imdb = self.getIMDBFromTitle(RSSMovie['name'] + ' ' + RSSMovie['year']) + + if imdb: + movies.append(imdb['imdb']) + + return movies \ No newline at end of file