Some minor improvements

- Now uses authkey+passkey in torrent urls, so it should support sending torrents to external clients such as Tranmission
- Fixed all remaster versions showing up as 's' in the torrent name
- Fixed duplicate request when a request is done while not being logged in to ptp
- Allow '.' character in torrent names
This commit is contained in:
Rembrand van Lakwijk
2012-08-13 14:23:23 +02:00
committed by Ruud
parent ca358d28ee
commit 39903314e4
2 changed files with 18 additions and 8 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
*.pyc *.pyc
/data/ /data/
/_source/ /_source/
.project
.pydevproject

View File

@@ -105,14 +105,14 @@ class PassThePopcorn(TorrentProvider):
return False return False
if response.getcode() == 200: if response.getcode() == 200:
log.info('Login HTTP status 200; seems successful') log.info('Login HTTP status 200; seems successful')
return True return response
else: else:
log.error('Login to passthepopcorn failed: returned code %d' % response.getcode()) log.error('Login to passthepopcorn failed: returned code %d' % response.getcode())
return False return False
def protected_request(self, url): def protected_request(self, url):
log.debug('Retrieving %s' % url) log.debug('Retrieving %s' % url)
maxattempts = 3 maxattempts = 2
while maxattempts > 0: while maxattempts > 0:
try: try:
response = self.opener.open(url) response = self.opener.open(url)
@@ -123,10 +123,16 @@ class PassThePopcorn(TorrentProvider):
return None return None
return txt return txt
except PassThePopcorn.NotLoggedInHTTPError as e: except PassThePopcorn.NotLoggedInHTTPError as e:
if not self.login(): # if we can login, just retry loginResult = self.login()
if not loginResult: # if we can login, just retry
log.error('Login failed, could not execute request %s' % url) log.error('Login failed, could not execute request %s' % url)
return None return None
log.debug("Should now be logged into passthepopcorn.me, trying request again...") else:
if loginResult.geturl() == url:
log.info('Login redirected to desired URL; success!')
return loginResult.read()
else:
log.info("Login seems to have succeeded, but got redirected to '%s' while we actually want to visit '%s'; retrying the request" % (loginResult.geturl(), url))
except urllib2.URLError as e: except urllib2.URLError as e:
log.error('Retrieving JSON from url %s failed: %s' % (url, e)) log.error('Retrieving JSON from url %s failed: %s' % (url, e))
return None return None
@@ -233,6 +239,8 @@ class PassThePopcorn(TorrentProvider):
log.info("PTP search returned nothing for '%s' at quality '%s' with search parameters %s" % (movieTitle, qualityID, params)) log.info("PTP search returned nothing for '%s' at quality '%s' with search parameters %s" % (movieTitle, qualityID, params))
return [] return []
log.info('PTP search returned %d movies' % len(res['Movies'])) log.info('PTP search returned %d movies' % len(res['Movies']))
authkey = res['AuthKey']
passkey = res['PassKey']
results = [] results = []
for ptpmovie in res['Movies']: for ptpmovie in res['Movies']:
if not 'Torrents' in ptpmovie: if not 'Torrents' in ptpmovie:
@@ -247,14 +255,14 @@ class PassThePopcorn(TorrentProvider):
torrentdesc += ' Scene' torrentdesc += ' Scene'
if 'RemasterTitle' in torrent and torrent['RemasterTitle']: if 'RemasterTitle' in torrent and torrent['RemasterTitle']:
# eliminate odd characters... # eliminate odd characters...
torrentdesc += self.htmltoascii(' %s') torrentdesc += self.htmltoascii(' %s' % torrent['RemasterTitle'])
torrentdesc += ' %s' % qualityID # this is really just to make CouchPotato not reject torrents we filtered ourselves using our own CPS->PTPSearch rules torrentdesc += ' %s' % qualityID # this is really just to make CouchPotato not reject torrents we filtered ourselves using our own CPS->PTPSearch rules
if not self.torrent_meets_quality_spec(torrent, type): if not self.torrent_meets_quality_spec(torrent, type):
log.info('Ignoring \'%s\' because it does not meet the quality spec of \'%s\'' % (torrentName, qualityID)) log.info('Ignoring \'%s\' because it does not meet the quality spec of \'%s\'' % (torrentName, qualityID))
continue continue
# if we know the IMDB id, this must be the correct name. This avoids failing the CouchPotato name check if we know for certain we have the correct movie. # if we know the IMDB id, this must be the correct name. This avoids failing the CouchPotato name check if we know for certain we have the correct movie.
torrentNameMovieTitle = movieTitle if imdbID else self.htmltoascii(ptpmovie['Title']) torrentNameMovieTitle = movieTitle if imdbID else self.htmltoascii(ptpmovie['Title'])
torrentName = re.sub('[^A-Za-z0-9\-_ \(\)]+', '', '%s (%s) - %s' % (torrentNameMovieTitle, ptpmovie['Year'], torrentdesc)) torrentName = re.sub('[^A-Za-z0-9\-_ \(\).]+', '', '%s (%s) - %s' % (torrentNameMovieTitle, ptpmovie['Year'], torrentdesc))
new = { new = {
'id': int(torrent['Id']), 'id': int(torrent['Id']),
'type': 'torrent', 'type': 'torrent',
@@ -271,7 +279,7 @@ class PassThePopcorn(TorrentProvider):
'extra_score': (lambda torrent: (50 if torrent['torrentjson']['GoldenPopcorn'] else 0)), 'extra_score': (lambda torrent: (50 if torrent['torrentjson']['GoldenPopcorn'] else 0)),
'download': self.download, 'download': self.download,
} }
new['url'] = 'https://%s/torrents.php?action=download&id=%d' % (self.domain, new['id']) new['url'] = 'https://%s/torrents.php?action=download&id=%d&authkey=%s&torrent_pass=%s' % (self.domain, new['id'], authkey, passkey)
new['score'] = fireEvent('score.calculate', new, movie, single=True) new['score'] = fireEvent('score.calculate', new, movie, single=True)
if fireEvent('searcher.correct_movie', nzb=new, movie=movie, quality=quality): if fireEvent('searcher.correct_movie', nzb=new, movie=movie, quality=quality):
results.append(new) results.append(new)