From b62afc63f1266cbb52f69491437c25123d25183b Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 4 Sep 2012 23:10:34 +0200 Subject: [PATCH] Speed up Userscript by not using BeautifulSoup. fix #796 --- .../providers/userscript/allocine/main.py | 24 ++++++++++----- .../userscript/rottentomatoes/main.py | 29 +++++++++++++++---- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/couchpotato/core/providers/userscript/allocine/main.py b/couchpotato/core/providers/userscript/allocine/main.py index 890ae223..8cc889ee 100644 --- a/couchpotato/core/providers/userscript/allocine/main.py +++ b/couchpotato/core/providers/userscript/allocine/main.py @@ -1,5 +1,9 @@ -from bs4 import BeautifulSoup +from couchpotato.core.logger import CPLog from couchpotato.core.providers.userscript.base import UserscriptBase +import traceback + +log = CPLog(__name__) + class AlloCine(UserscriptBase): @@ -15,11 +19,17 @@ class AlloCine(UserscriptBase): except: return - html = BeautifulSoup(data) - title = html.find('title').contents[0].strip() - split = title.split(') - ') + name = None + year = None - name = split[0][:-5].strip() - year = split[0][-4:] + try: + start = data.find('') + end = data.find('', start) + page_title = data[start + len(''):end].strip().split('-') + + name = page_title[0].strip() + year = page_title[1].strip()[-4:] + return self.search(name, year) + except: + log.error('Failed parsing page for title and year: %s', traceback.format_exc()) - return self.search(name, year) diff --git a/couchpotato/core/providers/userscript/rottentomatoes/main.py b/couchpotato/core/providers/userscript/rottentomatoes/main.py index c6117790..0b16a441 100644 --- a/couchpotato/core/providers/userscript/rottentomatoes/main.py +++ b/couchpotato/core/providers/userscript/rottentomatoes/main.py @@ -1,6 +1,10 @@ -from bs4 import BeautifulSoup -from couchpotato.core.event import fireEvent +from couchpotato.core.logger import CPLog from couchpotato.core.providers.userscript.base import UserscriptBase +import re +import traceback + +log = CPLog(__name__) + class RottenTomatoes(UserscriptBase): @@ -16,7 +20,20 @@ class RottenTomatoes(UserscriptBase): except: return - html = BeautifulSoup(data) - title = html.find('span', {'itemprop':'name'}).text - info = fireEvent('scanner.name_year', title, single = True) - return self.search(info['name'], info['year']) + try: + name = None + year = None + metas = re.findall("property=\"(video:release_date|og:title)\" content=\"([^\"]*)\"", data) + + for meta in metas: + mname, mvalue = meta + if mname == 'og:title': + name = mvalue.decode('unicode_escape') + elif mname == 'video:release_date': + year = mvalue[:4] + + if name and year: + return self.search(name, year) + + except: + log.error('Failed parsing page for title and year: %s', traceback.format_exc())