diff --git a/couchpotato/core/plugins/automation/main.py b/couchpotato/core/plugins/automation/main.py index f4ede40d..c216688c 100644 --- a/couchpotato/core/plugins/automation/main.py +++ b/couchpotato/core/plugins/automation/main.py @@ -12,7 +12,7 @@ class Automation(Plugin): fireEvent('schedule.interval', 'automation.add_movies', self.addMovies, hours = self.conf('hour', default = 12)) - if not Env.get('dev'): + if Env.get('dev'): addEvent('app.load', self.addMovies) def addMovies(self): diff --git a/couchpotato/core/providers/automation/base.py b/couchpotato/core/providers/automation/base.py index 9f86ad12..8d08f913 100644 --- a/couchpotato/core/providers/automation/base.py +++ b/couchpotato/core/providers/automation/base.py @@ -1,13 +1,13 @@ from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.logger import CPLog -from couchpotato.core.plugins.base import Plugin +from couchpotato.core.providers.base import Provider from couchpotato.environment import Env import time log = CPLog(__name__) -class Automation(Plugin): +class Automation(Provider): enabled_option = 'automation_enabled' @@ -19,6 +19,9 @@ class Automation(Plugin): def _getMovies(self): + if self.isDisabled(): + return + if not self.canCheck(): log.debug('Just checked, skipping %s', self.getName()) return [] diff --git a/couchpotato/core/providers/automation/bluray/main.py b/couchpotato/core/providers/automation/bluray/main.py index ac28152c..235a1e5f 100644 --- a/couchpotato/core/providers/automation/bluray/main.py +++ b/couchpotato/core/providers/automation/bluray/main.py @@ -1,8 +1,7 @@ from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import md5, tryInt +from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation -import xml.etree.ElementTree as XMLTree log = CPLog(__name__) @@ -14,32 +13,24 @@ class Bluray(Automation, RSS): def getIMDBids(self): - if self.isDisabled(): - return - movies = [] - cache_key = 'bluray.%s' % md5(self.rss_url) - rss_data = self.getCache(cache_key, self.rss_url) - data = XMLTree.fromstring(rss_data) + rss_movies = self.getRSSData(self.rss_url) - if data is not None: - rss_movies = self.getElements(data, 'channel/item') + for movie in rss_movies: + name = self.getTextElement(movie, 'title').lower().split('blu-ray')[0].strip('(').rstrip() + year = self.getTextElement(movie, 'description').split('|')[1].strip('(').strip() - for movie in rss_movies: - name = self.getTextElement(movie, "title").lower().split("blu-ray")[0].strip("(").rstrip() - year = self.getTextElement(movie, "description").split("|")[1].strip("(").strip() + if not name.find('/') == -1: # make sure it is not a double movie release + continue - if not name.find("/") == -1: # make sure it is not a double movie release - continue + if tryInt(year) < self.getMinimal('year'): + continue - if tryInt(year) < self.getMinimal('year'): - continue + imdb = self.search(name, year) - imdb = self.search(name, year) - - if imdb: - if self.isMinimalMovie(imdb): - movies.append(imdb['imdb']) + if imdb: + if self.isMinimalMovie(imdb): + movies.append(imdb['imdb']) return movies diff --git a/couchpotato/core/providers/automation/cp/main.py b/couchpotato/core/providers/automation/cp/main.py index 24d69092..22b7942a 100644 --- a/couchpotato/core/providers/automation/cp/main.py +++ b/couchpotato/core/providers/automation/cp/main.py @@ -8,7 +8,4 @@ class CP(Automation): def getMovies(self): - if self.isDisabled(): - return - return [] diff --git a/couchpotato/core/providers/automation/imdb/main.py b/couchpotato/core/providers/automation/imdb/main.py index c2324856..428a8b2b 100644 --- a/couchpotato/core/providers/automation/imdb/main.py +++ b/couchpotato/core/providers/automation/imdb/main.py @@ -1,5 +1,5 @@ from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import md5, getImdb, splitString, tryInt +from couchpotato.core.helpers.variable import getImdb, splitString, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation import traceback @@ -13,9 +13,6 @@ class IMDB(Automation, RSS): def getIMDBids(self): - if self.isDisabled(): - return - movies = [] enablers = [tryInt(x) for x in splitString(self.conf('automation_urls_use'))] @@ -29,8 +26,7 @@ class IMDB(Automation, RSS): continue try: - cache_key = 'imdb.rss.%s' % md5(url) - rss_data = self.getCache(cache_key, url) + rss_data = self.getHTMLData(url) imdbs = getImdb(rss_data, multiple = True) for imdb in imdbs: diff --git a/couchpotato/core/providers/automation/kinepolis/main.py b/couchpotato/core/providers/automation/kinepolis/main.py index f6633af7..4158d488 100644 --- a/couchpotato/core/providers/automation/kinepolis/main.py +++ b/couchpotato/core/providers/automation/kinepolis/main.py @@ -1,9 +1,7 @@ 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 import datetime -import xml.etree.ElementTree as XMLTree log = CPLog(__name__) @@ -15,25 +13,17 @@ class Kinepolis(Automation, RSS): def getIMDBids(self): - if self.isDisabled(): - return - movies = [] - cache_key = 'kinepolis.%s' % md5(self.rss_url) - rss_data = self.getCache(cache_key, self.rss_url) - data = XMLTree.fromstring(rss_data) + rss_movies = self.getRSSData(self.rss_url) - if data is not None: - rss_movies = self.getElements(data, 'channel/item') + for movie in rss_movies: + name = self.getTextElement(movie, 'title') + year = datetime.datetime.now().strftime('%Y') - for movie in rss_movies: - name = self.getTextElement(movie, "title") - year = datetime.datetime.now().strftime("%Y") + imdb = self.search(name, year) - 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 diff --git a/couchpotato/core/providers/automation/moviemeter_nl/__init__.py b/couchpotato/core/providers/automation/moviemeter/__init__.py similarity index 100% rename from couchpotato/core/providers/automation/moviemeter_nl/__init__.py rename to couchpotato/core/providers/automation/moviemeter/__init__.py diff --git a/couchpotato/core/providers/automation/moviemeter/main.py b/couchpotato/core/providers/automation/moviemeter/main.py new file mode 100644 index 00000000..dae764bf --- /dev/null +++ b/couchpotato/core/providers/automation/moviemeter/main.py @@ -0,0 +1,28 @@ +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.rss import RSS +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation + +log = CPLog(__name__) + + +class Moviemeter(Automation, RSS): + + interval = 1800 + rss_url = 'http://www.moviemeter.nl/rss/cinema' + + def getIMDBids(self): + + movies = [] + + rss_movies = self.getRSSData(self.rss_url) + + for movie in rss_movies: + + name_year = fireEvent('scanner.name_year', self.getTextElement(movie, 'title'), single = True) + imdb = self.search(name_year.get('name'), name_year.get('year')) + + if imdb and self.isMinimalMovie(imdb): + movies.append(imdb['imdb']) + + return movies diff --git a/couchpotato/core/providers/automation/moviemeter_nl/main.py b/couchpotato/core/providers/automation/moviemeter_nl/main.py deleted file mode 100644 index b9de372f..00000000 --- a/couchpotato/core/providers/automation/moviemeter_nl/main.py +++ /dev/null @@ -1,39 +0,0 @@ -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 -import datetime -import xml.etree.ElementTree as XMLTree - -log = CPLog(__name__) - - -class Moviemeter(Automation, RSS): - - interval = 1800 - rss_url = 'http://www.moviemeter.nl/rss/cinema' - - def getIMDBids(self): - - if self.isDisabled(): - return - - movies = [] - - cache_key = 'moviemeter.%s' % md5(self.rss_url) - rss_data = self.getCache(cache_key, self.rss_url) - data = XMLTree.fromstring(rss_data) - - if data is not None: - rss_movies = self.getElements(data, 'channel/item') - - for movie in rss_movies: - name = self.getTextElement(movie, "title") - year = datetime.datetime.now().strftime("%Y") - - imdb = self.search(name, year) - - if imdb and self.isMinimalMovie(imdb): - movies.append(imdb['imdb']) - - return movies diff --git a/couchpotato/core/providers/automation/movies_io/main.py b/couchpotato/core/providers/automation/movies_io/main.py index 5875a4d9..0737e2e6 100644 --- a/couchpotato/core/providers/automation/movies_io/main.py +++ b/couchpotato/core/providers/automation/movies_io/main.py @@ -1,11 +1,8 @@ from couchpotato.core.event import fireEvent from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import md5 +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 ParseError -import traceback -import xml.etree.ElementTree as XMLTree log = CPLog(__name__) @@ -16,39 +13,27 @@ class MoviesIO(Automation, RSS): def getIMDBids(self): - if self.isDisabled(): - return - movies = [] - enablers = self.conf('automation_urls_use').split(',') + enablers = [tryInt(x) for x in splitString(self.conf('automation_urls_use'))] index = -1 - for rss_url in self.conf('automation_urls').split(','): + for rss_url in splitString(self.conf('automation_urls')): index += 1 if not enablers[index]: continue - try: - cache_key = 'imdb.rss.%s' % md5(rss_url) + rss_movies = self.getRSSData(rss_url, headers = {'Referer': ''}) - rss_data = self.getCache(cache_key, rss_url, headers = {'Referer': ''}) - data = XMLTree.fromstring(rss_data) - rss_movies = self.getElements(data, 'channel/item') + for movie in rss_movies: - for movie in rss_movies: + nameyear = fireEvent('scanner.name_year', self.getTextElement(movie, 'title'), single = True) + imdb = self.search(nameyear.get('name'), nameyear.get('year'), imdb_only = True) - nameyear = fireEvent('scanner.name_year', self.getTextElement(movie, "title"), single = True) - imdb = self.search(nameyear.get('name'), nameyear.get('year'), imdb_only = True) + if not imdb: + continue - if not imdb: - continue - - movies.append(imdb) - except ParseError: - log.debug('Failed loading Movies.io watchlist, probably empty: %s', (rss_url)) - except: - log.error('Failed loading Movies.io watchlist: %s %s', (rss_url, traceback.format_exc())) + movies.append(imdb) return movies diff --git a/couchpotato/core/providers/automation/trakt/main.py b/couchpotato/core/providers/automation/trakt/main.py index 764f6cfc..0109daf3 100644 --- a/couchpotato/core/providers/automation/trakt/main.py +++ b/couchpotato/core/providers/automation/trakt/main.py @@ -1,9 +1,8 @@ from couchpotato.core.event import addEvent -from couchpotato.core.helpers.variable import md5, sha1 +from couchpotato.core.helpers.variable import sha1 from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation import base64 -import json log = CPLog(__name__) @@ -25,9 +24,6 @@ class Trakt(Automation): def getIMDBids(self): - if self.isDisabled(): - return - movies = [] for movie in self.getWatchlist(): movies.append(movie.get('imdb_id')) @@ -38,22 +34,11 @@ class Trakt(Automation): method = (self.urls['watchlist'] % self.conf('automation_api_key')) + self.conf('automation_username') return self.call(method) - def call(self, method_url): - try: - if self.conf('automation_password'): - headers = { - 'Authorization': 'Basic %s' % base64.encodestring('%s:%s' % (self.conf('automation_username'), self.conf('automation_password')))[:-1] - } - else: - headers = {} + headers = {} + if self.conf('automation_password'): + headers['Authorization'] = 'Basic %s' % base64.encodestring('%s:%s' % (self.conf('automation_username'), self.conf('automation_password')))[:-1] - cache_key = 'trakt.%s' % md5(method_url) - json_string = self.getCache(cache_key, self.urls['base'] + method_url, headers = headers) - if json_string: - return json.loads(json_string) - except: - log.error('Failed to get data from trakt, check your login.') - - return [] + data = self.getJsonData(self.urls['base'] + method_url, headers = headers) + return data if data else [] diff --git a/couchpotato/core/providers/base.py b/couchpotato/core/providers/base.py index f16cf6ea..1415286f 100644 --- a/couchpotato/core/providers/base.py +++ b/couchpotato/core/providers/base.py @@ -44,6 +44,34 @@ class Provider(Plugin): return self.is_available.get(host, False) + def getJsonData(self, url, **kwargs): + + data = self.getCache(md5(url), url, **kwargs) + + if data: + try: + return json.loads(data) + except: + log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) + + return [] + + def getRSSData(self, url, **kwargs): + + data = self.getCache(md5(url), url, **kwargs) + + if data: + try: + data = XMLTree.fromstring(data) + return self.getElements(data, 'channel/item') + except: + log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) + + return [] + + def getHTMLData(self, url, **kwargs): + return self.getCache(md5(url), url, **kwargs) + class YarrProvider(Provider): @@ -165,34 +193,6 @@ class YarrProvider(Provider): return [self.cat_backup_id] - def getJsonData(self, url, **kwargs): - - data = self.getCache(md5(url), url, **kwargs) - - if data: - try: - return json.loads(data) - except: - log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) - - return [] - - def getRSSData(self, url, **kwargs): - - data = self.getCache(md5(url), url, **kwargs) - - if data: - try: - data = XMLTree.fromstring(data) - return self.getElements(data, 'channel/item') - except: - log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) - - return [] - - def getHTMLData(self, url, **kwargs): - return self.getCache(md5(url), url, **kwargs) - class ResultList(list):