From 3bf3e4bb7f0b8c82c885e3dc0ca53ff599d9d6f7 Mon Sep 17 00:00:00 2001 From: bwq Date: Sat, 23 Jun 2012 04:24:13 +0200 Subject: [PATCH] - Added a new arg for getCache: 'opener', which is a urllib2 opener with a cookiejar installed - The torrent providers now use getCache with the 'opener' argument which they get after a succesful login, this way they can always access the site with proper authentication. --- couchpotato/core/plugins/base.py | 13 ++++++++++++- couchpotato/core/providers/torrent/base.py | 2 +- couchpotato/core/providers/torrent/sceneaccess/main.py | 2 +- couchpotato/core/providers/torrent/scenehd/main.py | 2 +- couchpotato/core/providers/torrent/torrentleech/main.py | 6 +++--- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 2ad616b..68a24a2 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -215,7 +215,18 @@ class Plugin(object): cache_timeout = kwargs.get('cache_timeout') del kwargs['cache_timeout'] - data = self.urlopen(url, **kwargs) + if kwargs.get('opener'): + opener = kwargs.get('opener') + del kwargs['opener'] + + if opener: + log.info('Opening url: %s', url) + f = opener.open(url) + data = f.read() + f.close() + else: + data = self.urlopen(url, **kwargs) + if data: self.setCache(cache_key, data, timeout = cache_timeout) return data diff --git a/couchpotato/core/providers/torrent/base.py b/couchpotato/core/providers/torrent/base.py index 35c902c..a91af44 100644 --- a/couchpotato/core/providers/torrent/base.py +++ b/couchpotato/core/providers/torrent/base.py @@ -16,7 +16,7 @@ class TorrentProvider(YarrProvider): opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) urllib2.install_opener(opener) f = opener.open(self.urls['login'], params) - data = f.read() + loginData = f.read() f.close() except: diff --git a/couchpotato/core/providers/torrent/sceneaccess/main.py b/couchpotato/core/providers/torrent/sceneaccess/main.py index 2bb6944..aba475d 100644 --- a/couchpotato/core/providers/torrent/sceneaccess/main.py +++ b/couchpotato/core/providers/torrent/sceneaccess/main.py @@ -53,7 +53,7 @@ class SceneAccess(TorrentProvider): log.info("Couldn't login at SceneAccess") return results - data = self.getCache(cache_key, searchUrl) + data = self.getCache(cache_key, searchUrl, opener = opener) if data: html = BeautifulSoup(data) diff --git a/couchpotato/core/providers/torrent/scenehd/main.py b/couchpotato/core/providers/torrent/scenehd/main.py index e55dc89..e7cb9db 100644 --- a/couchpotato/core/providers/torrent/scenehd/main.py +++ b/couchpotato/core/providers/torrent/scenehd/main.py @@ -48,7 +48,7 @@ class SceneHD(TorrentProvider): log.error("Couldn't login at SceneHD") return results - data = self.getCache(cache_key, searchUrl) + data = self.getCache(cache_key, searchUrl, opener = opener) if data: html = BeautifulSoup(data) diff --git a/couchpotato/core/providers/torrent/torrentleech/main.py b/couchpotato/core/providers/torrent/torrentleech/main.py index efe2017..88dfce9 100644 --- a/couchpotato/core/providers/torrent/torrentleech/main.py +++ b/couchpotato/core/providers/torrent/torrentleech/main.py @@ -22,7 +22,7 @@ class TorrentLeech(TorrentProvider): urls = { 'test' : 'http://torrentleech.org/', - 'login' : 'http://torrentleech.org/user/account/login/', + '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', @@ -42,7 +42,7 @@ class TorrentLeech(TorrentProvider): def getLoginParams(self): loginParams = urllib.urlencode(dict(username=''+self.conf('username'), password=''+self.conf('password'), remember_me='on', login='submit')) - return loginParams + return loginParams def search(self, movie, quality): @@ -59,7 +59,7 @@ class TorrentLeech(TorrentProvider): log.info("Couldn't login at Torrentleech") return results - data = self.getCache(cache_key, searchUrl) + data = self.getCache(cache_key, searchUrl, opener = opener) if data: html = BeautifulSoup(data)