Piratebay with multiple domains

This commit is contained in:
Janez Troha committed 2012-07-02 00:44:53 +02:00
1 parent 7b53c4cde1
commit 7e7f319609
2 files changed
+150 -121

No files matched your search

@@ -1,6 +1,38 @@
from .main import ThePirateBay #!/usr/bin/python
# -*- coding: utf-8 -*-
from main import ThePirateBay
def start(): def start():
return ThePirateBay() return ThePirateBay()
config = []
config = [{'name': 'ThePirateBay', 'groups': [{
'tab': 'searcher',
'subtab': 'providers',
'name': 'ThePirateBay',
'description': 'The world\'s largest bittorrent tracker.',
'options': [{'name': 'enabled', 'type': 'enabler',
'default': False}, {
'name': 'domain_for_tpb',
'label': 'Proxy server',
'default': 'http://thepiratebay.se',
'description': 'Which domain do you preferr(or it\'s not blocked)',
'type': 'dropdown',
'values': [
('(Sweden) thepiratebay.se', 'http://thepiratebay.se'),
('(Sweden) tpb.ipredator.se (ssl)',
'https://tpb.ipredator.se'),
('(Germany) depiraatbaai.be', 'http://depiraatbaai.be'),
('(UK) piratereverse.info (ssl)',
'https://piratereverse.info'),
('(UK) tpb.pirateparty.org.uk (ssl)',
'https://tpb.pirateparty.org.uk'),
('(Netherlands) thepiratebay.se.coevoet.nl',
'http://thepiratebay.se.coevoet.nl'),
('(direct) 194.71.107.80', 'http://194.71.107.80'),
('(direct) 194.71.107.83', 'http://194.71.107.81'),
],
}],
}]}]
@@ -1,146 +1,143 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
from couchpotato.core.event import fireEvent
from couchpotato.core.helpers.variable import getTitle
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.providers.torrent.base import TorrentProvider from couchpotato.core.providers.torrent.base import TorrentProvider
import re
from urllib import quote_plus
import urllib2
log = CPLog(__name__) log = CPLog(__name__)
class ThePirateBay(TorrentProvider): class ThePirateBay(TorrentProvider):
urls = { urls = {'detail': '%s/torrent/%s', 'search': '%s/search/%s/0/7/%d'}
'download': 'http://torrents.depiraatbaai.be/%s/%s.torrent',
'nfo': 'https://depiraatbaai.be/torrent/%s',
'detail': 'https://depiraatbaai.be/torrent/%s',
'search': 'https://depiraatbaai.be/search/%s/0/7/%d',
}
cat_ids = [ cat_ids = [([207], ['720p', '1080p']), ([201], [
([207], ['720p', '1080p']), 'cam',
([200], ['cam', 'ts', 'dvdrip', 'tc', 'r5', 'scr', 'brrip']), 'ts',
([202], ['dvdr']) 'dvdrip',
] 'tc',
'r5',
'scr',
'brrip',
]), ([202], ['dvdr'])]
cat_backup_id = 200 cat_backup_id = 200
ignore_string = { def getAPIurl(self):
'720p': ' -brrip -bdrip', return ("http://thepiratebay.se", self.conf('domain_for_tpb'))[self.conf('domain_for_tpb') != None]
'1080p': ' -brrip -bdrip'
}
def __init__(self): def search(self, movie, quality):
pass
def find(self, movie, quality, type):
results = [] results = []
if not self.enabled(): if self.isDisabled():
return results return results
url = self.apiUrl % (quote_plus(self.toSearchString(movie.name + ' ' + quality) + self.makeIgnoreString(type)), self.getCatId(type)) movie_name = re.sub("\W", ' ', getTitle(movie['library']))
movie_name = re.sub(' ', ' ', movie_name)
log.info('Searching: %s', url) log.info('API url: %s', self.getAPIurl())
log.info('Cleaned Name: %s', movie_name)
data = self.urlopen(url) cache_key = 'thepiratebay.%s.%s' % (movie['library'
]['identifier'], quality.get('identifier'))
searchUrl = self.urls['search'] % (self.getAPIurl(),
quote_plus(movie_name + ' ' + quality['identifier']),
self.getCatId(quality['identifier'])[0])
log.info('searchUrl: %s', searchUrl)
data = self.getCache(cache_key, searchUrl)
#print data
if not data: if not data:
log.error('Failed to get data from %s.', url) log.error('Failed to get data from %s.', searchUrl)
return results return results
try: try:
tables = SoupStrainer('table') soup = BeautifulSoup(data)
html = BeautifulSoup(data, parseOnlyThese = tables) resultsTable = soup.find('table',
resultTable = html.find('table', attrs = {'id':'searchResult'}) attrs={'id': 'searchResult'})
for result in resultTable.findAll('tr'): entries = resultsTable.findAll('tr')
details = result.find('a', attrs = {'class':'detLink'}) for result in entries[1:]:
if details: link = result.find(href=re.compile('torrent\/\d+\/'))
href = re.search('/(?P<id>\d+)/', details['href']) download = result.find(href=re.compile('magnet:'))
id = href.group('id') #Uploaded 06-28 02:27, Size 1.37 GiB,
name = self.toSaveString(details.contents[0]) size = re.search('Size (?P<size>.+),', unicode(result.select("font.detDesc")[0])).group("size")
desc = result.find('font', attrs = {'class':'detDesc'}).contents[0].split(',') if link and download:
date = '' new = {
size = 0 'type': 'torrent',
for item in desc: 'check_nzb': False,
# Weird date stuff 'description': '',
if 'uploaded' in item.lower(): 'provider': self.getName(),
date = item.replace('Uploaded', '') }
date = date.replace('Today', '') trusted = (0, 10)[result.find('img',
alt=re.compile('Trusted')) != None]
vip = (0, 20)[result.find('img',
alt=re.compile('VIP')) != None]
moderated = (0, 50)[result.find('img',
alt=re.compile('Moderator')) != None]
log.info('Name: %s', link.string)
# Do something with yesterday log.info('Seeders: %s', result.findAll('td'
yesterdayMinus = 0 )[2].string)
if 'Y-day' in date: log.info('Leechers: %s', result.findAll('td'
date = date.replace('Y-day', '') )[3].string)
yesterdayMinus = 86400 log.info('Size: %s', size)
log.info('Score(trusted + vip + moderated): %d',
trusted + vip + moderated)
datestring = date.replace('&nbsp;', ' ').strip() new['name'] = link.string
date = int(time.mktime(parse(datestring).timetuple())) - yesterdayMinus new['id'] = re.search('/(?P<id>\d+)/', link['href'
# size ]).group('id')
elif 'size' in item.lower(): new['url'] = link['href']
size = item.replace('Size', '') new['download'] = self.getAPIurl() + download['href']
new['size'] = self.parseSize(size)
new['seeders'] = int(result.findAll('td')[2].string)
new['leechers'] = int(result.findAll('td'
)[3].string)
new['imdbid'] = movie['library']['identifier']
new['prtbscore'] = trusted + vip + moderated
seedleech = [] new['extra_score'] = self.extra_score
for td in result.findAll('td'): new['score'] = fireEvent('score.calculate', new,
try: movie, single=True)
seedleech.append(int(td.contents[0])) is_correct_movie = fireEvent(
except ValueError: 'searcher.correct_movie',
pass nzb=new,
movie=movie,
quality=quality,
imdb_results=True,
single_category=False,
single=True,
)
seeders = 0 if is_correct_movie:
leechers = 0 results.append(new)
if len(seedleech) == 2 and seedleech[0] > 0 and seedleech[1] > 0: self.found(new)
seeders = seedleech[0]
leechers = seedleech[1]
# to item
new = self.feedItem()
new.id = id
new.type = 'torrent'
new.name = name
new.date = date
new.size = self.parseSize(size)
new.seeders = seeders
new.leechers = leechers
new.url = self.downloadLink(id, name)
new.score = self.calcScore(new, movie) + self.uploader(result) + (seeders / 10)
if seeders > 0 and (new.date + (int(self.conf('wait')) * 60 * 60) < time.time()) and Qualities.types.get(type).get('minSize') <= new.size:
new.detailUrl = self.detailLink(id)
new.content = self.getInfo(new.detailUrl)
if self.isCorrectMovie(new, movie, type):
results.append(new)
log.info('Found: %s', new.name)
return results return results
except Exception, e:
log.debug(e)
log.info('Error occured during parsing! Passing only processed entries'
)
return results
except AttributeError: def extra_score(self, torrent):
log.debug('No search results found.') url = self.getAPIurl() + torrent['url']
log.info('extra_score: %s', url)
imdbId = torrent['imdbid']
return self.imdbMatch(url, imdbId) + torrent['prtbscore']
return [] def imdbMatch(self, url, imdbId):
log.info('imdbMatch: %s', url)
def makeIgnoreString(self, type): try:
ignore = self.ignoreString.get(type) data = urllib2.urlopen(url).read()
return ignore if ignore else '' pass
except:
def uploader(self, html): log.error('Failed to open %s.' % url)
score = 0 return 0
if html.find('img', attr = {'alt':'VIP'}): imdbIdAlt = re.sub('tt[0]*', 'tt', imdbId)
score += 3 data = unicode(data, errors='ignore')
if html.find('img', attr = {'alt':'Trusted'}): if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' \
score += 1 + imdbIdAlt in data:
return score return 50
return 0
def getInfo(self, url):
log.debug('Getting info: %s', url)
data = self.urlopen(url)
if not data:
log.error('Failed to get data from %s.', url)
return ''
div = SoupStrainer('div')
html = BeautifulSoup(data, parseOnlyThese = div)
html = html.find('div', attrs = {'class':'nfo'})
return str(html).decode("utf-8", "replace")
def downloadLink(self, id, name):
return self.downloadUrl % (id, quote_plus(name))
def isEnabled(self):
return self.conf('enabled') and TorrentProvider.isEnabled(self)