From 6ffeb24887f59343a98170e502345711c21b02bb Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 3 Feb 2012 17:21:26 +0100 Subject: [PATCH] MysterBin provider --- .../core/providers/nzb/mysterbin/__init__.py | 22 +++++ .../core/providers/nzb/mysterbin/main.py | 99 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 couchpotato/core/providers/nzb/mysterbin/__init__.py create mode 100644 couchpotato/core/providers/nzb/mysterbin/main.py diff --git a/couchpotato/core/providers/nzb/mysterbin/__init__.py b/couchpotato/core/providers/nzb/mysterbin/__init__.py new file mode 100644 index 00000000..07be1d4e --- /dev/null +++ b/couchpotato/core/providers/nzb/mysterbin/__init__.py @@ -0,0 +1,22 @@ +from .main import Mysterbin + +def start(): + return Mysterbin() + +config = [{ + 'name': 'mysterbin', + 'groups': [ + { + 'tab': 'providers', + 'name': 'Mysterbin', + 'description': '', + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/nzb/mysterbin/main.py b/couchpotato/core/providers/nzb/mysterbin/main.py new file mode 100644 index 00000000..2b59fc57 --- /dev/null +++ b/couchpotato/core/providers/nzb/mysterbin/main.py @@ -0,0 +1,99 @@ +from BeautifulSoup import BeautifulSoup, SoupStrainer +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.nzb.base import NZBProvider +from couchpotato.environment import Env +import urllib + +log = CPLog(__name__) + + +class Mysterbin(NZBProvider): + + urls = { + 'search': 'http://www.mysterbin.com/advsearch?%s', + 'download': 'http://www.mysterbin.com/nzb?c=%s', + 'nfo': 'http://www.mysterbin.com/nfo?c=%s', + } + + http_time_between_calls = 1 #seconds + + def search(self, movie, quality): + + results = [] + if self.isDisabled() or not self.isAvailable(self.urls['search']): + return results + + q = '"%s" %s %s' % (movie['library']['titles'][0]['title'], movie['library']['year'], quality.get('identifier')) + for ignored in Env.setting('ignored_words', 'searcher').split(','): + q = '%s -%s' % (q, ignored.strip()) + + params = { + 'q': q, + 'match': 'normal', + 'minSize': quality.get('size_min'), + 'maxSize': quality.get('size_max'), + 'complete': 2, + 'maxAge': Env.setting('retention', 'nzb'), + 'nopasswd': 'on', + } + + cache_key = 'mysterbin.%s' % q + data = self.getCache(cache_key, self.urls['search'] % urllib.urlencode(params)) + if data: + + try: + html = BeautifulSoup(data) + resultable = html.find('table', attrs = {'class':'t'}) + for result in resultable.findAll('tr'): + + try: + myster_id = result.find('input', attrs = {'class': 'check4nzb'})['value'] + + # Age + age = '' + for temp in result.find('td', attrs = {'class': 'cdetail'}).findAll(text = True): + if 'days' in temp: + age = tryInt(temp.split(' ')[0]) + break + + # size + size = None + for temp in result.find('div', attrs = {'class': 'cdetail'}).findAll(text = True): + if 'gb' in temp.lower() or 'mb' in temp.lower() or 'kb' in temp.lower(): + size = self.parseSize(temp) + break + + description = '' + if result.find('a', text = 'View NFO'): + description = toUnicode(self.getCache('mysterbin.%s' % myster_id, self.urls['nfo'] % myster_id, timeout = 25920000)) + + new = { + 'id': myster_id, + 'name': ''.join(result.find('span', attrs = {'class': 'cname'}).findAll(text = True)), + 'type': 'nzb', + 'provider': self.getName(), + 'age': age, + 'size': size, + 'url': self.urls['download'] % myster_id, + 'description': 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 = False, single_category = False, single = True) + if is_correct_movie: + results.append(new) + self.found(new) + except: + pass + + return [] + except AttributeError: + log.debug('No search results found.') + + return results