|
@ -1,10 +1,9 @@ |
|
|
from bs4 import BeautifulSoup |
|
|
from bs4 import BeautifulSoup |
|
|
from couchpotato.core.event import fireEvent |
|
|
|
|
|
from couchpotato.core.helpers.encoding import tryUrlencode |
|
|
from couchpotato.core.helpers.encoding import tryUrlencode |
|
|
from couchpotato.core.helpers.variable import getTitle, tryInt |
|
|
from couchpotato.core.helpers.variable import getTitle, tryInt |
|
|
from couchpotato.core.logger import CPLog |
|
|
from couchpotato.core.logger import CPLog |
|
|
|
|
|
from couchpotato.core.providers.base import ResultList |
|
|
from couchpotato.core.providers.torrent.base import TorrentProvider |
|
|
from couchpotato.core.providers.torrent.base import TorrentProvider |
|
|
from urllib import quote_plus |
|
|
|
|
|
import traceback |
|
|
import traceback |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -14,11 +13,11 @@ log = CPLog(__name__) |
|
|
class TorrentLeech(TorrentProvider): |
|
|
class TorrentLeech(TorrentProvider): |
|
|
|
|
|
|
|
|
urls = { |
|
|
urls = { |
|
|
'test' : 'http://torrentleech.org/', |
|
|
'test' : 'http://www.torrentleech.org/', |
|
|
'login' : 'http://torrentleech.org/user/account/login/', |
|
|
'login' : 'http://www.torrentleech.org/user/account/login/', |
|
|
'detail' : 'http://torrentleech.org/torrent/%s', |
|
|
'detail' : 'http://www.torrentleech.org/torrent/%s', |
|
|
'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d', |
|
|
'search' : 'http://www.torrentleech.org/torrents/browse/index/query/%s/categories/%d', |
|
|
'download' : 'http://torrentleech.org%s', |
|
|
'download' : 'http://www.torrentleech.org%s', |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cat_ids = [ |
|
|
cat_ids = [ |
|
@ -36,17 +35,17 @@ class TorrentLeech(TorrentProvider): |
|
|
|
|
|
|
|
|
def search(self, movie, quality): |
|
|
def search(self, movie, quality): |
|
|
|
|
|
|
|
|
results = [] |
|
|
|
|
|
if self.isDisabled(): |
|
|
if self.isDisabled(): |
|
|
return results |
|
|
return [] |
|
|
|
|
|
|
|
|
# Cookie login |
|
|
# Cookie login |
|
|
if not self.login_opener and not self.login(): |
|
|
if not self.login_opener and not self.login(): |
|
|
return results |
|
|
return [] |
|
|
|
|
|
|
|
|
cache_key = 'torrentleech.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) |
|
|
results = ResultList(self, movie, quality) |
|
|
url = self.urls['search'] % (quote_plus(getTitle(movie['library']).replace(':', '') + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0]) |
|
|
|
|
|
data = self.getCache(cache_key, url, opener = self.login_opener) |
|
|
url = self.urls['search'] % (tryUrlencode(getTitle(movie['library']).replace(':', '') + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0]) |
|
|
|
|
|
data = self.getHTMLData(url, opener = self.login_opener) |
|
|
|
|
|
|
|
|
if data: |
|
|
if data: |
|
|
html = BeautifulSoup(data) |
|
|
html = BeautifulSoup(data) |
|
@ -54,7 +53,7 @@ class TorrentLeech(TorrentProvider): |
|
|
try: |
|
|
try: |
|
|
result_table = html.find('table', attrs = {'id' : 'torrenttable'}) |
|
|
result_table = html.find('table', attrs = {'id' : 'torrenttable'}) |
|
|
if not result_table: |
|
|
if not result_table: |
|
|
return results |
|
|
return [] |
|
|
|
|
|
|
|
|
entries = result_table.find_all('tr') |
|
|
entries = result_table.find_all('tr') |
|
|
|
|
|
|
|
@ -64,36 +63,21 @@ class TorrentLeech(TorrentProvider): |
|
|
url = result.find('td', attrs = {'class' : 'quickdownload'}).find('a') |
|
|
url = result.find('td', attrs = {'class' : 'quickdownload'}).find('a') |
|
|
details = result.find('td', attrs = {'class' : 'name'}).find('a') |
|
|
details = result.find('td', attrs = {'class' : 'name'}).find('a') |
|
|
|
|
|
|
|
|
new = { |
|
|
results.append({ |
|
|
'id': link['href'].replace('/torrent/', ''), |
|
|
'id': link['href'].replace('/torrent/', ''), |
|
|
'name': link.string, |
|
|
'name': link.string, |
|
|
'type': 'torrent', |
|
|
|
|
|
'check_nzb': False, |
|
|
|
|
|
'description': '', |
|
|
|
|
|
'provider': self.getName(), |
|
|
|
|
|
'url': self.urls['download'] % url['href'], |
|
|
'url': self.urls['download'] % url['href'], |
|
|
'detail_url': self.urls['download'] % details['href'], |
|
|
'detail_url': self.urls['download'] % details['href'], |
|
|
'download': self.loginDownload, |
|
|
'download': self.loginDownload, |
|
|
'size': self.parseSize(result.find_all('td')[4].string), |
|
|
'size': self.parseSize(result.find_all('td')[4].string), |
|
|
'seeders': tryInt(result.find('td', attrs = {'class' : 'seeders'}).string), |
|
|
'seeders': tryInt(result.find('td', attrs = {'class' : 'seeders'}).string), |
|
|
'leechers': tryInt(result.find('td', attrs = {'class' : 'leechers'}).string), |
|
|
'leechers': tryInt(result.find('td', attrs = {'class' : 'leechers'}).string), |
|
|
} |
|
|
}) |
|
|
|
|
|
|
|
|
imdb_results = self.imdbMatch(self.urls['detail'] % new['id'], movie['library']['identifier']) |
|
|
|
|
|
|
|
|
|
|
|
new['score'] = fireEvent('score.calculate', new, movie, single = True) |
|
|
|
|
|
is_correct_movie = fireEvent('searcher.correct_movie', nzb = new, movie = movie, quality = quality, |
|
|
|
|
|
imdb_results = imdb_results, single = True) |
|
|
|
|
|
|
|
|
|
|
|
if is_correct_movie: |
|
|
|
|
|
results.append(new) |
|
|
|
|
|
self.found(new) |
|
|
|
|
|
|
|
|
|
|
|
return results |
|
|
|
|
|
except: |
|
|
except: |
|
|
log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) |
|
|
log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) |
|
|
|
|
|
|
|
|
return [] |
|
|
return results |
|
|
|
|
|
|
|
|
def getLoginParams(self): |
|
|
def getLoginParams(self): |
|
|
return tryUrlencode({ |
|
|
return tryUrlencode({ |
|
|