Cache for detail page, more logging exception handling and cleaning the search string

This commit is contained in:
Janez Troha committed 2012-07-01 02:38:54 +02:00
1 parent 615a781be4
commit c6c754f179
1 file changed
+61 -53
@@ -25,6 +25,8 @@ class PublicHD(TorrentProvider):
cat_ids = [([2], ['720p']), ([5], ['1080p']), ([15], ['bdrip']), cat_ids = [([2], ['720p']), ([5], ['1080p']), ([15], ['bdrip']),
([16], ['brrip']), ([16], ['blue-ray'])] ([16], ['brrip']), ([16], ['blue-ray'])]
cat_backup_id = 0
def search(self, movie, quality): def search(self, movie, quality):
results = [] results = []
@@ -39,79 +41,84 @@ class PublicHD(TorrentProvider):
% (quote_plus(movie_name + ' ' % (quote_plus(movie_name + ' '
+ quality['identifier']), + quality['identifier']),
self.getCatId(quality['identifier'])[0]) self.getCatId(quality['identifier'])[0])
log.info('searchUrl: %s', searchUrl)
data = self.getCache(cache_key, searchUrl) data = self.getCache(cache_key, searchUrl)
try: if data:
soup = BeautifulSoup(data) soup = BeautifulSoup(data)
resultsTable = soup.find('table', attrs={'id': 'bgtorrlist2' resultsTable = soup.find('table', attrs={'id': 'bgtorrlist2'
}) })
entries = resultsTable.findAll('tr') entries = resultsTable.findAll('tr')
for result in entries[1:]: for result in entries[2:len(entries) - 1]:
info_url = result.find(href=re.compile('torrent-details' try:
))
download = result.find(href=re.compile('\.torrent'))
date_uploaded = result.findAll('td')[3].string
if info_url and download and date_uploaded:
new = {
'type': 'torrent',
'check_nzb': False,
'description': '',
'provider': self.getName(),
}
log.info('Name: %s', result.findAll('td')[1].string)
log.info('Date uploaded: %s', date_uploaded)
log.info('Seeds: %s', result.findAll('td'
)[4].string)
log.info('Leaches: %s', result.findAll('td'
)[5].string)
log.info('Size: %s', result.findAll('td')[7].string)
url = parse_qs(info_url['href']) info_url = result.find(href=re.compile('torrent-details'
))
download = result.find(href=re.compile('\.torrent'))
new['name'] = info_url.string if info_url and download:
new['id'] = url['id'][0] new = {
new['url'] = self.urls['download'] % download['href' 'type': 'torrent',
] 'check_nzb': False,
new['size'] = self.parseSize(result.findAll('td' 'description': '',
)[7].string) 'provider': self.getName(),
new['seeders'] = int(result.findAll('td')[4].string) }
new['leechers'] = int(result.findAll('td' log.info('Name: %s', result.findAll('td')[1].string)
)[5].string) log.info('Seeds: %s', result.findAll('td'
new['imdbid'] = movie['library']['identifier'] )[4].string)
log.info('Leaches: %s', result.findAll('td'
)[5].string)
log.info('Size: %s', result.findAll('td')[7].string)
new['extra_score'] = self.extra_score url = parse_qs(info_url['href'])
new['score'] = fireEvent('score.calculate', new,
movie, single=True) new['name'] = info_url.string
is_correct_movie = fireEvent( new['id'] = url['id'][0]
'searcher.correct_movie', new['url'] = self.urls['download'] % download['href'
nzb=new, ]
movie=movie, new['size'] = self.parseSize(result.findAll('td'
quality=quality, )[7].string)
imdb_results=True, new['seeders'] = int(result.findAll('td')[4].string)
single_category=False, new['leechers'] = int(result.findAll('td'
single=True, )[5].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)
except Exception, e:
log.debug(e)
log.info("Eroro occured during parsing! Passing only processed entries")
return results
if is_correct_movie:
new['download'] = self.download
results.append(new)
self.found(new)
return results return results
except:
log.info('No results found at PublicHD')
return []
def extra_score(self, req): def extra_score(self, req):
url = self.urls['detail'] % req['id'] url = self.urls['detail'] % req['id']
log.info('extra_score: %s', url)
imdbId = req['imdbid'] imdbId = req['imdbid']
return self.imdbMatch(url, imdbId) return self.imdbMatch(url, imdbId)
def imdbMatch(self, url, imdbId): def imdbMatch(self, url, imdbId):
log.info('imdbMatch: %s', url)
try: try:
data = urllib2.urlopen(url).read() data = self.getCache(url, url)
pass pass
except IOError: except IOError:
log.error('Failed to open %s.' % url) log.error('Failed to open %s.' % url)
@@ -121,9 +128,10 @@ class PublicHD(TorrentProvider):
data = unicode(data, errors='ignore') data = unicode(data, errors='ignore')
if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' \ if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' \
+ imdbIdAlt in data: + imdbIdAlt in data:
return 50 return 500
return 0 return 0
def download(self, url='', nzb_id=''): def download(self, url='', nzb_id=''):
log.info('Downloading: %s', url)
torrent = self.urlopen(url) torrent = self.urlopen(url)
return torrent return torrent