From 56a788286c83f49581b455e4d7832f9b7b1f7458 Mon Sep 17 00:00:00 2001 From: Micah James Date: Wed, 31 Jul 2013 22:41:49 -0400 Subject: [PATCH 1/6] Adding code for custom urls UI --- .../core/providers/automation/rottentomatoes/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/couchpotato/core/providers/automation/rottentomatoes/__init__.py b/couchpotato/core/providers/automation/rottentomatoes/__init__.py index 83a545b..579fe1f 100644 --- a/couchpotato/core/providers/automation/rottentomatoes/__init__.py +++ b/couchpotato/core/providers/automation/rottentomatoes/__init__.py @@ -19,6 +19,16 @@ config = [{ 'type': 'enabler', }, { + 'name': 'automation_urls_use', + 'label': 'Use', + }, + { + 'name': 'automation_urls', + 'label': 'url', + 'type': 'combined', + 'combine': ['automation_urls_use', 'automation_urls'], + }, + { 'name': 'tomatometer_percent', 'default': '80', 'label': 'Tomatometer', From 3a8f891c7d168d570b1c02ac51ebe00ebef34604 Mon Sep 17 00:00:00 2001 From: Micah James Date: Wed, 31 Jul 2013 22:45:48 -0400 Subject: [PATCH 2/6] Adding more code. --- couchpotato/core/providers/automation/rottentomatoes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/providers/automation/rottentomatoes/__init__.py b/couchpotato/core/providers/automation/rottentomatoes/__init__.py index 579fe1f..1940614 100644 --- a/couchpotato/core/providers/automation/rottentomatoes/__init__.py +++ b/couchpotato/core/providers/automation/rottentomatoes/__init__.py @@ -8,7 +8,7 @@ config = [{ 'groups': [ { 'tab': 'automation', - 'list': 'automation_providers', + 'list': 'watchlist_providers', 'name': 'rottentomatoes_automation', 'label': 'Rottentomatoes', 'description': 'Imports movies from the rottentomatoes "in theaters"-feed.', From 797018fb8aabbc8caa39a9f91cdeb78a82c77168 Mon Sep 17 00:00:00 2001 From: Micah James Date: Wed, 31 Jul 2013 22:47:52 -0400 Subject: [PATCH 3/6] Revert "Adding more code." This reverts commit 3a8f891c7d168d570b1c02ac51ebe00ebef34604. --- couchpotato/core/providers/automation/rottentomatoes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/providers/automation/rottentomatoes/__init__.py b/couchpotato/core/providers/automation/rottentomatoes/__init__.py index 1940614..579fe1f 100644 --- a/couchpotato/core/providers/automation/rottentomatoes/__init__.py +++ b/couchpotato/core/providers/automation/rottentomatoes/__init__.py @@ -8,7 +8,7 @@ config = [{ 'groups': [ { 'tab': 'automation', - 'list': 'watchlist_providers', + 'list': 'automation_providers', 'name': 'rottentomatoes_automation', 'label': 'Rottentomatoes', 'description': 'Imports movies from the rottentomatoes "in theaters"-feed.', From da50b19b6b08d456deef5b977eb2de40c05eafbb Mon Sep 17 00:00:00 2001 From: Micah James Date: Wed, 31 Jul 2013 23:06:12 -0400 Subject: [PATCH 4/6] Added custom url code handling --- .../providers/automation/rottentomatoes/main.py | 54 +++++++++++++--------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/couchpotato/core/providers/automation/rottentomatoes/main.py b/couchpotato/core/providers/automation/rottentomatoes/main.py index 9842d4c..47b9395 100644 --- a/couchpotato/core/providers/automation/rottentomatoes/main.py +++ b/couchpotato/core/providers/automation/rottentomatoes/main.py @@ -1,5 +1,5 @@ from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.helpers.variable import tryInt, splitString from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation from xml.etree.ElementTree import QName @@ -11,38 +11,48 @@ log = CPLog(__name__) class Rottentomatoes(Automation, RSS): interval = 1800 - urls = { - 'namespace': 'http://www.rottentomatoes.com/xmlns/rtmovie/', - 'theater': 'http://www.rottentomatoes.com/syndication/rss/in_theaters.xml', - } + + def getIMDBids(self): movies = [] - rss_movies = self.getRSSData(self.urls['theater']) - rating_tag = str(QName(self.urls['namespace'], 'tomatometer_percent')) + rotten_tomatoes_namespace = 'http://www.rottentomatoes.com/xmlns/rtmovie/' + enablers = [tryInt(x) for x in splitString(self.conf('automation_urls_use'))] + urls = splitString(self.conf('automation_urls')) + + index = -1 + + for url in urls: + + index += 1 + if not enablers[index]: + continue + + rss_movies = self.getRSSData(url) + rating_tag = str(QName(rotten_tomatoes_namespace, 'tomatometer_percent')) - for movie in rss_movies: + for movie in rss_movies: - value = self.getTextElement(movie, "title") - result = re.search('(?<=%\s).*', value) + value = self.getTextElement(movie, "title") + result = re.search('(?<=%\s).*', value) - if result: + if result: - log.info2('Something smells...') - rating = tryInt(self.getTextElement(movie, rating_tag)) - name = result.group(0) + log.info2('Something smells...') + rating = tryInt(self.getTextElement(movie, rating_tag)) + name = result.group(0) - if rating < tryInt(self.conf('tomatometer_percent')): - log.info2('%s seems to be rotten...', name) - else: + if rating < tryInt(self.conf('tomatometer_percent')): + log.info2('%s seems to be rotten...', name) + else: - log.info2('Found %s fresh enough movies, enqueuing: %s', (rating, name)) - year = datetime.datetime.now().strftime("%Y") - imdb = self.search(name, year) + log.info2('Found %s fresh enough movies, enqueuing: %s', (rating, name)) + year = datetime.datetime.now().strftime("%Y") + imdb = self.search(name, year) - if imdb and self.isMinimalMovie(imdb): - movies.append(imdb['imdb']) + if imdb and self.isMinimalMovie(imdb): + movies.append(imdb['imdb']) return movies From 4330dc39bf37d6e1332d2a2471454c6667b86aa7 Mon Sep 17 00:00:00 2001 From: Micah James Date: Wed, 31 Jul 2013 23:14:58 -0400 Subject: [PATCH 5/6] Changed description to be better suited for this. --- couchpotato/core/providers/automation/rottentomatoes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/providers/automation/rottentomatoes/__init__.py b/couchpotato/core/providers/automation/rottentomatoes/__init__.py index 579fe1f..52b1c88 100644 --- a/couchpotato/core/providers/automation/rottentomatoes/__init__.py +++ b/couchpotato/core/providers/automation/rottentomatoes/__init__.py @@ -11,7 +11,7 @@ config = [{ 'list': 'automation_providers', 'name': 'rottentomatoes_automation', 'label': 'Rottentomatoes', - 'description': 'Imports movies from the rottentomatoes "in theaters"-feed.', + 'description': 'Imports movies from rottentomatoes rss feeds specified below.', 'options': [ { 'name': 'automation_enabled', From 4ffda9f705c32e903ea8cda2323b4272a290a653 Mon Sep 17 00:00:00 2001 From: Micah James Date: Thu, 1 Aug 2013 23:15:36 -0400 Subject: [PATCH 6/6] Made code more python-y per mano3ms recommendation. --- couchpotato/core/providers/automation/rottentomatoes/main.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/providers/automation/rottentomatoes/main.py b/couchpotato/core/providers/automation/rottentomatoes/main.py index 47b9395..40f72a5 100644 --- a/couchpotato/core/providers/automation/rottentomatoes/main.py +++ b/couchpotato/core/providers/automation/rottentomatoes/main.py @@ -19,15 +19,11 @@ class Rottentomatoes(Automation, RSS): movies = [] rotten_tomatoes_namespace = 'http://www.rottentomatoes.com/xmlns/rtmovie/' - enablers = [tryInt(x) for x in splitString(self.conf('automation_urls_use'))] - urls = splitString(self.conf('automation_urls')) - - index = -1 + urls = dict(zip(splitString(self.conf('automation_urls')), [tryInt(x) for x in splitString(self.conf('automation_urls_use'))])) for url in urls: - index += 1 - if not enablers[index]: + if not urls[url]: continue rss_movies = self.getRSSData(url)