|
|
@ -22,6 +22,7 @@ class TorrentLeech(TorrentProvider): |
|
|
|
|
|
|
|
urls = { |
|
|
|
'test' : 'http://torrentleech.org/', |
|
|
|
'login' : 'http://torrentleech.org/user/account/login/', |
|
|
|
'detail' : 'http://torrentleech.org/torrent/%s', |
|
|
|
'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d', |
|
|
|
'download' : 'http://torrentleech.org%s', |
|
|
@ -38,6 +39,10 @@ class TorrentLeech(TorrentProvider): |
|
|
|
] |
|
|
|
|
|
|
|
http_time_between_calls = 1 #seconds |
|
|
|
|
|
|
|
def getLoginParams(self): |
|
|
|
loginParams = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit')) |
|
|
|
return loginParams |
|
|
|
|
|
|
|
def search(self, movie, quality): |
|
|
|
|
|
|
@ -46,30 +51,21 @@ 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]) |
|
|
|
data = self.getCache(cache_key, searchUrl) |
|
|
|
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']).replace(':','') + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0]) |
|
|
|
loginParams = self.getLoginParams() |
|
|
|
|
|
|
|
opener = self.login(params = loginParams) |
|
|
|
if not opener: |
|
|
|
log.info("Couldn't login at Torrentleech") |
|
|
|
return results |
|
|
|
|
|
|
|
if data: |
|
|
|
data = self.getCache(cache_key, searchUrl, opener = opener) |
|
|
|
|
|
|
|
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) |
|
|
|
if data: |
|
|
|
html = BeautifulSoup(data) |
|
|
|
|
|
|
|
else: |
|
|
|
log.info("No results found at Torrentleech") |
|
|
|
|
|
|
|
try: |
|
|
|
resultsTable = html.find('table', attrs = {'id' : 'torrenttable'}) |
|
|
@ -89,13 +85,14 @@ class TorrentLeech(TorrentProvider): |
|
|
|
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['leechers'] = int(result.find('td', attrs = {'class' : 'leechers'}).string) |
|
|
|
|
|
|
|
details = self.urls['detail'] % new['id'] |
|
|
|
imdb_results = self.imdbMatch(details, 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) |
|
|
|
imdb_results = imdb_results, single_category = False, single = True) |
|
|
|
|
|
|
|
if is_correct_movie: |
|
|
|
new['download'] = self.download |
|
|
@ -107,10 +104,6 @@ class TorrentLeech(TorrentProvider): |
|
|
|
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: |
|
|
@ -118,16 +111,10 @@ class TorrentLeech(TorrentProvider): |
|
|
|
pass |
|
|
|
except IOError: |
|
|
|
log.error('Failed to open %s.' % url) |
|
|
|
return '' |
|
|
|
return False |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
return True |
|
|
|
return False |
|
|
|