From 3ac095d359d61a0879539cbbf3d8699568054923 Mon Sep 17 00:00:00 2001 From: sax Date: Tue, 28 May 2013 15:28:51 +0000 Subject: [PATCH 1/5] Added support for Torrent Shack provider. --- .../torrent/torrentshack/__init__.py | 42 +++++++++++ .../providers/torrent/torrentshack/main.py | 75 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 couchpotato/core/providers/torrent/torrentshack/__init__.py create mode 100644 couchpotato/core/providers/torrent/torrentshack/main.py diff --git a/couchpotato/core/providers/torrent/torrentshack/__init__.py b/couchpotato/core/providers/torrent/torrentshack/__init__.py new file mode 100644 index 00000000..2d78da06 --- /dev/null +++ b/couchpotato/core/providers/torrent/torrentshack/__init__.py @@ -0,0 +1,42 @@ +from .main import TorrentShack + +def start(): + return TorrentShack() + +config = [{ + 'name': 'torrentshack', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'providers', + 'list': 'torrent_providers', + 'name': 'TorrentShack', + 'description': 'See TorrentShack', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'password', + 'default': '', + 'type': 'password', + }, + { + 'name': 'extra_score', + 'advanced': True, + 'label': 'Extra Score', + 'type': 'int', + 'default': 0, + 'description': 'Starting score for each release found via this provider.', + } + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/torrentshack/main.py b/couchpotato/core/providers/torrent/torrentshack/main.py new file mode 100644 index 00000000..91a97770 --- /dev/null +++ b/couchpotato/core/providers/torrent/torrentshack/main.py @@ -0,0 +1,75 @@ +from bs4 import BeautifulSoup +from couchpotato.core.helpers.encoding import tryUrlencode +from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.torrent.base import TorrentProvider +import traceback + + +log = CPLog(__name__) + + +class TorrentShack(TorrentProvider): + + urls = { + 'test' : 'http://www.torrentshack.net/', + 'login' : 'http://www.torrentshack.net/login.php', + 'detail' : 'http://www.torrentshack.net/torrent/%s', + 'search' : 'http://www.torrentshack.net/torrents.php?searchstr=%s&filter_cat[%d]=1', + 'download' : 'http://www.torrentshack.net/%s', + } + + cat_ids = [ + ([970], ['bd50']), + ([300], ['720p', '1080p']), + ([350], ['dvdr']), + ([400], ['brrip', 'dvdrip']), + ] + + http_time_between_calls = 1 #seconds + cat_backup_id = None + + def _searchOnTitle(self, title, movie, quality, results): + + url = self.urls['search'] % (tryUrlencode('%s %s' % (title.replace(':', ''), movie['library']['year'])), self.getCatId(quality['identifier'])[0]) + data = self.getHTMLData(url, opener = self.login_opener) + + if data: + html = BeautifulSoup(data) + + try: + result_table = html.find('table', attrs = {'id' : 'torrent_table'}) + if not result_table: + return + + entries = result_table.find_all('tr', attrs = {'class' : 'torrent'}) + + for result in entries[1:]: + + link = result.find('span', attrs = {'class' : 'torrent_name_link'}).parent + url = result.find('td', attrs = {'class' : 'torrent_td'}).find('a') + + results.append({ + 'id': link['href'].replace('torrents.php?torrentid=', ''), + 'name': link.span.string, + 'url': self.urls['download'] % url['href'], + 'detail_url': self.urls['download'] % link['href'], + 'download': self.loginDownload, + 'size': self.parseSize(result.find_all('td')[4].string), + 'seeders': tryInt(result.find_all('td')[6].string), + 'leechers': tryInt(result.find_all('td')[7].string), + }) + + except: + log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) + + def getLoginParams(self): + return tryUrlencode({ + 'username': self.conf('username'), + 'password': self.conf('password'), + 'keeplogged': '1', + 'login': 'Login', + }) + + def loginSuccess(self, output): + return '/logout.php' in output.lower() From ca02c66f26d8fdc5e2d0a15e8d79ba45d123916d Mon Sep 17 00:00:00 2001 From: sax Date: Tue, 28 May 2013 15:33:06 +0000 Subject: [PATCH 2/5] Fixed login success detection. --- couchpotato/core/providers/torrent/torrentshack/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/providers/torrent/torrentshack/main.py b/couchpotato/core/providers/torrent/torrentshack/main.py index 91a97770..2c428e28 100644 --- a/couchpotato/core/providers/torrent/torrentshack/main.py +++ b/couchpotato/core/providers/torrent/torrentshack/main.py @@ -72,4 +72,4 @@ class TorrentShack(TorrentProvider): }) def loginSuccess(self, output): - return '/logout.php' in output.lower() + return 'logout.php' in output.lower() From 631759d833a394128a4790977e743ed8efb36076 Mon Sep 17 00:00:00 2001 From: sax Date: Tue, 28 May 2013 15:33:30 +0000 Subject: [PATCH 3/5] Added configuration option to search over scene releases only. Fixed release name issue (removed ­ element). --- .../torrent/torrentshack/__init__.py | 5 ++++ .../providers/torrent/torrentshack/main.py | 30 ++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/couchpotato/core/providers/torrent/torrentshack/__init__.py b/couchpotato/core/providers/torrent/torrentshack/__init__.py index 2d78da06..1c0d8a12 100644 --- a/couchpotato/core/providers/torrent/torrentshack/__init__.py +++ b/couchpotato/core/providers/torrent/torrentshack/__init__.py @@ -28,6 +28,11 @@ config = [{ 'default': '', 'type': 'password', }, + { + 'name': 'scene only', + 'type': 'bool', + 'default': False + }, { 'name': 'extra_score', 'advanced': True, diff --git a/couchpotato/core/providers/torrent/torrentshack/main.py b/couchpotato/core/providers/torrent/torrentshack/main.py index 2c428e28..08e0faf6 100644 --- a/couchpotato/core/providers/torrent/torrentshack/main.py +++ b/couchpotato/core/providers/torrent/torrentshack/main.py @@ -44,21 +44,29 @@ class TorrentShack(TorrentProvider): entries = result_table.find_all('tr', attrs = {'class' : 'torrent'}) - for result in entries[1:]: + for result in entries: link = result.find('span', attrs = {'class' : 'torrent_name_link'}).parent url = result.find('td', attrs = {'class' : 'torrent_td'}).find('a') - results.append({ - 'id': link['href'].replace('torrents.php?torrentid=', ''), - 'name': link.span.string, - 'url': self.urls['download'] % url['href'], - 'detail_url': self.urls['download'] % link['href'], - 'download': self.loginDownload, - 'size': self.parseSize(result.find_all('td')[4].string), - 'seeders': tryInt(result.find_all('td')[6].string), - 'leechers': tryInt(result.find_all('td')[7].string), - }) + extra_info = '' + if result.find('span', attrs = {'class' : 'torrent_extra_info'}): + extra_info = result.find('span', attrs = {'class' : 'torrent_extra_info'}).text + + if not self.conf('scene only') or extra_info != '[NotScene]': + results.append({ + 'id': link['href'].replace('torrents.php?torrentid=', ''), + 'name': unicode(link.span.string).translate({ord(u'\xad'): None}), + 'url': self.urls['download'] % url['href'], + 'detail_url': self.urls['download'] % link['href'], + 'download': self.loginDownload, + 'size': self.parseSize(result.find_all('td')[4].string), + 'seeders': tryInt(result.find_all('td')[6].string), + 'leechers': tryInt(result.find_all('td')[7].string), + }) + log.info('Adding release %s' % unicode(link.span.string).translate({ord(u'\xad'): None})) + else: + log.info('Not adding release %s [NotScene]' % unicode(link.span.string).translate({ord(u'\xad'): None})) except: log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) From 91e0452320c9a210bd0db7948edff1bc9fdf0e3b Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 29 May 2013 19:03:28 +0200 Subject: [PATCH 4/5] Torrentshack cleanup --- couchpotato/core/providers/torrent/torrentshack/__init__.py | 6 +++--- couchpotato/core/providers/torrent/torrentshack/main.py | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/providers/torrent/torrentshack/__init__.py b/couchpotato/core/providers/torrent/torrentshack/__init__.py index 1c0d8a12..203e0996 100644 --- a/couchpotato/core/providers/torrent/torrentshack/__init__.py +++ b/couchpotato/core/providers/torrent/torrentshack/__init__.py @@ -12,7 +12,6 @@ config = [{ 'list': 'torrent_providers', 'name': 'TorrentShack', 'description': 'See TorrentShack', - 'wizard': True, 'options': [ { 'name': 'enabled', @@ -29,9 +28,10 @@ config = [{ 'type': 'password', }, { - 'name': 'scene only', + 'name': 'scene_only', 'type': 'bool', - 'default': False + 'default': False, + 'description': 'Only allow scene releases.' }, { 'name': 'extra_score', diff --git a/couchpotato/core/providers/torrent/torrentshack/main.py b/couchpotato/core/providers/torrent/torrentshack/main.py index 08e0faf6..df2ea291 100644 --- a/couchpotato/core/providers/torrent/torrentshack/main.py +++ b/couchpotato/core/providers/torrent/torrentshack/main.py @@ -5,7 +5,6 @@ from couchpotato.core.logger import CPLog from couchpotato.core.providers.torrent.base import TorrentProvider import traceback - log = CPLog(__name__) @@ -31,7 +30,7 @@ class TorrentShack(TorrentProvider): def _searchOnTitle(self, title, movie, quality, results): - url = self.urls['search'] % (tryUrlencode('%s %s' % (title.replace(':', ''), movie['library']['year'])), self.getCatId(quality['identifier'])[0]) + url = self.urls['search'] % (tryUrlencode('"%s" %s' % (title.replace(':', ''), movie['library']['year'])), self.getCatId(quality['identifier'])[0]) data = self.getHTMLData(url, opener = self.login_opener) if data: @@ -53,7 +52,7 @@ class TorrentShack(TorrentProvider): if result.find('span', attrs = {'class' : 'torrent_extra_info'}): extra_info = result.find('span', attrs = {'class' : 'torrent_extra_info'}).text - if not self.conf('scene only') or extra_info != '[NotScene]': + if not self.conf('scene_only') or extra_info != '[NotScene]': results.append({ 'id': link['href'].replace('torrents.php?torrentid=', ''), 'name': unicode(link.span.string).translate({ord(u'\xad'): None}), @@ -64,7 +63,6 @@ class TorrentShack(TorrentProvider): 'seeders': tryInt(result.find_all('td')[6].string), 'leechers': tryInt(result.find_all('td')[7].string), }) - log.info('Adding release %s' % unicode(link.span.string).translate({ord(u'\xad'): None})) else: log.info('Not adding release %s [NotScene]' % unicode(link.span.string).translate({ord(u'\xad'): None})) From a4c1480a1a1bdbe17fa340f378d4bb1a3cd689a4 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 29 May 2013 19:03:49 +0200 Subject: [PATCH 5/5] Force update check from dropdown --- couchpotato/core/_base/updater/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/_base/updater/main.py b/couchpotato/core/_base/updater/main.py index 14a0b173..e4e936ce 100644 --- a/couchpotato/core/_base/updater/main.py +++ b/couchpotato/core/_base/updater/main.py @@ -33,7 +33,6 @@ class Updater(Plugin): else: self.updater = SourceUpdater() - addEvent('app.load', self.autoUpdate) addEvent('app.load', self.setCrons) addEvent('updater.info', self.info) @@ -81,8 +80,8 @@ class Updater(Plugin): return False - def check(self): - if self.isDisabled(): + def check(self, force = False): + if not force and self.isDisabled(): return if self.updater.check(): @@ -101,7 +100,7 @@ class Updater(Plugin): def checkView(self): return jsonified({ - 'update_available': self.check(), + 'update_available': self.check(force = True), 'info': self.updater.info() })