From 1a63baaa139fa6a69f1c1c1fc5612f56b207b076 Mon Sep 17 00:00:00 2001 From: bwq Date: Wed, 20 Jun 2012 20:26:54 +0200 Subject: [PATCH 1/2] Added 3 torrent providers - SceneAccess, SceneHD and TorrentLeech --- .../providers/torrent/sceneaccess/__init__.py | 31 ++++ .../providers/torrent/sceneaccess/main.py | 134 ++++++++++++++++++ .../providers/torrent/scenehd/__init__.py | 31 ++++ .../core/providers/torrent/scenehd/main.py | 119 ++++++++++++++++ .../torrent/torrentleech/__init__.py | 31 ++++ .../providers/torrent/torrentleech/main.py | 133 +++++++++++++++++ 6 files changed, 479 insertions(+) create mode 100644 couchpotato/core/providers/torrent/sceneaccess/__init__.py create mode 100644 couchpotato/core/providers/torrent/sceneaccess/main.py create mode 100644 couchpotato/core/providers/torrent/scenehd/__init__.py create mode 100644 couchpotato/core/providers/torrent/scenehd/main.py create mode 100644 couchpotato/core/providers/torrent/torrentleech/__init__.py create mode 100644 couchpotato/core/providers/torrent/torrentleech/main.py diff --git a/couchpotato/core/providers/torrent/sceneaccess/__init__.py b/couchpotato/core/providers/torrent/sceneaccess/__init__.py new file mode 100644 index 00000000..385f015f --- /dev/null +++ b/couchpotato/core/providers/torrent/sceneaccess/__init__.py @@ -0,0 +1,31 @@ +from .main import SceneAccess + +def start(): + return SceneAccess() + +config = [{ + 'name': 'sceneaccess', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'providers', + 'name': 'SceneAccess', + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'password', + 'default': '', + 'type': 'password', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/sceneaccess/main.py b/couchpotato/core/providers/torrent/sceneaccess/main.py new file mode 100644 index 00000000..d42a7b07 --- /dev/null +++ b/couchpotato/core/providers/torrent/sceneaccess/main.py @@ -0,0 +1,134 @@ +from bs4 import BeautifulSoup +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.variable import tryInt, getTitle +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.torrent.base import TorrentProvider +import StringIO +import gzip +import re +import traceback +import urllib +import urllib2 +import cookielib +from urllib import quote_plus +from urllib2 import URLError + +log = CPLog(__name__) + + +class SceneAccess(TorrentProvider): + + urls = { + 'test': 'https://www.sceneaccess.eu/', + 'detail': 'https://www.sceneaccess.eu/details?id=%s', + 'search': 'https://www.sceneaccess.eu/browse?search=%s&method=2&c%d=%d', + 'download': 'https://www.sceneaccess.eu/%s', + } + + cat_ids = [ + ([22], ['720p', '1080p']), + ([7], ['cam', 'ts', 'dvdrip', 'tc', 'r5', 'scr', 'brrip']), + ([8], ['dvdr']), + ] + + http_time_between_calls = 1 #seconds + + def search(self, movie, quality): + + results = [] + if self.isDisabled(): + return results + + cache_key = 'sceneaccess.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) + searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0], self.getCatId(quality['identifier'])[0]) + data = self.getCache(cache_key, searchUrl) + + if data: + + cat_ids = self.getCatId(quality['identifier']) + + try: + cookiejar = cookielib.CookieJar() + opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) + urllib2.install_opener(opener) + params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), submit='come on in')) + f = opener.open('https://www.sceneaccess.eu/login', params) + data = f.read() + f.close() + f = opener.open(searchUrl) + data = f.read() + f.close() + + except (IOError, URLError): + log.error('Failed to open %s.' % url) + return results + + html = BeautifulSoup(data) + + try: + resultsTable = html.find('table', attrs = {'id' : 'torrents-table'}) + entries = resultsTable.findAll('tr', attrs = {'class' : 'tt_row'}) + for result in entries: + new = { + 'type': 'torrent', + 'check_nzb': False, + 'description': '', + 'provider': self.getName(), + } + + link = result.find('td', attrs = {'class' : 'ttr_name'}).find('a') + new['name'] = link['title'] + new['id'] = link['href'].replace('details?id=', '') + url = result.find('td', attrs = {'class' : 'td_dl'}).find('a') + new['url'] = self.urls['download'] % url['href'] + new['size'] = self.parseSize(result.find('td', attrs = {'class' : 'ttr_size'}).contents[0]) + new['seeders'] = int(result.find('td', attrs = {'class' : 'ttr_seeders'}).find('a').string) + leechers = result.find('td', attrs = {'class' : 'ttr_leechers'}).find('a') + if leechers: + new['leechers'] = int(leechers.string) + else: + new['leechers'] = 0 + + new['imdbid'] = movie['library']['identifier'] + new['extra_score'] = self.extra_score + 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 = False, single = True) + + if is_correct_movie: + new['download'] = self.download + results.append(new) + self.found(new) + return results + + except: + log.info("No results found at SceneAccess") + return [] + + def extra_score(self, nzb): + url = self.urls['detail'] % nzb['id'] + imdbId = nzb['imdbid'] + return self.imdbMatch(url, imdbId) + + def imdbMatch(self, url, imdbId): + try: + data = urllib2.urlopen(url).read() + pass + except IOError: + log.error('Failed to open %s.' % url) + return '' + + html = BeautifulSoup(data) + imdbDiv = html.find('span', attrs = {'class':'i_link'}) + imdbDiv = str(imdbDiv).decode("utf-8", "replace") + imdbIdAlt = re.sub('tt[0]*', 'tt', imdbId) + + if 'imdb.com/title/' + imdbId in imdbDiv or 'imdb.com/title/' + imdbIdAlt in imdbDiv: + return 50 + return 0 + + def download(self, url = '', nzb_id = ''): + torrent = self.urlopen(url) + return torrent + + diff --git a/couchpotato/core/providers/torrent/scenehd/__init__.py b/couchpotato/core/providers/torrent/scenehd/__init__.py new file mode 100644 index 00000000..010b2784 --- /dev/null +++ b/couchpotato/core/providers/torrent/scenehd/__init__.py @@ -0,0 +1,31 @@ +from .main import SceneHD + +def start(): + return SceneHD() + +config = [{ + 'name': 'scenehd', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'providers', + 'name': 'SceneHD', + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'password', + 'default': '', + 'type': 'password', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/scenehd/main.py b/couchpotato/core/providers/torrent/scenehd/main.py new file mode 100644 index 00000000..4e6d5539 --- /dev/null +++ b/couchpotato/core/providers/torrent/scenehd/main.py @@ -0,0 +1,119 @@ +from bs4 import BeautifulSoup +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.variable import tryInt, getTitle +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.torrent.base import TorrentProvider +import StringIO +import gzip +import re +import traceback +import urllib +import urllib2 +import cookielib +from urllib import quote_plus +from urllib2 import URLError + + +log = CPLog(__name__) + + +class SceneHD(TorrentProvider): + + urls = { + 'test': 'http://scenehd.org/', + 'detail': 'http://scenehd.org/details.php?id=%s', + 'search': 'http://scenehd.org/browse.php?ajax&search=%s', + 'download': 'http://scenehd.org/download.php?id=%s', + } + + http_time_between_calls = 1 #seconds + + def search(self, movie, quality): + + results = [] + if self.isDisabled(): + return results + + cache_key = 'scenehd.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) + searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier'])) + data = self.getCache(cache_key, searchUrl) + + if data: + + try: + cookiejar = cookielib.CookieJar() + opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) + urllib2.install_opener(opener) + params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), ssl='yes')) + f = opener.open('http://scenehd.org/takelogin.php', params) + data = f.read() + f.close() + f = opener.open(searchUrl) + data = f.read() + f.close() + + except (IOError, URLError): + log.error('Failed to open %s.' % url) + return results + + html = BeautifulSoup(data) + + try: + resultsTable = html.findAll('table')[6] + entries = resultsTable.findAll('tr') + for result in entries[1:]: + new = { + 'type': 'torrent', + 'check_nzb': False, + 'description': '', + 'provider': self.getName(), + } + + allCells = result.findAll('td') + new['size'] = self.parseSize(allCells[7].string.replace('GiB', 'GB')) + new['seeders'] = allCells[10].find('a').string + leechers = allCells[11].find('a') + if leechers: + new['leechers'] = leechers.string + else: + new['leechers'] = allCells[11].string + + detailLink = allCells[2].find('a') + details = detailLink['href'] + new['id'] = details.replace('details.php?id=', '') + new['name'] = detailLink['title'] + + imdbLink = allCells[1].find('a') + if imdbLink: + new['imdbresult'] = imdbLink['href'].replace('http://www.imdb.com/title/','').rstrip('/') + else: + new['imdbresult'] = 'tt00000000' + + new['url'] = self.urls['download'] % new['id'] + new['imdbid'] = movie['library']['identifier'] + new['extra_score'] = self.extra_score + 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 = False, single = True) + + if is_correct_movie: + new['download'] = self.download + results.append(new) + self.found(new) + return results + + except: + log.info("No results found at SceneHD") + return [] + + def extra_score(self, nzb): + imdbIdAlt = re.sub('tt[0]*', 'tt', nzb['imdbresult']) + if nzb['imdbresult'] == nzb['imdbid'] or imdbIdAlt == nzb['imdbid']: + return 50 + return 0 + + def download(self, url = '', nzb_id = ''): + torrent = self.urlopen(url) + return torrent + + diff --git a/couchpotato/core/providers/torrent/torrentleech/__init__.py b/couchpotato/core/providers/torrent/torrentleech/__init__.py new file mode 100644 index 00000000..0fb62804 --- /dev/null +++ b/couchpotato/core/providers/torrent/torrentleech/__init__.py @@ -0,0 +1,31 @@ +from .main import TorrentLeech + +def start(): + return TorrentLeech() + +config = [{ + 'name': 'torrentleech', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'providers', + 'name': 'TorrentLeech', + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'password', + 'default': '', + 'type': 'password', + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/torrentleech/main.py b/couchpotato/core/providers/torrent/torrentleech/main.py new file mode 100644 index 00000000..daecc149 --- /dev/null +++ b/couchpotato/core/providers/torrent/torrentleech/main.py @@ -0,0 +1,133 @@ +from bs4 import BeautifulSoup +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.variable import tryInt, getTitle +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.torrent.base import TorrentProvider +import StringIO +import gzip +import re +import traceback +import urllib +import urllib2 +import cookielib +from urllib import quote_plus +from urllib2 import URLError +import sys + + +log = CPLog(__name__) + + +class TorrentLeech(TorrentProvider): + + urls = { + 'test' : 'http://torrentleech.org/', + 'detail' : 'http://torrentleech.org/torrent/%s', + 'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d', + 'download' : 'http://torrentleech.org%s', + } + + cat_ids = [ + ([13], ['720p', '1080p']), + ([8], ['cam']), + ([9], ['ts', 'tc']), + ([10], ['r5', 'scr']), + ([11], ['dvdrip']), + ([14], ['brrip']), + ([12], ['dvdr']), + ] + + http_time_between_calls = 1 #seconds + + def search(self, movie, quality): + + results = [] + if self.isDisabled(): + return results + + cache_key = 'torrentleech.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) + searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0]) + data = self.getCache(cache_key, searchUrl) + + if data: + + cat_ids = self.getCatId(quality['identifier']) + + try: + cookiejar = cookielib.CookieJar() + opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) + urllib2.install_opener(opener) + params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit')) + f = opener.open('http://torrentleech.org/user/account/login/', params) + data = f.read() + f.close() + f = opener.open(searchUrl) + data = f.read() + f.close() + + except (IOError, URLError): + log.error('Failed to open %s.' % url) + return results + + html = BeautifulSoup(data) + + try: + resultsTable = html.find('table', attrs = {'id' : 'torrenttable'}) + entries = resultsTable.findAll('tr') + for result in entries[1:]: + new = { + 'type': 'torrent', + 'check_nzb': False, + 'description': '', + 'provider': self.getName(), + } + + link = result.find('td', attrs = {'class' : 'name'}).find('a') + new['name'] = link.string + new['id'] = link['href'].replace('/torrent/', '') + url = result.find('td', attrs = {'class' : 'quickdownload'}).find('a') + new['url'] = self.urls['download'] % url['href'] + new['size'] = self.parseSize(result.findAll('td')[4].string) + new['seeders'] = int(result.find('td', attrs = {'class' : 'seeders'}).string) + new['leechers'] = int(result.find('td', attrs = {'class' : 'leechers'}).string) + new['imdbid'] = movie['library']['identifier'] + + new['extra_score'] = self.extra_score + 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 = False, single = True) + + if is_correct_movie: + new['download'] = self.download + results.append(new) + self.found(new) + return results + + except: + log.info("No results found at TorrentLeech") + return [] + + def extra_score(self, nzb): + url = self.urls['detail'] % nzb['id'] + imdbId = nzb['imdbid'] + return self.imdbMatch(url, imdbId) + + def imdbMatch(self, url, imdbId): + try: + data = urllib2.urlopen(url).read() + pass + except IOError: + log.error('Failed to open %s.' % url) + return '' + + imdbIdAlt = re.sub('tt[0]*', 'tt', imdbId) + data = unicode(data, errors='ignore') + if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' + imdbIdAlt in data: + return 50 + return 0 + + def download(self, url = '', nzb_id = ''): + torrent = self.urlopen(url) + return torrent + + From 286fce9afd76e00544f1c0ec52a40c55589768b2 Mon Sep 17 00:00:00 2001 From: bwq Date: Fri, 22 Jun 2012 01:36:47 +0200 Subject: [PATCH 2/2] Replaced all tabs. --- .../providers/torrent/sceneaccess/__init__.py | 2 +- .../providers/torrent/sceneaccess/main.py | 86 +++++++-------- .../providers/torrent/scenehd/__init__.py | 2 +- .../core/providers/torrent/scenehd/main.py | 100 +++++++++--------- .../torrent/torrentleech/__init__.py | 2 +- .../providers/torrent/torrentleech/main.py | 86 +++++++-------- 6 files changed, 139 insertions(+), 139 deletions(-) diff --git a/couchpotato/core/providers/torrent/sceneaccess/__init__.py b/couchpotato/core/providers/torrent/sceneaccess/__init__.py index 385f015f..3a128638 100644 --- a/couchpotato/core/providers/torrent/sceneaccess/__init__.py +++ b/couchpotato/core/providers/torrent/sceneaccess/__init__.py @@ -16,7 +16,7 @@ config = [{ 'type': 'enabler', 'default': False, }, - { + { 'name': 'username', 'default': '', }, diff --git a/couchpotato/core/providers/torrent/sceneaccess/main.py b/couchpotato/core/providers/torrent/sceneaccess/main.py index d42a7b07..09d7dfa9 100644 --- a/couchpotato/core/providers/torrent/sceneaccess/main.py +++ b/couchpotato/core/providers/torrent/sceneaccess/main.py @@ -46,64 +46,64 @@ class SceneAccess(TorrentProvider): if data: cat_ids = self.getCatId(quality['identifier']) - - try: - cookiejar = cookielib.CookieJar() - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) - urllib2.install_opener(opener) - params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), submit='come on in')) - f = opener.open('https://www.sceneaccess.eu/login', params) - data = f.read() - f.close() - f = opener.open(searchUrl) - data = f.read() - f.close() - except (IOError, URLError): + try: + cookiejar = cookielib.CookieJar() + opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) + urllib2.install_opener(opener) + params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), submit='come on in')) + f = opener.open('https://www.sceneaccess.eu/login', params) + data = f.read() + f.close() + f = opener.open(searchUrl) + data = f.read() + f.close() + + except (IOError, URLError): log.error('Failed to open %s.' % url) - return results + return results html = BeautifulSoup(data) - try: - resultsTable = html.find('table', attrs = {'id' : 'torrents-table'}) - entries = resultsTable.findAll('tr', attrs = {'class' : 'tt_row'}) - for result in entries: - new = { - 'type': 'torrent', + try: + resultsTable = html.find('table', attrs = {'id' : 'torrents-table'}) + entries = resultsTable.findAll('tr', attrs = {'class' : 'tt_row'}) + for result in entries: + new = { + 'type': 'torrent', 'check_nzb': False, 'description': '', 'provider': self.getName(), } - link = result.find('td', attrs = {'class' : 'ttr_name'}).find('a') - new['name'] = link['title'] - new['id'] = link['href'].replace('details?id=', '') + link = result.find('td', attrs = {'class' : 'ttr_name'}).find('a') + new['name'] = link['title'] + new['id'] = link['href'].replace('details?id=', '') url = result.find('td', attrs = {'class' : 'td_dl'}).find('a') new['url'] = self.urls['download'] % url['href'] - new['size'] = self.parseSize(result.find('td', attrs = {'class' : 'ttr_size'}).contents[0]) - new['seeders'] = int(result.find('td', attrs = {'class' : 'ttr_seeders'}).find('a').string) - leechers = result.find('td', attrs = {'class' : 'ttr_leechers'}).find('a') - if leechers: - new['leechers'] = int(leechers.string) - else: - new['leechers'] = 0 - - new['imdbid'] = movie['library']['identifier'] - new['extra_score'] = self.extra_score - new['score'] = fireEvent('score.calculate', new, movie, single = True) - is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, + new['size'] = self.parseSize(result.find('td', attrs = {'class' : 'ttr_size'}).contents[0]) + new['seeders'] = int(result.find('td', attrs = {'class' : 'ttr_seeders'}).find('a').string) + leechers = result.find('td', attrs = {'class' : 'ttr_leechers'}).find('a') + if leechers: + new['leechers'] = int(leechers.string) + else: + new['leechers'] = 0 + + new['imdbid'] = movie['library']['identifier'] + new['extra_score'] = self.extra_score + 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 = False, single = True) if is_correct_movie: - new['download'] = self.download + new['download'] = self.download results.append(new) self.found(new) - return results + return results - except: - log.info("No results found at SceneAccess") - return [] + except: + log.info("No results found at SceneAccess") + return [] def extra_score(self, nzb): url = self.urls['detail'] % nzb['id'] @@ -123,9 +123,9 @@ class SceneAccess(TorrentProvider): imdbDiv = str(imdbDiv).decode("utf-8", "replace") imdbIdAlt = re.sub('tt[0]*', 'tt', imdbId) - if 'imdb.com/title/' + imdbId in imdbDiv or 'imdb.com/title/' + imdbIdAlt in imdbDiv: - return 50 - return 0 + if 'imdb.com/title/' + imdbId in imdbDiv or 'imdb.com/title/' + imdbIdAlt in imdbDiv: + return 50 + return 0 def download(self, url = '', nzb_id = ''): torrent = self.urlopen(url) diff --git a/couchpotato/core/providers/torrent/scenehd/__init__.py b/couchpotato/core/providers/torrent/scenehd/__init__.py index 010b2784..d4b7a0b8 100644 --- a/couchpotato/core/providers/torrent/scenehd/__init__.py +++ b/couchpotato/core/providers/torrent/scenehd/__init__.py @@ -16,7 +16,7 @@ config = [{ 'type': 'enabler', 'default': False, }, - { + { 'name': 'username', 'default': '', }, diff --git a/couchpotato/core/providers/torrent/scenehd/main.py b/couchpotato/core/providers/torrent/scenehd/main.py index 4e6d5539..497f2d09 100644 --- a/couchpotato/core/providers/torrent/scenehd/main.py +++ b/couchpotato/core/providers/torrent/scenehd/main.py @@ -39,77 +39,77 @@ class SceneHD(TorrentProvider): data = self.getCache(cache_key, searchUrl) if data: - - try: - cookiejar = cookielib.CookieJar() - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) - urllib2.install_opener(opener) - params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), ssl='yes')) - f = opener.open('http://scenehd.org/takelogin.php', params) - data = f.read() - f.close() - f = opener.open(searchUrl) - data = f.read() - f.close() - except (IOError, URLError): + try: + cookiejar = cookielib.CookieJar() + opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) + urllib2.install_opener(opener) + params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), ssl='yes')) + f = opener.open('http://scenehd.org/takelogin.php', params) + data = f.read() + f.close() + f = opener.open(searchUrl) + data = f.read() + f.close() + + except (IOError, URLError): log.error('Failed to open %s.' % url) - return results + return results html = BeautifulSoup(data) - - try: - resultsTable = html.findAll('table')[6] - entries = resultsTable.findAll('tr') - for result in entries[1:]: - new = { - 'type': 'torrent', + + try: + resultsTable = html.findAll('table')[6] + entries = resultsTable.findAll('tr') + for result in entries[1:]: + new = { + 'type': 'torrent', 'check_nzb': False, 'description': '', 'provider': self.getName(), } - allCells = result.findAll('td') - new['size'] = self.parseSize(allCells[7].string.replace('GiB', 'GB')) + allCells = result.findAll('td') + new['size'] = self.parseSize(allCells[7].string.replace('GiB', 'GB')) new['seeders'] = allCells[10].find('a').string - leechers = allCells[11].find('a') - if leechers: - new['leechers'] = leechers.string + leechers = allCells[11].find('a') + if leechers: + new['leechers'] = leechers.string else: - new['leechers'] = allCells[11].string - - detailLink = allCells[2].find('a') - details = detailLink['href'] - new['id'] = details.replace('details.php?id=', '') - new['name'] = detailLink['title'] - - imdbLink = allCells[1].find('a') - if imdbLink: - new['imdbresult'] = imdbLink['href'].replace('http://www.imdb.com/title/','').rstrip('/') - else: - new['imdbresult'] = 'tt00000000' - - new['url'] = self.urls['download'] % new['id'] - new['imdbid'] = movie['library']['identifier'] - new['extra_score'] = self.extra_score - new['score'] = fireEvent('score.calculate', new, movie, single = True) - is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, + new['leechers'] = allCells[11].string + + detailLink = allCells[2].find('a') + details = detailLink['href'] + new['id'] = details.replace('details.php?id=', '') + new['name'] = detailLink['title'] + + imdbLink = allCells[1].find('a') + if imdbLink: + new['imdbresult'] = imdbLink['href'].replace('http://www.imdb.com/title/','').rstrip('/') + else: + new['imdbresult'] = 'tt00000000' + + new['url'] = self.urls['download'] % new['id'] + new['imdbid'] = movie['library']['identifier'] + new['extra_score'] = self.extra_score + 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 = False, single = True) if is_correct_movie: - new['download'] = self.download + new['download'] = self.download results.append(new) self.found(new) - return results + return results - except: - log.info("No results found at SceneHD") - return [] + except: + log.info("No results found at SceneHD") + return [] def extra_score(self, nzb): imdbIdAlt = re.sub('tt[0]*', 'tt', nzb['imdbresult']) if nzb['imdbresult'] == nzb['imdbid'] or imdbIdAlt == nzb['imdbid']: - return 50 + return 50 return 0 def download(self, url = '', nzb_id = ''): diff --git a/couchpotato/core/providers/torrent/torrentleech/__init__.py b/couchpotato/core/providers/torrent/torrentleech/__init__.py index 0fb62804..19627e11 100644 --- a/couchpotato/core/providers/torrent/torrentleech/__init__.py +++ b/couchpotato/core/providers/torrent/torrentleech/__init__.py @@ -16,7 +16,7 @@ config = [{ 'type': 'enabler', 'default': False, }, - { + { 'name': 'username', 'default': '', }, diff --git a/couchpotato/core/providers/torrent/torrentleech/main.py b/couchpotato/core/providers/torrent/torrentleech/main.py index daecc149..0a693dc1 100644 --- a/couchpotato/core/providers/torrent/torrentleech/main.py +++ b/couchpotato/core/providers/torrent/torrentleech/main.py @@ -24,7 +24,7 @@ class TorrentLeech(TorrentProvider): 'test' : 'http://torrentleech.org/', 'detail' : 'http://torrentleech.org/torrent/%s', 'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d', - 'download' : 'http://torrentleech.org%s', + 'download' : 'http://torrentleech.org%s', } cat_ids = [ @@ -46,66 +46,66 @@ class TorrentLeech(TorrentProvider): return results cache_key = 'torrentleech.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) - searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0]) + searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0]) data = self.getCache(cache_key, searchUrl) - if data: + if data: cat_ids = self.getCatId(quality['identifier']) - - try: - cookiejar = cookielib.CookieJar() - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) - urllib2.install_opener(opener) - params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit')) - f = opener.open('http://torrentleech.org/user/account/login/', params) - data = f.read() - f.close() - f = opener.open(searchUrl) - data = f.read() - f.close() - except (IOError, URLError): + try: + cookiejar = cookielib.CookieJar() + opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) + urllib2.install_opener(opener) + params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit')) + f = opener.open('http://torrentleech.org/user/account/login/', params) + data = f.read() + f.close() + f = opener.open(searchUrl) + data = f.read() + f.close() + + except (IOError, URLError): log.error('Failed to open %s.' % url) - return results + return results - html = BeautifulSoup(data) + html = BeautifulSoup(data) try: - resultsTable = html.find('table', attrs = {'id' : 'torrenttable'}) - entries = resultsTable.findAll('tr') - for result in entries[1:]: - new = { - 'type': 'torrent', + resultsTable = html.find('table', attrs = {'id' : 'torrenttable'}) + entries = resultsTable.findAll('tr') + for result in entries[1:]: + new = { + 'type': 'torrent', 'check_nzb': False, 'description': '', 'provider': self.getName(), } - link = result.find('td', attrs = {'class' : 'name'}).find('a') - new['name'] = link.string - new['id'] = link['href'].replace('/torrent/', '') + link = result.find('td', attrs = {'class' : 'name'}).find('a') + new['name'] = link.string + new['id'] = link['href'].replace('/torrent/', '') url = result.find('td', attrs = {'class' : 'quickdownload'}).find('a') new['url'] = self.urls['download'] % url['href'] - new['size'] = self.parseSize(result.findAll('td')[4].string) - new['seeders'] = int(result.find('td', attrs = {'class' : 'seeders'}).string) - new['leechers'] = int(result.find('td', attrs = {'class' : 'leechers'}).string) - new['imdbid'] = movie['library']['identifier'] - - new['extra_score'] = self.extra_score - new['score'] = fireEvent('score.calculate', new, movie, single = True) - is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, + new['size'] = self.parseSize(result.findAll('td')[4].string) + new['seeders'] = int(result.find('td', attrs = {'class' : 'seeders'}).string) + new['leechers'] = int(result.find('td', attrs = {'class' : 'leechers'}).string) + new['imdbid'] = movie['library']['identifier'] + + new['extra_score'] = self.extra_score + 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 = False, single = True) if is_correct_movie: - new['download'] = self.download + new['download'] = self.download results.append(new) self.found(new) - return results + return results - except: - log.info("No results found at TorrentLeech") - return [] + except: + log.info("No results found at TorrentLeech") + return [] def extra_score(self, nzb): url = self.urls['detail'] % nzb['id'] @@ -121,10 +121,10 @@ class TorrentLeech(TorrentProvider): return '' imdbIdAlt = re.sub('tt[0]*', 'tt', imdbId) - data = unicode(data, errors='ignore') - if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' + imdbIdAlt in data: - return 50 - return 0 + data = unicode(data, errors='ignore') + if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' + imdbIdAlt in data: + return 50 + return 0 def download(self, url = '', nzb_id = ''): torrent = self.urlopen(url)