From e1a311de40ab787f862f585ad41b44117b0b247c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Thu, 21 Nov 2013 19:55:36 +0100 Subject: [PATCH 01/11] initial couchtarter provider (torrent newznab) initial ground work based on newznab provider needs UI changes: http://i.imgur.com/4MiJUH5.png (need to add ratio and seed hours also) untested code --- .../core/providers/torrent/couchtater/__init__.py | 53 +++++++++ .../core/providers/torrent/couchtater/main.py | 121 +++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 couchpotato/core/providers/torrent/couchtater/__init__.py create mode 100644 couchpotato/core/providers/torrent/couchtater/main.py diff --git a/couchpotato/core/providers/torrent/couchtater/__init__.py b/couchpotato/core/providers/torrent/couchtater/__init__.py new file mode 100644 index 0000000..1b1cf9c --- /dev/null +++ b/couchpotato/core/providers/torrent/couchtater/__init__.py @@ -0,0 +1,53 @@ +from .main import Couchtarter + +def start(): + return Couchtarter() + +config = [{ + 'name': 'couchtart', + 'groups': [ + { + 'tab': 'searcher', + 'list': 'torrent_providers', + 'name': 'couchtart', + 'order': 10, + 'description': 'Cocuhtart providers.', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': True, + }, + { + 'name': 'use', + 'default': '0,0,0,0,0,0' + }, + { + 'name': 'host', + 'default': '', + 'description': 'The url path of your Couchtart provider.', + }, + { + 'name': 'extra_score', + 'advanced': True, + 'label': 'Extra Score', + 'default': '0', + 'description': 'Starting score for each release found via this provider.', + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'pass_key', + 'default': ',', + 'label': 'Pass Key', + 'description': 'Can be found on your profile page', + 'type': 'combined', + 'combine': ['use', 'host', 'username', 'pass_key', 'extra_score'], + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/couchtater/main.py b/couchpotato/core/providers/torrent/couchtater/main.py new file mode 100644 index 0000000..c7d2fa5 --- /dev/null +++ b/couchpotato/core/providers/torrent/couchtater/main.py @@ -0,0 +1,121 @@ +from couchpotato.core.helpers.encoding import tryUrlencode, toUnicode +from couchpotato.core.helpers.variable import splitString, tryInt +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.base import ResultList +from couchpotato.core.providers.torrent.base import TorrentProvider +from couchpotato.environment import Env +import traceback + +log = CPLog(__name__) + +class Couchtarter(TorrentProvider): + + limits_reached = {} + + http_time_between_calls = 1 # Seconds + + def search(self, movie, quality): + hosts = self.getHosts() + + results = ResultList(self, movie, quality, imdb_results = True) + + for host in hosts: + if self.isDisabled(host): + continue + + self._searchOnHost(host, movie, quality, results) + + return results + + def _searchOnHost(self, host, movie, quality, results): + + arguments = tryUrlencode({ + 'user': host['username'], + 'passkey': host['pass_key'], + 'imdbid': movie['library']['identifier'].replace('tt', '') + }) + url = '%s&%s' % (host['host'], arguments) + + torrents = self.getJsonData(url, cache_timeout = 1800) + + if torrents: + try: + if torrents.get('Error'): + if 'Incorrect parameters.' in torrents['Error']: + log.error('Wrong parameters passed to: %s', host['host']) + elif 'Death by authorization.' in torrents['Error']: + log.error('Wrong username or pass key for: %s', host['host']) + else: + log.error('Unknown error for: %s', host['host']) + return #(can I disable this host somehow? and notify user?) + + elif torrents.get('Results'): + if 'None found' in torrents['Results']: + return + else: + for torrent in torrents['Results']: + print torrent['ReleaseName'] + print torrent['Size'] + print torrent['DownloadURL'] + #results.append({ + # 'id': tryInt(result['TorrentID']), + # 'name': toUnicode(result['ReleaseName']), + # 'size': tryInt(self.parseSize(result['Size'])), + # 'url': result['DownloadURL'], + # 'detail_url': result['DetailURL'], + # 'resoultion': result['Resolution'], + # 'score': host['extra_score'], + # 'get_more_info': result['IMDbID'] + #}) + + except: + log.error('Failed getting results from %s: %s', (host['host'], traceback.format_exc())) + + def getHosts(self): + + uses = splitString(str(self.conf('use')), clean = False) + hosts = splitString(self.conf('host'), clean = False) + usernames = splitString(self.conf('username'), clean = False) + pass_keys = splitString(self.conf('pass_key'), clean = False) + extra_score = splitString(self.conf('extra_score'), clean = False) + + list = [] + for nr in range(len(hosts)): + + try: key = pass_keys[nr] + except: key = '' + + try: host = hosts[nr] + except: host = '' + + list.append({ + 'use': uses[nr], + 'host': host, + 'pass_key': key, + 'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0 + }) + + return list + + def belongsTo(self, url, provider = None, host = None): + + hosts = self.getHosts() + + for host in hosts: + result = super(Couchtater, self).belongsTo(url, host = host['host'], provider = provider) + if result: + return result + + def isDisabled(self, host = None): + return not self.isEnabled(host) + + def isEnabled(self, host = None): + + # Return true if at least one is enabled and no host is given + if host is None: + for host in self.getHosts(): + if self.isEnabled(host): + return True + return False + + return TorrentProvider.isEnabled(self) and host['host'] and host['pass_key'] and int(host['use']) From 357166414cd2946656da6d75bac163741d6fc6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Thu, 21 Nov 2013 22:20:45 +0100 Subject: [PATCH 02/11] use .get() and added more options --- couchpotato/core/providers/torrent/couchtater/main.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/providers/torrent/couchtater/main.py b/couchpotato/core/providers/torrent/couchtater/main.py index c7d2fa5..79c6511 100644 --- a/couchpotato/core/providers/torrent/couchtater/main.py +++ b/couchpotato/core/providers/torrent/couchtater/main.py @@ -58,14 +58,17 @@ class Couchtarter(TorrentProvider): print torrent['Size'] print torrent['DownloadURL'] #results.append({ - # 'id': tryInt(result['TorrentID']), - # 'name': toUnicode(result['ReleaseName']), - # 'size': tryInt(self.parseSize(result['Size'])), - # 'url': result['DownloadURL'], - # 'detail_url': result['DetailURL'], - # 'resoultion': result['Resolution'], + # 'id': tryInt(result.get('TorrentID')), + # 'name': toUnicode(result.get('ReleaseName')), + # 'url': result.get('DownloadURL'), + # 'detail_url': result.get('DetailURL'), + # 'size': tryInt(self.parseSize(result.get('Size'))), # 'score': host['extra_score'], - # 'get_more_info': result['IMDbID'] + # 'seeders': tryInt(result.get('Seeders'), + # 'leechers': tryInt(result.get('leechers'), + # 'resoultion': result.get('Resolution'), + # 'source': result.get('Media'), + # 'get_more_info': result.get('IMDbID') #}) except: From 8951e9fc9007a4bb08ede97af6493404c38664d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Thu, 21 Nov 2013 22:22:19 +0100 Subject: [PATCH 03/11] typo --- couchpotato/core/providers/torrent/couchtater/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/providers/torrent/couchtater/main.py b/couchpotato/core/providers/torrent/couchtater/main.py index 79c6511..e0262a5 100644 --- a/couchpotato/core/providers/torrent/couchtater/main.py +++ b/couchpotato/core/providers/torrent/couchtater/main.py @@ -65,7 +65,7 @@ class Couchtarter(TorrentProvider): # 'size': tryInt(self.parseSize(result.get('Size'))), # 'score': host['extra_score'], # 'seeders': tryInt(result.get('Seeders'), - # 'leechers': tryInt(result.get('leechers'), + # 'leechers': tryInt(result.get('Leechers'), # 'resoultion': result.get('Resolution'), # 'source': result.get('Media'), # 'get_more_info': result.get('IMDbID') From 379f62a339e899ee4719d27edc45f75dd2a49c26 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 23 Nov 2013 00:31:26 +0100 Subject: [PATCH 04/11] CouchTater fixes --- .../core/providers/torrent/couchtater/__init__.py | 16 +++--- .../core/providers/torrent/couchtater/main.py | 57 +++++++++++----------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/couchpotato/core/providers/torrent/couchtater/__init__.py b/couchpotato/core/providers/torrent/couchtater/__init__.py index 1b1cf9c..9be23f9 100644 --- a/couchpotato/core/providers/torrent/couchtater/__init__.py +++ b/couchpotato/core/providers/torrent/couchtater/__init__.py @@ -1,27 +1,27 @@ -from .main import Couchtarter +from .main import Couchtater def start(): - return Couchtarter() + return Couchtater() config = [{ - 'name': 'couchtart', + 'name': 'couchtater', 'groups': [ { 'tab': 'searcher', 'list': 'torrent_providers', 'name': 'couchtart', 'order': 10, - 'description': 'Cocuhtart providers.', + 'description': 'Couchtater providers.', 'wizard': True, 'options': [ { 'name': 'enabled', 'type': 'enabler', - 'default': True, + 'default': False, }, { 'name': 'use', - 'default': '0,0,0,0,0,0' + 'default': '' }, { 'name': 'host', @@ -36,7 +36,7 @@ config = [{ 'description': 'Starting score for each release found via this provider.', }, { - 'name': 'username', + 'name': 'name', 'default': '', }, { @@ -45,7 +45,7 @@ config = [{ 'label': 'Pass Key', 'description': 'Can be found on your profile page', 'type': 'combined', - 'combine': ['use', 'host', 'username', 'pass_key', 'extra_score'], + 'combine': ['use', 'host', 'name', 'pass_key', 'extra_score'], }, ], }, diff --git a/couchpotato/core/providers/torrent/couchtater/main.py b/couchpotato/core/providers/torrent/couchtater/main.py index e0262a5..25270b0 100644 --- a/couchpotato/core/providers/torrent/couchtater/main.py +++ b/couchpotato/core/providers/torrent/couchtater/main.py @@ -1,14 +1,14 @@ -from couchpotato.core.helpers.encoding import tryUrlencode, toUnicode +from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.variable import splitString, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.base import ResultList from couchpotato.core.providers.torrent.base import TorrentProvider -from couchpotato.environment import Env import traceback log = CPLog(__name__) -class Couchtarter(TorrentProvider): + +class Couchtater(TorrentProvider): limits_reached = {} @@ -30,17 +30,17 @@ class Couchtarter(TorrentProvider): def _searchOnHost(self, host, movie, quality, results): arguments = tryUrlencode({ - 'user': host['username'], + 'user': host['name'], 'passkey': host['pass_key'], - 'imdbid': movie['library']['identifier'].replace('tt', '') + 'imdbid': movie['library']['identifier'] }) - url = '%s&%s' % (host['host'], arguments) + url = '%s?%s' % (host['host'], arguments) torrents = self.getJsonData(url, cache_timeout = 1800) if torrents: try: - if torrents.get('Error'): + if torrents.get('error'): if 'Incorrect parameters.' in torrents['Error']: log.error('Wrong parameters passed to: %s', host['host']) elif 'Death by authorization.' in torrents['Error']: @@ -49,27 +49,22 @@ class Couchtarter(TorrentProvider): log.error('Unknown error for: %s', host['host']) return #(can I disable this host somehow? and notify user?) - elif torrents.get('Results'): - if 'None found' in torrents['Results']: - return - else: - for torrent in torrents['Results']: - print torrent['ReleaseName'] - print torrent['Size'] - print torrent['DownloadURL'] - #results.append({ - # 'id': tryInt(result.get('TorrentID')), - # 'name': toUnicode(result.get('ReleaseName')), - # 'url': result.get('DownloadURL'), - # 'detail_url': result.get('DetailURL'), - # 'size': tryInt(self.parseSize(result.get('Size'))), - # 'score': host['extra_score'], - # 'seeders': tryInt(result.get('Seeders'), - # 'leechers': tryInt(result.get('Leechers'), - # 'resoultion': result.get('Resolution'), - # 'source': result.get('Media'), - # 'get_more_info': result.get('IMDbID') - #}) + elif torrents.get('results'): + for torrent in torrents['results']: + print torrent + #results.append({ + # 'id': tryInt(result.get('TorrentID')), + # 'name': toUnicode(result.get('ReleaseName')), + # 'url': result.get('DownloadURL'), + # 'detail_url': result.get('DetailURL'), + # 'size': tryInt(self.parseSize(result.get('Size'))), + # 'score': host['extra_score'], + # 'seeders': tryInt(result.get('Seeders'), + # 'leechers': tryInt(result.get('Leechers'), + # 'resoultion': result.get('Resolution'), + # 'source': result.get('Media'), + # 'get_more_info': result.get('IMDbID') + #}) except: log.error('Failed getting results from %s: %s', (host['host'], traceback.format_exc())) @@ -78,7 +73,7 @@ class Couchtarter(TorrentProvider): uses = splitString(str(self.conf('use')), clean = False) hosts = splitString(self.conf('host'), clean = False) - usernames = splitString(self.conf('username'), clean = False) + names = splitString(self.conf('name'), clean = False) pass_keys = splitString(self.conf('pass_key'), clean = False) extra_score = splitString(self.conf('extra_score'), clean = False) @@ -91,9 +86,13 @@ class Couchtarter(TorrentProvider): try: host = hosts[nr] except: host = '' + try: name = names[nr] + except: name = '' + list.append({ 'use': uses[nr], 'host': host, + 'name': name, 'pass_key': key, 'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0 }) From df60d7059233963acb4da80a524a5edc604e406d Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 23 Nov 2013 12:06:46 +0100 Subject: [PATCH 05/11] Move it --- .../core/providers/torrent/couchtater/__init__.py | 53 --------- .../core/providers/torrent/couchtater/main.py | 123 --------------------- .../providers/torrent/torrentpotato/__init__.py | 53 +++++++++ .../core/providers/torrent/torrentpotato/main.py | 123 +++++++++++++++++++++ 4 files changed, 176 insertions(+), 176 deletions(-) delete mode 100644 couchpotato/core/providers/torrent/couchtater/__init__.py delete mode 100644 couchpotato/core/providers/torrent/couchtater/main.py create mode 100644 couchpotato/core/providers/torrent/torrentpotato/__init__.py create mode 100644 couchpotato/core/providers/torrent/torrentpotato/main.py diff --git a/couchpotato/core/providers/torrent/couchtater/__init__.py b/couchpotato/core/providers/torrent/couchtater/__init__.py deleted file mode 100644 index 9be23f9..0000000 --- a/couchpotato/core/providers/torrent/couchtater/__init__.py +++ /dev/null @@ -1,53 +0,0 @@ -from .main import Couchtater - -def start(): - return Couchtater() - -config = [{ - 'name': 'couchtater', - 'groups': [ - { - 'tab': 'searcher', - 'list': 'torrent_providers', - 'name': 'couchtart', - 'order': 10, - 'description': 'Couchtater providers.', - 'wizard': True, - 'options': [ - { - 'name': 'enabled', - 'type': 'enabler', - 'default': False, - }, - { - 'name': 'use', - 'default': '' - }, - { - 'name': 'host', - 'default': '', - 'description': 'The url path of your Couchtart provider.', - }, - { - 'name': 'extra_score', - 'advanced': True, - 'label': 'Extra Score', - 'default': '0', - 'description': 'Starting score for each release found via this provider.', - }, - { - 'name': 'name', - 'default': '', - }, - { - 'name': 'pass_key', - 'default': ',', - 'label': 'Pass Key', - 'description': 'Can be found on your profile page', - 'type': 'combined', - 'combine': ['use', 'host', 'name', 'pass_key', 'extra_score'], - }, - ], - }, - ], -}] diff --git a/couchpotato/core/providers/torrent/couchtater/main.py b/couchpotato/core/providers/torrent/couchtater/main.py deleted file mode 100644 index 25270b0..0000000 --- a/couchpotato/core/providers/torrent/couchtater/main.py +++ /dev/null @@ -1,123 +0,0 @@ -from couchpotato.core.helpers.encoding import tryUrlencode -from couchpotato.core.helpers.variable import splitString, tryInt -from couchpotato.core.logger import CPLog -from couchpotato.core.providers.base import ResultList -from couchpotato.core.providers.torrent.base import TorrentProvider -import traceback - -log = CPLog(__name__) - - -class Couchtater(TorrentProvider): - - limits_reached = {} - - http_time_between_calls = 1 # Seconds - - def search(self, movie, quality): - hosts = self.getHosts() - - results = ResultList(self, movie, quality, imdb_results = True) - - for host in hosts: - if self.isDisabled(host): - continue - - self._searchOnHost(host, movie, quality, results) - - return results - - def _searchOnHost(self, host, movie, quality, results): - - arguments = tryUrlencode({ - 'user': host['name'], - 'passkey': host['pass_key'], - 'imdbid': movie['library']['identifier'] - }) - url = '%s?%s' % (host['host'], arguments) - - torrents = self.getJsonData(url, cache_timeout = 1800) - - if torrents: - try: - if torrents.get('error'): - if 'Incorrect parameters.' in torrents['Error']: - log.error('Wrong parameters passed to: %s', host['host']) - elif 'Death by authorization.' in torrents['Error']: - log.error('Wrong username or pass key for: %s', host['host']) - else: - log.error('Unknown error for: %s', host['host']) - return #(can I disable this host somehow? and notify user?) - - elif torrents.get('results'): - for torrent in torrents['results']: - print torrent - #results.append({ - # 'id': tryInt(result.get('TorrentID')), - # 'name': toUnicode(result.get('ReleaseName')), - # 'url': result.get('DownloadURL'), - # 'detail_url': result.get('DetailURL'), - # 'size': tryInt(self.parseSize(result.get('Size'))), - # 'score': host['extra_score'], - # 'seeders': tryInt(result.get('Seeders'), - # 'leechers': tryInt(result.get('Leechers'), - # 'resoultion': result.get('Resolution'), - # 'source': result.get('Media'), - # 'get_more_info': result.get('IMDbID') - #}) - - except: - log.error('Failed getting results from %s: %s', (host['host'], traceback.format_exc())) - - def getHosts(self): - - uses = splitString(str(self.conf('use')), clean = False) - hosts = splitString(self.conf('host'), clean = False) - names = splitString(self.conf('name'), clean = False) - pass_keys = splitString(self.conf('pass_key'), clean = False) - extra_score = splitString(self.conf('extra_score'), clean = False) - - list = [] - for nr in range(len(hosts)): - - try: key = pass_keys[nr] - except: key = '' - - try: host = hosts[nr] - except: host = '' - - try: name = names[nr] - except: name = '' - - list.append({ - 'use': uses[nr], - 'host': host, - 'name': name, - 'pass_key': key, - 'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0 - }) - - return list - - def belongsTo(self, url, provider = None, host = None): - - hosts = self.getHosts() - - for host in hosts: - result = super(Couchtater, self).belongsTo(url, host = host['host'], provider = provider) - if result: - return result - - def isDisabled(self, host = None): - return not self.isEnabled(host) - - def isEnabled(self, host = None): - - # Return true if at least one is enabled and no host is given - if host is None: - for host in self.getHosts(): - if self.isEnabled(host): - return True - return False - - return TorrentProvider.isEnabled(self) and host['host'] and host['pass_key'] and int(host['use']) diff --git a/couchpotato/core/providers/torrent/torrentpotato/__init__.py b/couchpotato/core/providers/torrent/torrentpotato/__init__.py new file mode 100644 index 0000000..9be23f9 --- /dev/null +++ b/couchpotato/core/providers/torrent/torrentpotato/__init__.py @@ -0,0 +1,53 @@ +from .main import Couchtater + +def start(): + return Couchtater() + +config = [{ + 'name': 'couchtater', + 'groups': [ + { + 'tab': 'searcher', + 'list': 'torrent_providers', + 'name': 'couchtart', + 'order': 10, + 'description': 'Couchtater providers.', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'use', + 'default': '' + }, + { + 'name': 'host', + 'default': '', + 'description': 'The url path of your Couchtart provider.', + }, + { + 'name': 'extra_score', + 'advanced': True, + 'label': 'Extra Score', + 'default': '0', + 'description': 'Starting score for each release found via this provider.', + }, + { + 'name': 'name', + 'default': '', + }, + { + 'name': 'pass_key', + 'default': ',', + 'label': 'Pass Key', + 'description': 'Can be found on your profile page', + 'type': 'combined', + 'combine': ['use', 'host', 'name', 'pass_key', 'extra_score'], + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/torrentpotato/main.py b/couchpotato/core/providers/torrent/torrentpotato/main.py new file mode 100644 index 0000000..25270b0 --- /dev/null +++ b/couchpotato/core/providers/torrent/torrentpotato/main.py @@ -0,0 +1,123 @@ +from couchpotato.core.helpers.encoding import tryUrlencode +from couchpotato.core.helpers.variable import splitString, tryInt +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.base import ResultList +from couchpotato.core.providers.torrent.base import TorrentProvider +import traceback + +log = CPLog(__name__) + + +class Couchtater(TorrentProvider): + + limits_reached = {} + + http_time_between_calls = 1 # Seconds + + def search(self, movie, quality): + hosts = self.getHosts() + + results = ResultList(self, movie, quality, imdb_results = True) + + for host in hosts: + if self.isDisabled(host): + continue + + self._searchOnHost(host, movie, quality, results) + + return results + + def _searchOnHost(self, host, movie, quality, results): + + arguments = tryUrlencode({ + 'user': host['name'], + 'passkey': host['pass_key'], + 'imdbid': movie['library']['identifier'] + }) + url = '%s?%s' % (host['host'], arguments) + + torrents = self.getJsonData(url, cache_timeout = 1800) + + if torrents: + try: + if torrents.get('error'): + if 'Incorrect parameters.' in torrents['Error']: + log.error('Wrong parameters passed to: %s', host['host']) + elif 'Death by authorization.' in torrents['Error']: + log.error('Wrong username or pass key for: %s', host['host']) + else: + log.error('Unknown error for: %s', host['host']) + return #(can I disable this host somehow? and notify user?) + + elif torrents.get('results'): + for torrent in torrents['results']: + print torrent + #results.append({ + # 'id': tryInt(result.get('TorrentID')), + # 'name': toUnicode(result.get('ReleaseName')), + # 'url': result.get('DownloadURL'), + # 'detail_url': result.get('DetailURL'), + # 'size': tryInt(self.parseSize(result.get('Size'))), + # 'score': host['extra_score'], + # 'seeders': tryInt(result.get('Seeders'), + # 'leechers': tryInt(result.get('Leechers'), + # 'resoultion': result.get('Resolution'), + # 'source': result.get('Media'), + # 'get_more_info': result.get('IMDbID') + #}) + + except: + log.error('Failed getting results from %s: %s', (host['host'], traceback.format_exc())) + + def getHosts(self): + + uses = splitString(str(self.conf('use')), clean = False) + hosts = splitString(self.conf('host'), clean = False) + names = splitString(self.conf('name'), clean = False) + pass_keys = splitString(self.conf('pass_key'), clean = False) + extra_score = splitString(self.conf('extra_score'), clean = False) + + list = [] + for nr in range(len(hosts)): + + try: key = pass_keys[nr] + except: key = '' + + try: host = hosts[nr] + except: host = '' + + try: name = names[nr] + except: name = '' + + list.append({ + 'use': uses[nr], + 'host': host, + 'name': name, + 'pass_key': key, + 'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0 + }) + + return list + + def belongsTo(self, url, provider = None, host = None): + + hosts = self.getHosts() + + for host in hosts: + result = super(Couchtater, self).belongsTo(url, host = host['host'], provider = provider) + if result: + return result + + def isDisabled(self, host = None): + return not self.isEnabled(host) + + def isEnabled(self, host = None): + + # Return true if at least one is enabled and no host is given + if host is None: + for host in self.getHosts(): + if self.isEnabled(host): + return True + return False + + return TorrentProvider.isEnabled(self) and host['host'] and host['pass_key'] and int(host['use']) From 4b9f9862fc035dcbc83aed62be977c2c1dcd479e Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 23 Nov 2013 12:07:00 +0100 Subject: [PATCH 06/11] Change name and response --- .../providers/torrent/torrentpotato/__init__.py | 12 +++--- .../core/providers/torrent/torrentpotato/main.py | 44 +++++++++------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/couchpotato/core/providers/torrent/torrentpotato/__init__.py b/couchpotato/core/providers/torrent/torrentpotato/__init__.py index 9be23f9..3d711e9 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/__init__.py +++ b/couchpotato/core/providers/torrent/torrentpotato/__init__.py @@ -1,17 +1,17 @@ -from .main import Couchtater +from .main import TorrentPotato def start(): - return Couchtater() + return TorrentPotato() config = [{ - 'name': 'couchtater', + 'name': 'torrentpotato', 'groups': [ { 'tab': 'searcher', 'list': 'torrent_providers', - 'name': 'couchtart', + 'name': 'TorrentPotato', 'order': 10, - 'description': 'Couchtater providers.', + 'description': 'CouchPotato torrent provider providers.', 'wizard': True, 'options': [ { @@ -26,7 +26,7 @@ config = [{ { 'name': 'host', 'default': '', - 'description': 'The url path of your Couchtart provider.', + 'description': 'The url path of your TorrentPotato provider.', }, { 'name': 'extra_score', diff --git a/couchpotato/core/providers/torrent/torrentpotato/main.py b/couchpotato/core/providers/torrent/torrentpotato/main.py index 25270b0..15ab323 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/main.py +++ b/couchpotato/core/providers/torrent/torrentpotato/main.py @@ -1,15 +1,17 @@ -from couchpotato.core.helpers.encoding import tryUrlencode +from couchpotato.core.helpers.encoding import tryUrlencode, toUnicode from couchpotato.core.helpers.variable import splitString, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.base import ResultList from couchpotato.core.providers.torrent.base import TorrentProvider +import re import traceback log = CPLog(__name__) -class Couchtater(TorrentProvider): +class TorrentPotato(TorrentProvider): + urls = {} limits_reached = {} http_time_between_calls = 1 # Seconds @@ -41,30 +43,20 @@ class Couchtater(TorrentProvider): if torrents: try: if torrents.get('error'): - if 'Incorrect parameters.' in torrents['Error']: - log.error('Wrong parameters passed to: %s', host['host']) - elif 'Death by authorization.' in torrents['Error']: - log.error('Wrong username or pass key for: %s', host['host']) - else: - log.error('Unknown error for: %s', host['host']) - return #(can I disable this host somehow? and notify user?) - + log.error('%s: %s', (torrents.get('error'), host['host'])) elif torrents.get('results'): - for torrent in torrents['results']: - print torrent - #results.append({ - # 'id': tryInt(result.get('TorrentID')), - # 'name': toUnicode(result.get('ReleaseName')), - # 'url': result.get('DownloadURL'), - # 'detail_url': result.get('DetailURL'), - # 'size': tryInt(self.parseSize(result.get('Size'))), - # 'score': host['extra_score'], - # 'seeders': tryInt(result.get('Seeders'), - # 'leechers': tryInt(result.get('Leechers'), - # 'resoultion': result.get('Resolution'), - # 'source': result.get('Media'), - # 'get_more_info': result.get('IMDbID') - #}) + for torrent in torrents.get('results', []): + results.append({ + 'id': torrent.get('torrent_id'), + 'protocol': 'torrent' if re.match('^(http|https|ftp)://.*$', torrent.get('download_url')) else 'torrent_magnet', + 'name': toUnicode(torrent.get('name')), + 'url': torrent.get('download_url'), + 'detail_url': torrent.get('details_url'), + 'size': torrent.get('size'), + 'score': host['extra_score'], + 'seeders': torrent.get('seeders'), + 'leechers': torrent.get('leechers'), + }) except: log.error('Failed getting results from %s: %s', (host['host'], traceback.format_exc())) @@ -104,7 +96,7 @@ class Couchtater(TorrentProvider): hosts = self.getHosts() for host in hosts: - result = super(Couchtater, self).belongsTo(url, host = host['host'], provider = provider) + result = super(TorrentPotato, self).belongsTo(url, host = host['host'], provider = provider) if result: return result From 50262112b8bb8a8e4e26c0af718d677d1cad474f Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 24 Nov 2013 00:27:47 +0100 Subject: [PATCH 07/11] Use release_name --- couchpotato/core/providers/torrent/torrentpotato/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/providers/torrent/torrentpotato/main.py b/couchpotato/core/providers/torrent/torrentpotato/main.py index 15ab323..9951157 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/main.py +++ b/couchpotato/core/providers/torrent/torrentpotato/main.py @@ -49,7 +49,7 @@ class TorrentPotato(TorrentProvider): results.append({ 'id': torrent.get('torrent_id'), 'protocol': 'torrent' if re.match('^(http|https|ftp)://.*$', torrent.get('download_url')) else 'torrent_magnet', - 'name': toUnicode(torrent.get('name')), + 'name': toUnicode(torrent.get('release_name')), 'url': torrent.get('download_url'), 'detail_url': torrent.get('details_url'), 'size': torrent.get('size'), From 37b98cb83505a078a41ce2bd53c5a6dd12331c17 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 24 Nov 2013 00:52:51 +0100 Subject: [PATCH 08/11] TorrentPotato styling of inputs --- .../core/providers/torrent/torrentpotato/__init__.py | 5 +++-- couchpotato/static/style/settings.css | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/providers/torrent/torrentpotato/__init__.py b/couchpotato/core/providers/torrent/torrentpotato/__init__.py index 3d711e9..2e4b466 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/__init__.py +++ b/couchpotato/core/providers/torrent/torrentpotato/__init__.py @@ -11,7 +11,7 @@ config = [{ 'list': 'torrent_providers', 'name': 'TorrentPotato', 'order': 10, - 'description': 'CouchPotato torrent provider providers.', + 'description': 'CouchPotato torrent provider. Checkout the wiki page about this provider for more info.', 'wizard': True, 'options': [ { @@ -37,6 +37,7 @@ config = [{ }, { 'name': 'name', + 'label': 'Username', 'default': '', }, { @@ -45,7 +46,7 @@ config = [{ 'label': 'Pass Key', 'description': 'Can be found on your profile page', 'type': 'combined', - 'combine': ['use', 'host', 'name', 'pass_key', 'extra_score'], + 'combine': ['use', 'host', 'pass_key', 'name', 'extra_score'], }, ], }, diff --git a/couchpotato/static/style/settings.css b/couchpotato/static/style/settings.css index 744531a..e47284d 100644 --- a/couchpotato/static/style/settings.css +++ b/couchpotato/static/style/settings.css @@ -546,11 +546,28 @@ display: none; } .page .combined_table .head abbr.host { - margin-right: 190px; + margin-right: 195px; } + .page .combined_table input.host { + width: 215px; + } + .page .combined_table .head abbr.name { + margin-right: 67px; + } + .page .combined_table input.name { + width: 120px; + } .page .combined_table .head abbr.api_key { + margin-right: 178px; + } + .page .combined_table .head abbr.pass_key { margin-right: 171px; } + .page .combined_table input.api_key, + .page .combined_table input.pass_key { + width: 213px; + } + .page .combined_table .head .extra_score, .page .combined_table .extra_score { width: 70px; From 8a58d7f9737a1f1e7ae6dbc64147c87d6f0716f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sun, 24 Nov 2013 14:51:03 +0100 Subject: [PATCH 09/11] use hostname instead of TorrentPotato (dashboard) --- couchpotato/core/providers/torrent/torrentpotato/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/couchpotato/core/providers/torrent/torrentpotato/main.py b/couchpotato/core/providers/torrent/torrentpotato/main.py index 9951157..7032095 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/main.py +++ b/couchpotato/core/providers/torrent/torrentpotato/main.py @@ -3,6 +3,7 @@ from couchpotato.core.helpers.variable import splitString, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.base import ResultList from couchpotato.core.providers.torrent.base import TorrentProvider +from urlparse import urlparse import re import traceback @@ -49,6 +50,7 @@ class TorrentPotato(TorrentProvider): results.append({ 'id': torrent.get('torrent_id'), 'protocol': 'torrent' if re.match('^(http|https|ftp)://.*$', torrent.get('download_url')) else 'torrent_magnet', + 'provider_extra': urlparse(host['host']).hostname or host['host'], 'name': toUnicode(torrent.get('release_name')), 'url': torrent.get('download_url'), 'detail_url': torrent.get('details_url'), From f3380c4fed0b73da6bca71f5705e21dc69aa1f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sun, 24 Nov 2013 19:33:29 +0100 Subject: [PATCH 10/11] seed_time and seed_ratio --- .../core/providers/torrent/torrentpotato/__init__.py | 14 ++++++++++++++ couchpotato/core/providers/torrent/torrentpotato/main.py | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/couchpotato/core/providers/torrent/torrentpotato/__init__.py b/couchpotato/core/providers/torrent/torrentpotato/__init__.py index 2e4b466..fab6d17 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/__init__.py +++ b/couchpotato/core/providers/torrent/torrentpotato/__init__.py @@ -41,6 +41,20 @@ config = [{ 'default': '', }, { + 'name': 'seed_ratio', + 'label': 'Seed ratio', + 'type': 'float', + 'default': 1, + 'description': 'Will not be (re)moved until this seed ratio is met.', + }, + { + 'name': 'seed_time', + 'label': 'Seed time', + 'type': 'int', + 'default': 40, + 'description': 'Will not be (re)moved until this seed time (in hours) is met.', + }, + { 'name': 'pass_key', 'default': ',', 'label': 'Pass Key', diff --git a/couchpotato/core/providers/torrent/torrentpotato/main.py b/couchpotato/core/providers/torrent/torrentpotato/main.py index 7032095..501dbd5 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/main.py +++ b/couchpotato/core/providers/torrent/torrentpotato/main.py @@ -68,6 +68,8 @@ class TorrentPotato(TorrentProvider): uses = splitString(str(self.conf('use')), clean = False) hosts = splitString(self.conf('host'), clean = False) names = splitString(self.conf('name'), clean = False) + seed_times = splitString(self.conf('seed_time'), clean = False) + seed_ratios = splitString(self.conf('seed_ratio'), clean = False) pass_keys = splitString(self.conf('pass_key'), clean = False) extra_score = splitString(self.conf('extra_score'), clean = False) @@ -83,10 +85,18 @@ class TorrentPotato(TorrentProvider): try: name = names[nr] except: name = '' + try: ratio = seed_ratios + except: ratio = '' + + try: seed_time = seed_times + except: seed_time = '' + list.append({ 'use': uses[nr], 'host': host, 'name': name, + 'seed_ratio': ratio, + 'seed_time': seed_time, 'pass_key': key, 'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0 }) From 8d2e3a1919db73ae4536c69a18870a64e3cbc0cf Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 24 Nov 2013 21:43:54 +0100 Subject: [PATCH 11/11] Add ratio and seed time styling --- .../providers/torrent/torrentpotato/__init__.py | 8 ++--- .../core/providers/torrent/torrentpotato/main.py | 8 +++-- couchpotato/static/style/settings.css | 42 +++++++++++----------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/couchpotato/core/providers/torrent/torrentpotato/__init__.py b/couchpotato/core/providers/torrent/torrentpotato/__init__.py index fab6d17..5054f98 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/__init__.py +++ b/couchpotato/core/providers/torrent/torrentpotato/__init__.py @@ -43,15 +43,13 @@ config = [{ { 'name': 'seed_ratio', 'label': 'Seed ratio', - 'type': 'float', - 'default': 1, + 'default': '1', 'description': 'Will not be (re)moved until this seed ratio is met.', }, { 'name': 'seed_time', 'label': 'Seed time', - 'type': 'int', - 'default': 40, + 'default': '40', 'description': 'Will not be (re)moved until this seed time (in hours) is met.', }, { @@ -60,7 +58,7 @@ config = [{ 'label': 'Pass Key', 'description': 'Can be found on your profile page', 'type': 'combined', - 'combine': ['use', 'host', 'pass_key', 'name', 'extra_score'], + 'combine': ['use', 'host', 'pass_key', 'name', 'seed_ratio', 'seed_time', 'extra_score'], }, ], }, diff --git a/couchpotato/core/providers/torrent/torrentpotato/main.py b/couchpotato/core/providers/torrent/torrentpotato/main.py index 501dbd5..a81d0ed 100644 --- a/couchpotato/core/providers/torrent/torrentpotato/main.py +++ b/couchpotato/core/providers/torrent/torrentpotato/main.py @@ -1,5 +1,5 @@ from couchpotato.core.helpers.encoding import tryUrlencode, toUnicode -from couchpotato.core.helpers.variable import splitString, tryInt +from couchpotato.core.helpers.variable import splitString, tryInt, tryFloat from couchpotato.core.logger import CPLog from couchpotato.core.providers.base import ResultList from couchpotato.core.providers.torrent.base import TorrentProvider @@ -58,6 +58,8 @@ class TorrentPotato(TorrentProvider): 'score': host['extra_score'], 'seeders': torrent.get('seeders'), 'leechers': torrent.get('leechers'), + 'seed_ratio': host['seed_ratio'], + 'seed_time': host['seed_time'], }) except: @@ -95,8 +97,8 @@ class TorrentPotato(TorrentProvider): 'use': uses[nr], 'host': host, 'name': name, - 'seed_ratio': ratio, - 'seed_time': seed_time, + 'seed_ratio': tryFloat(ratio), + 'seed_time': tryInt(seed_time), 'pass_key': key, 'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0 }) diff --git a/couchpotato/static/style/settings.css b/couchpotato/static/style/settings.css index e47284d..0ee7479 100644 --- a/couchpotato/static/style/settings.css +++ b/couchpotato/static/style/settings.css @@ -545,28 +545,30 @@ .page .combined_table .head abbr:first-child { display: none; } - .page .combined_table .head abbr.host { - margin-right: 195px; - } - .page .combined_table input.host { - width: 215px; - } - .page .combined_table .head abbr.name { - margin-right: 67px; - } - .page .combined_table input.name { - width: 120px; - } - .page .combined_table .head abbr.api_key { - margin-right: 178px; + .page .combined_table .head abbr.host { margin-right: 120px; } + .page .combined_table input.host { width: 140px; } + .page .section_newznab .combined_table .head abbr.host { margin-right: 200px; } + .page .section_newznab .combined_table input.host { width: 220px; } + + .page .combined_table .head abbr.name { margin-right: 57px; } + .page .combined_table input.name { width: 120px; } + .page .combined_table .head abbr.api_key { margin-right: 75px; } + + .page .combined_table .head abbr.pass_key { margin-right: 71px; } + .page .combined_table input.pass_key { width: 113px; } + + .page .section_newznab .combined_table .head abbr.api_key { margin-right: 185px; } + .page .section_newznab .combined_table input.api_key { width: 223px; } + + .page .combined_table .seed_ratio, + .page .combined_table .seed_time { + width: 70px; + text-align: center; + margin-left: 10px; } - .page .combined_table .head abbr.pass_key { - margin-right: 171px; + .page .combined_table .seed_time { + margin-right: 10px; } - .page .combined_table input.api_key, - .page .combined_table input.pass_key { - width: 213px; - } .page .combined_table .head .extra_score, .page .combined_table .extra_score {