- 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.
This commit is contained in:
@@ -1,5 +1,31 @@
|
|||||||
from couchpotato.core.providers.base import YarrProvider
|
from couchpotato.core.providers.base import YarrProvider
|
||||||
|
from couchpotato.core.logger import CPLog
|
||||||
|
import urllib2
|
||||||
|
import cookielib
|
||||||
|
|
||||||
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TorrentProvider(YarrProvider):
|
class TorrentProvider(YarrProvider):
|
||||||
type = 'torrent'
|
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
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class SceneAccess(TorrentProvider):
|
|||||||
|
|
||||||
urls = {
|
urls = {
|
||||||
'test': 'https://www.sceneaccess.eu/',
|
'test': 'https://www.sceneaccess.eu/',
|
||||||
|
'login' : 'https://www.sceneaccess.eu/login',
|
||||||
'detail': 'https://www.sceneaccess.eu/details?id=%s',
|
'detail': 'https://www.sceneaccess.eu/details?id=%s',
|
||||||
'search': 'https://www.sceneaccess.eu/browse?search=%s&method=2&c%d=%d',
|
'search': 'https://www.sceneaccess.eu/browse?search=%s&method=2&c%d=%d',
|
||||||
'download': 'https://www.sceneaccess.eu/%s',
|
'download': 'https://www.sceneaccess.eu/%s',
|
||||||
@@ -32,6 +33,10 @@ class SceneAccess(TorrentProvider):
|
|||||||
]
|
]
|
||||||
|
|
||||||
http_time_between_calls = 1 #seconds
|
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):
|
def search(self, movie, quality):
|
||||||
|
|
||||||
@@ -40,30 +45,21 @@ class SceneAccess(TorrentProvider):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
cache_key = 'sceneaccess.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
|
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])
|
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()
|
||||||
|
|
||||||
|
opener = self.login(params = loginParams)
|
||||||
|
if not opener:
|
||||||
|
log.info("Couldn't login at SceneAccess")
|
||||||
|
return results
|
||||||
|
|
||||||
data = self.getCache(cache_key, searchUrl)
|
data = self.getCache(cache_key, searchUrl)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
html = BeautifulSoup(data)
|
||||||
cat_ids = self.getCatId(quality['identifier'])
|
|
||||||
|
else:
|
||||||
try:
|
log.info("No results found at SceneAccess")
|
||||||
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
|
|
||||||
|
|
||||||
html = BeautifulSoup(data)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resultsTable = html.find('table', attrs = {'id' : 'torrents-table'})
|
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:
|
if 'imdb.com/title/' + imdbId in imdbDiv or 'imdb.com/title/' + imdbIdAlt in imdbDiv:
|
||||||
return 50
|
return 50
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def download(self, url = '', nzb_id = ''):
|
|
||||||
torrent = self.urlopen(url)
|
|
||||||
return torrent
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class SceneHD(TorrentProvider):
|
|||||||
|
|
||||||
urls = {
|
urls = {
|
||||||
'test': 'http://scenehd.org/',
|
'test': 'http://scenehd.org/',
|
||||||
|
'login' : 'http://scenehd.org/takelogin.php',
|
||||||
'detail': 'http://scenehd.org/details.php?id=%s',
|
'detail': 'http://scenehd.org/details.php?id=%s',
|
||||||
'search': 'http://scenehd.org/browse.php?ajax&search=%s',
|
'search': 'http://scenehd.org/browse.php?ajax&search=%s',
|
||||||
'download': 'http://scenehd.org/download.php?id=%s',
|
'download': 'http://scenehd.org/download.php?id=%s',
|
||||||
@@ -28,6 +29,10 @@ class SceneHD(TorrentProvider):
|
|||||||
|
|
||||||
http_time_between_calls = 1 #seconds
|
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):
|
def search(self, movie, quality):
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
@@ -35,28 +40,21 @@ class SceneHD(TorrentProvider):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
cache_key = 'scenehd.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
|
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)
|
data = self.getCache(cache_key, searchUrl)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
html = BeautifulSoup(data)
|
||||||
try:
|
|
||||||
cookiejar = cookielib.CookieJar()
|
else:
|
||||||
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
|
log.info("No results found at SceneHD")
|
||||||
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)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resultsTable = html.findAll('table')[6]
|
resultsTable = html.findAll('table')[6]
|
||||||
@@ -112,8 +110,4 @@ class SceneHD(TorrentProvider):
|
|||||||
return 50
|
return 50
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def download(self, url = '', nzb_id = ''):
|
|
||||||
torrent = self.urlopen(url)
|
|
||||||
return torrent
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class TorrentLeech(TorrentProvider):
|
|||||||
|
|
||||||
urls = {
|
urls = {
|
||||||
'test' : 'http://torrentleech.org/',
|
'test' : 'http://torrentleech.org/',
|
||||||
|
'login' : 'http://torrentleech.org/user/account/login/',
|
||||||
'detail' : 'http://torrentleech.org/torrent/%s',
|
'detail' : 'http://torrentleech.org/torrent/%s',
|
||||||
'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d',
|
'search' : 'http://torrentleech.org/torrents/browse/index/query/%s/categories/%d',
|
||||||
'download' : 'http://torrentleech.org%s',
|
'download' : 'http://torrentleech.org%s',
|
||||||
@@ -38,6 +39,10 @@ class TorrentLeech(TorrentProvider):
|
|||||||
]
|
]
|
||||||
|
|
||||||
http_time_between_calls = 1 #seconds
|
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):
|
def search(self, movie, quality):
|
||||||
|
|
||||||
@@ -46,30 +51,21 @@ class TorrentLeech(TorrentProvider):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
cache_key = 'torrentleech.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
|
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)
|
data = self.getCache(cache_key, searchUrl)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
html = BeautifulSoup(data)
|
||||||
cat_ids = self.getCatId(quality['identifier'])
|
|
||||||
|
else:
|
||||||
try:
|
log.info("No results found at Torrentleech")
|
||||||
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)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resultsTable = html.find('table', attrs = {'id' : 'torrenttable'})
|
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:
|
if 'imdb.com/title/' + imdbId in data or 'imdb.com/title/' + imdbIdAlt in data:
|
||||||
return 50
|
return 50
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def download(self, url = '', nzb_id = ''):
|
|
||||||
torrent = self.urlopen(url)
|
|
||||||
return torrent
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user