Browse Source

- added global login func for all torrent providers (all private trackers need cookies)

- added global download func (same, downloading also requires cookies)

These 2 functions were necessary to allow the user to download other found releases at a later time.
In the current version this doesn't work because it goes to the url directly, without any cookies
which causes it to download the login page instead of a torrent.

All 3 providers now properly use the cache and have much better error handling.
pull/482/head
bwq 13 years ago
parent
commit
1edf7a1a4f
  1. 26
      couchpotato/core/providers/torrent/base.py
  2. 44
      couchpotato/core/providers/torrent/sceneaccess/main.py
  3. 40
      couchpotato/core/providers/torrent/scenehd/main.py
  4. 44
      couchpotato/core/providers/torrent/torrentleech/main.py

26
couchpotato/core/providers/torrent/base.py

@ -1,5 +1,31 @@
from couchpotato.core.providers.base import YarrProvider
from couchpotato.core.logger import CPLog
import urllib2
import cookielib
log = CPLog(__name__)
class TorrentProvider(YarrProvider):
type = 'torrent'
def login(self, params):
try:
cookiejar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)
f = opener.open(self.urls['login'], params)
data = f.read()
f.close()
except:
log.error('Failed to login.')
return opener
def download(self, url = '', nzb_id = ''):
loginParams = self.getLoginParams()
self.login(params = loginParams)
torrent = self.urlopen(url)
return torrent

44
couchpotato/core/providers/torrent/sceneaccess/main.py

@ -20,6 +20,7 @@ class SceneAccess(TorrentProvider):
urls = {
'test': 'https://www.sceneaccess.eu/',
'login' : 'https://www.sceneaccess.eu/login',
'detail': 'https://www.sceneaccess.eu/details?id=%s',
'search': 'https://www.sceneaccess.eu/browse?search=%s&method=2&c%d=%d',
'download': 'https://www.sceneaccess.eu/%s',
@ -32,6 +33,10 @@ class SceneAccess(TorrentProvider):
]
http_time_between_calls = 1 #seconds
def getLoginParams(self):
loginParams = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), submit='come on in'))
return loginParams
def search(self, movie, quality):
@ -40,30 +45,21 @@ class SceneAccess(TorrentProvider):
return results
cache_key = 'sceneaccess.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0], self.getCatId(quality['identifier'])[0])
data = self.getCache(cache_key, searchUrl)
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']).replace(':','') + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0], self.getCatId(quality['identifier'])[0])
loginParams = self.getLoginParams()
if data:
opener = self.login(params = loginParams)
if not opener:
log.info("Couldn't login at SceneAccess")
return results
cat_ids = self.getCatId(quality['identifier'])
try:
cookiejar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)
params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), submit='come on in'))
f = opener.open('https://www.sceneaccess.eu/login', params)
data = f.read()
f.close()
f = opener.open(searchUrl)
data = f.read()
f.close()
except (IOError, URLError):
log.error('Failed to open %s.' % url)
return results
data = self.getCache(cache_key, searchUrl)
html = BeautifulSoup(data)
if data:
html = BeautifulSoup(data)
else:
log.info("No results found at SceneAccess")
try:
resultsTable = html.find('table', attrs = {'id' : 'torrents-table'})
@ -126,9 +122,3 @@ class SceneAccess(TorrentProvider):
if 'imdb.com/title/' + imdbId in imdbDiv or 'imdb.com/title/' + imdbIdAlt in imdbDiv:
return 50
return 0
def download(self, url = '', nzb_id = ''):
torrent = self.urlopen(url)
return torrent

40
couchpotato/core/providers/torrent/scenehd/main.py

@ -21,6 +21,7 @@ class SceneHD(TorrentProvider):
urls = {
'test': 'http://scenehd.org/',
'login' : 'http://scenehd.org/takelogin.php',
'detail': 'http://scenehd.org/details.php?id=%s',
'search': 'http://scenehd.org/browse.php?ajax&search=%s',
'download': 'http://scenehd.org/download.php?id=%s',
@ -28,6 +29,10 @@ class SceneHD(TorrentProvider):
http_time_between_calls = 1 #seconds
def getLoginParams(self):
loginParams = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), ssl='yes'))
return loginParams
def search(self, movie, quality):
results = []
@ -35,28 +40,21 @@ class SceneHD(TorrentProvider):
return results
cache_key = 'scenehd.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']))
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']).replace(':','') + ' ' + quality['identifier']))
loginParams = self.getLoginParams()
opener = self.login(params = loginParams)
if not opener:
log.error("Couldn't login at SceneHD")
return results
data = self.getCache(cache_key, searchUrl)
if data:
try:
cookiejar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)
params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), ssl='yes'))
f = opener.open('http://scenehd.org/takelogin.php', params)
data = f.read()
f.close()
f = opener.open(searchUrl)
data = f.read()
f.close()
except (IOError, URLError):
log.error('Failed to open %s.' % url)
return results
html = BeautifulSoup(data)
html = BeautifulSoup(data)
else:
log.info("No results found at SceneHD")
try:
resultsTable = html.findAll('table')[6]
@ -112,8 +110,4 @@ class SceneHD(TorrentProvider):
return 50
return 0
def download(self, url = '', nzb_id = ''):
torrent = self.urlopen(url)
return torrent

44
couchpotato/core/providers/torrent/torrentleech/main.py

@ -22,6 +22,7 @@ class TorrentLeech(TorrentProvider):
urls = {
'test' : 'http://torrentleech.org/',
'login' : 'http://torrentleech.org/user/account/login/',
'detail' : 'http://torrentleech.org/torrent/%s',
'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d',
'download' : 'http://torrentleech.org%s',
@ -38,6 +39,10 @@ class TorrentLeech(TorrentProvider):
]
http_time_between_calls = 1 #seconds
def getLoginParams(self):
loginParams = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit'))
return loginParams
def search(self, movie, quality):
@ -46,30 +51,21 @@ class TorrentLeech(TorrentProvider):
return results
cache_key = 'torrentleech.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']) + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0])
searchUrl = self.urls['search'] % (quote_plus(getTitle(movie['library']).replace(':','') + ' ' + quality['identifier']), self.getCatId(quality['identifier'])[0])
loginParams = self.getLoginParams()
opener = self.login(params = loginParams)
if not opener:
log.info("Couldn't login at Torrentleech")
return results
data = self.getCache(cache_key, searchUrl)
if data:
cat_ids = self.getCatId(quality['identifier'])
try:
cookiejar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)
params = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit'))
f = opener.open('http://torrentleech.org/user/account/login/', params)
data = f.read()
f.close()
f = opener.open(searchUrl)
data = f.read()
f.close()
except (IOError, URLError):
log.error('Failed to open %s.' % url)
return results
html = BeautifulSoup(data)
html = BeautifulSoup(data)
else:
log.info("No results found at Torrentleech")
try:
resultsTable = html.find('table', attrs = {'id' : 'torrenttable'})
@ -125,9 +121,3 @@ class TorrentLeech(TorrentProvider):
if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' + imdbIdAlt in data:
return 50
return 0
def download(self, url = '', nzb_id = ''):
torrent = self.urlopen(url)
return torrent

Loading…
Cancel
Save