From f0c1f57673779271d145854a73c5e9e8dba3b12f Mon Sep 17 00:00:00 2001 From: bwq Date: Tue, 11 Oct 2011 21:40:50 +0200 Subject: [PATCH] Added the #alt.binaries.hdtv.x264 provider. Added error handling for faulty/empty nzbs and file handling for rarred nzbs. --- .gitignore | 3 +- couchpotato/core/downloaders/blackhole/main.py | 10 +++ couchpotato/core/providers/nzb/x264/__init__.py | 20 ++++++ couchpotato/core/providers/nzb/x264/main.py | 89 +++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 couchpotato/core/providers/nzb/x264/__init__.py create mode 100644 couchpotato/core/providers/nzb/x264/main.py diff --git a/.gitignore b/.gitignore index 217a73c..8a4b7fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /settings.conf /logs/*.log /_source/ -/_data/ \ No newline at end of file +/_data/ +*.pyc diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index f4357e7..d940e94 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -29,6 +29,16 @@ class Blackhole(Downloader): try: file = data.get('download')(url = data.get('url'), nzb_id = data.get('id')) + # error handling for nzbs that aren't available + if "no nzb" in file: + log.error('No nzb available!') + return False + + # some providers provide nzbs that are rarred, save these with the proper extension + if "DOCTYPE nzb" not in file: + if data.get('type') == 'nzb': + fullPath = os.path.join(directory, '%s%s.%s' % (toSafeString(data.get('name')), self.cpTag(movie) , 'rar')) + with open(fullPath, 'wb') as f: f.write(file) except: diff --git a/couchpotato/core/providers/nzb/x264/__init__.py b/couchpotato/core/providers/nzb/x264/__init__.py new file mode 100644 index 0000000..cf65b0a --- /dev/null +++ b/couchpotato/core/providers/nzb/x264/__init__.py @@ -0,0 +1,20 @@ +from .main import X264 + +def start(): + return X264() + +config = [{ + 'name': 'x264', + 'groups': [ + { + 'tab': 'providers', + 'name': '#alt.binaries.hdtv.x264', + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/nzb/x264/main.py b/couchpotato/core/providers/nzb/x264/main.py new file mode 100644 index 0000000..0382acd --- /dev/null +++ b/couchpotato/core/providers/nzb/x264/main.py @@ -0,0 +1,89 @@ +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.rss import RSS +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.nzb.base import NZBProvider +from dateutil.parser import parse +from imdb.parser.http.bsouplxml._bsoup import SoupStrainer, BeautifulSoup +import urllib +import urllib2 +from urllib import urlencode +from urllib import quote_plus +import time +import re + +log = CPLog(__name__) + + +class X264(NZBProvider, RSS): + + urls = { + 'download': 'http://85.214.105.230/get_nzb.php?id=%s§ion=hd', + 'search': 'http://85.214.105.230/x264/requests.php?release=%s&status=FILLED&age=700&sort=ID', + 'regex': '(?P.*?)(?P.*?)</td>', + } + + def search(self, movie, quality): + + results = [] + if self.isDisabled() or not self.isAvailable(self.urls['search']): + return results + + url = self.urls['search'] % quote_plus(movie['library']['titles'][0]['title'] + ' ' + quality.get('identifier')) + log.info('Searching: %s' % url) + + try: + opener = urllib2.build_opener() + urllib2.install_opener(opener) + f = opener.open(url) + data = f.read() + f.close() + + except (IOError, URLError): + log.error('Failed to open %s.' % url) + return results + + match = re.compile(self.urls['regex'], re.DOTALL ).finditer(data) + + for nzb in match: + new = { + 'id': nzb.group('id'), + 'name': nzb.group('title'), + 'type': 'nzb', + 'provider': self.getName(), + 'age': self.calculateAge(time.time()), + 'size': 9999, + 'url': self.urls['download'] % (nzb.group('id')), + 'download': self.download, + 'detail_url': '', + '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) + return results + + def download(self, url = '', nzb_id = ''): + try: + log.info('Download nzb from #alt.binaries.hdtv.x264, report id: %s ' % nzb_id) + + return self.urlopen(self.urls['download'] % nzb_id) + except Exception, e: + log.error('Failed downloading from #alt.binaries.hdtv.x264, check credit: %s' % e) + return False + + def getFormatId(self, format): + for id, quality in self.format_ids.iteritems(): + for q in quality: + if q == format: + return id + + return self.cat_backup_id + + def isEnabled(self): + return NZBProvider.isEnabled(self) and self.conf('enabled')