From 82aba8868c0782e263bf9245d7a0bf4e6b288585 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 20 May 2012 15:39:14 +0200 Subject: [PATCH] Only get nzb details when needed --- couchpotato/core/plugins/score/main.py | 5 +++ couchpotato/core/plugins/searcher/main.py | 10 ++++++ couchpotato/core/providers/nzb/newzbin/main.py | 2 +- couchpotato/core/providers/nzb/newznab/main.py | 3 +- couchpotato/core/providers/nzb/nzbclub/main.py | 40 ++++++++++++++++++------ couchpotato/core/providers/nzb/nzbindex/main.py | 19 ++++++----- couchpotato/core/providers/nzb/nzbmatrix/main.py | 2 +- 7 files changed, 60 insertions(+), 21 deletions(-) diff --git a/couchpotato/core/plugins/score/main.py b/couchpotato/core/plugins/score/main.py index 74fed1d..8b4fedb 100644 --- a/couchpotato/core/plugins/score/main.py +++ b/couchpotato/core/plugins/score/main.py @@ -38,4 +38,9 @@ class Score(Plugin): # Duplicates in name score += duplicateScore(nzb['name'], getTitle(movie['library'])) + # Extra provider specific check + extra_score = nzb.get('extra_score') + if extra_score: + score += extra_score(nzb) + return score diff --git a/couchpotato/core/plugins/searcher/main.py b/couchpotato/core/plugins/searcher/main.py index 7983f92..99392ac 100644 --- a/couchpotato/core/plugins/searcher/main.py +++ b/couchpotato/core/plugins/searcher/main.py @@ -265,6 +265,16 @@ class Searcher(Plugin): return False + # Provider specific functions + get_more = nzb.get('get_more_info') + if get_more: + get_more(nzb) + + extra_check = nzb.get('extra_check') + if extra_check and not extra_check(nzb): + return False + + if imdb_results: return True diff --git a/couchpotato/core/providers/nzb/newzbin/main.py b/couchpotato/core/providers/nzb/newzbin/main.py index 80f856e..02efffa 100644 --- a/couchpotato/core/providers/nzb/newzbin/main.py +++ b/couchpotato/core/providers/nzb/newzbin/main.py @@ -115,12 +115,12 @@ class Newzbin(NZBProvider, RSS): 'description': self.getTextElement(nzb, "description"), 'check_nzb': False, } - new['score'] = fireEvent('score.calculate', new, movie, single = True) is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, imdb_results = True, single_category = single_cat, single = True) if is_correct_movie: + new['score'] = fireEvent('score.calculate', new, movie, single = True) results.append(new) self.found(new) diff --git a/couchpotato/core/providers/nzb/newznab/main.py b/couchpotato/core/providers/nzb/newznab/main.py index 8b959b5..691f5e6 100644 --- a/couchpotato/core/providers/nzb/newznab/main.py +++ b/couchpotato/core/providers/nzb/newznab/main.py @@ -144,13 +144,12 @@ class Newznab(NZBProvider, RSS): } if not for_feed: - new['score'] = fireEvent('score.calculate', new, movie, single = True) - is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, imdb_results = True, single_category = single_cat, single = True) if is_correct_movie: + new['score'] = fireEvent('score.calculate', new, movie, single = True) results.append(new) self.found(new) else: diff --git a/couchpotato/core/providers/nzb/nzbclub/main.py b/couchpotato/core/providers/nzb/nzbclub/main.py index 40bc2d1..2005fd2 100644 --- a/couchpotato/core/providers/nzb/nzbclub/main.py +++ b/couchpotato/core/providers/nzb/nzbclub/main.py @@ -58,10 +58,14 @@ class NZBClub(NZBProvider, RSS): size = enclosure['length'] date = self.getTextElement(nzb, "pubDate") - full_description = self.getCache('nzbclub.%s' % nzbclub_id, self.getTextElement(nzb, "link"), cache_timeout = 25920000) - html = BeautifulSoup(full_description) - nfo_pre = html.find('pre', attrs = {'class':'nfo'}) - description = toUnicode(nfo_pre.text) if nfo_pre else '' + def extra_check(item): + full_description = self.getCache('nzbclub.%s' % nzbclub_id, item['detail_url'], cache_timeout = 25920000) + + if 'ARCHIVE inside ARCHIVE' in full_description: + log.info('Wrong: Seems to be passworded files: %s' % new['name']) + return False + + return True new = { 'id': nzbclub_id, @@ -73,19 +77,17 @@ class NZBClub(NZBProvider, RSS): 'url': enclosure['url'].replace(' ', '_'), 'download': self.download, 'detail_url': self.getTextElement(nzb, "link"), - 'description': description, + 'description': '', + 'get_more_info': self.getMoreInfo, + 'extra_check': extra_check } - new['score'] = fireEvent('score.calculate', new, movie, single = True) - - if 'ARCHIVE inside ARCHIVE' in full_description: - log.info('Wrong: Seems to be passworded files: %s' % new['name']) - continue is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, imdb_results = False, single_category = False, single = True) if is_correct_movie: + new['score'] = fireEvent('score.calculate', new, movie, single = True) results.append(new) self.found(new) @@ -94,3 +96,21 @@ class NZBClub(NZBProvider, RSS): log.error('Failed to parse XML response from NZBClub') return results + + def getMoreInfo(self, item): + full_description = self.getCache('nzbclub.%s' % item['id'], item['detail_url'], cache_timeout = 25920000) + html = BeautifulSoup(full_description) + nfo_pre = html.find('pre', attrs = {'class':'nfo'}) + description = toUnicode(nfo_pre.text) if nfo_pre else '' + + item['description'] = description + return item + + def extraCheck(self, item): + full_description = self.getCache('nzbclub.%s' % item['id'], item['detail_url'], cache_timeout = 25920000) + + if 'ARCHIVE inside ARCHIVE' in full_description: + log.info('Wrong: Seems to be passworded files: %s' % new['name']) + return False + + return True diff --git a/couchpotato/core/providers/nzb/nzbindex/main.py b/couchpotato/core/providers/nzb/nzbindex/main.py index 831ea9c..96e875a 100644 --- a/couchpotato/core/providers/nzb/nzbindex/main.py +++ b/couchpotato/core/providers/nzb/nzbindex/main.py @@ -63,13 +63,8 @@ class NzbIndex(NZBProvider, RSS): try: description = self.getTextElement(nzb, "description") - if '/nfo/' in description.lower(): - nfo_url = re.search('href=\"(?P.+)\" ', description).group('nfo') - full_description = self.getCache('nzbindex.%s' % nzbindex_id, url = nfo_url, cache_timeout = 25920000) - html = BeautifulSoup(full_description) - description = toUnicode(html.find('pre', attrs = {'id':'nfo0'}).text) except: - pass + description = '' new = { 'id': nzbindex_id, @@ -81,15 +76,16 @@ class NzbIndex(NZBProvider, RSS): 'url': enclosure['url'], 'detail_url': enclosure['url'].replace('/download/', '/release/'), 'description': description, + 'get_more_info': self.getMoreInfo, 'check_nzb': True, } - new['score'] = fireEvent('score.calculate', new, movie, single = True) is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, imdb_results = False, single_category = False, single = True) if is_correct_movie: + new['score'] = fireEvent('score.calculate', new, movie, single = True) results.append(new) self.found(new) @@ -99,6 +95,15 @@ class NzbIndex(NZBProvider, RSS): return results + def getMoreInfo(self, item): + try: + if '/nfo/' in item['description'].lower(): + nfo_url = re.search('href=\"(?P.+)\" ', item['description']).group('nfo') + full_description = self.getCache('nzbindex.%s' % item['id'], url = nfo_url, cache_timeout = 25920000) + html = BeautifulSoup(full_description) + item['description'] = toUnicode(html.find('pre', attrs = {'id':'nfo0'}).text) + except: + pass def isEnabled(self): return NZBProvider.isEnabled(self) and self.conf('enabled') diff --git a/couchpotato/core/providers/nzb/nzbmatrix/main.py b/couchpotato/core/providers/nzb/nzbmatrix/main.py index 2a6e5a8..c1e579c 100644 --- a/couchpotato/core/providers/nzb/nzbmatrix/main.py +++ b/couchpotato/core/providers/nzb/nzbmatrix/main.py @@ -83,13 +83,13 @@ class NZBMatrix(NZBProvider, RSS): 'description': self.getTextElement(nzb, "description"), 'check_nzb': True, } - new['score'] = fireEvent('score.calculate', new, movie, single = True) is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, imdb_results = True, single_category = single_cat, single = True) if is_correct_movie: + new['score'] = fireEvent('score.calculate', new, movie, single = True) results.append(new) self.found(new)