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

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