From 3c04eed2182a30648fa237f755dbc9a1c1393da7 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 20 Dec 2012 15:18:46 +0100 Subject: [PATCH 1/3] Added nzbx option --- .../core/providers/nzb/nzbx/__init__.py | 23 +++++ couchpotato/core/providers/nzb/nzbx/main.py | 92 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 couchpotato/core/providers/nzb/nzbx/__init__.py create mode 100644 couchpotato/core/providers/nzb/nzbx/main.py diff --git a/couchpotato/core/providers/nzb/nzbx/__init__.py b/couchpotato/core/providers/nzb/nzbx/__init__.py new file mode 100644 index 00000000..9d794e3d --- /dev/null +++ b/couchpotato/core/providers/nzb/nzbx/__init__.py @@ -0,0 +1,23 @@ +from .main import Nzbx + +def start(): + return Nzbx() + +config = [{ + 'name': 'nzbx', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'nzb_providers', + 'name': 'nzbx', + 'description': 'Free provider, less accurate. See nzbx', + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': True, + }, + ], + }, + ], +}] diff --git a/couchpotato/core/providers/nzb/nzbx/main.py b/couchpotato/core/providers/nzb/nzbx/main.py new file mode 100644 index 00000000..e7c2d342 --- /dev/null +++ b/couchpotato/core/providers/nzb/nzbx/main.py @@ -0,0 +1,92 @@ +from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode, \ + simplifyString +from couchpotato.core.helpers.rss import RSS +from couchpotato.core.helpers.variable import tryInt, getTitle +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.nzb.base import NZBProvider +from couchpotato.environment import Env +from dateutil.parser import parse +import re +import time +import traceback +import json + +log = CPLog(__name__) + + +class Nzbx(NZBProvider, RSS): + endpoint = 'https://nzbx.co/api/' + + urls = { + 'search': endpoint + 'search', + 'details': endpoint + 'details?guid=%s', + 'comments': endpoint + 'get-comments?guid=%s', + 'ratings': endpoint + 'get-votes?guid=%s', + 'downloads': endpoint + 'get-downloads-count?guid=%s', + 'categories': endpoint + 'categories', + 'groups': endpoint + 'groups', + } + + http_time_between_calls = 1 # Seconds + + def search(self, movie, quality): + + results = [] + if self.isDisabled(): + return results + + q = '"%s %s" %s' % (simplifyString(getTitle(movie['library'])), movie['library']['year'], quality.get('identifier')) + arguments = tryUrlencode({ + 'q': q, + 'l': 250, # Limit on number of files returned + #'i': '', # index of file + #'sf': '' # size filter + }) + url = "%s?%s" % (self.urls['search'], arguments) + + cache_key = 'nzbx.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) + + data = self.getCache(cache_key, url) + if data: + try: + try: + nzbs = json.loads(data) + except Exception, e: + log.debug('%s, %s', (self.getName(), e)) + return results + + for nzb in nzbs: + + nzbx_guid = nzb['guid'] + + # need to filter by completed + + new = { + 'guid': nzbx_guid, + 'type': 'nzb', + 'provider': self.getName(), + 'download': nzb['nzb'], + 'name': nzb['name'], + 'age': self.calculateAge(int(nzb['postdate'])), + 'size': tryInt(nzb['size']) / 1024 / 1024, + 'check_nzb': True, + } + + is_correct_movie = fireEvent('searcher.correct_movie', + nzb = new, movie = movie, quality = quality, + imdb_results = False, single = True) + + if is_correct_movie: + new['score'] = fireEvent('score.calculate', new, movie, single = True) + results.append(new) + self.found(new) + + return results + except: + log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) + + return results + + def isEnabled(self): + return NZBProvider.isEnabled(self) and self.conf('enabled') From 031a186d71e14c4f020abd258de30cd887f8eb45 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 20 Dec 2012 15:19:40 +0100 Subject: [PATCH 2/3] NZBx fixes --- couchpotato/core/providers/nzb/nzbx/main.py | 45 ++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/couchpotato/core/providers/nzb/nzbx/main.py b/couchpotato/core/providers/nzb/nzbx/main.py index e7c2d342..138641e9 100644 --- a/couchpotato/core/providers/nzb/nzbx/main.py +++ b/couchpotato/core/providers/nzb/nzbx/main.py @@ -16,18 +16,18 @@ log = CPLog(__name__) class Nzbx(NZBProvider, RSS): - endpoint = 'https://nzbx.co/api/' - + endpoint = 'https://nzbx.co/api/' + urls = { - 'search': endpoint + 'search', - 'details': endpoint + 'details?guid=%s', - 'comments': endpoint + 'get-comments?guid=%s', - 'ratings': endpoint + 'get-votes?guid=%s', - 'downloads': endpoint + 'get-downloads-count?guid=%s', - 'categories': endpoint + 'categories', - 'groups': endpoint + 'groups', + 'search': 'https://nzbx.co/api/search', + 'details': 'https://nzbx.co/api/details?guid=%s', + 'comments': 'https://nzbx.co/api/get-comments?guid=%s', + 'ratings': 'https://nzbx.co/api/get-votes?guid=%s', + 'downloads': 'https://nzbx.co/api/get-downloads-count?guid=%s', + 'categories': 'https://nzbx.co/api/categories', + 'groups': 'https://nzbx.co/api/groups', } - + http_time_between_calls = 1 # Seconds def search(self, movie, quality): @@ -39,9 +39,9 @@ class Nzbx(NZBProvider, RSS): q = '"%s %s" %s' % (simplifyString(getTitle(movie['library'])), movie['library']['year'], quality.get('identifier')) arguments = tryUrlencode({ 'q': q, - 'l': 250, # Limit on number of files returned - #'i': '', # index of file - #'sf': '' # size filter + 'l': 250, # Limit on number of files returned + #'i': '', # index of file + #'sf': '' # size filter }) url = "%s?%s" % (self.urls['search'], arguments) @@ -59,17 +59,26 @@ class Nzbx(NZBProvider, RSS): for nzb in nzbs: nzbx_guid = nzb['guid'] - - # need to filter by completed - + + def extra_score(item): + score = 0 + if item['votes']['upvotes'] > item['votes']['downvotes']: + score += 5 + + return score + new = { 'guid': nzbx_guid, 'type': 'nzb', 'provider': self.getName(), - 'download': nzb['nzb'], + 'download': self.download, + 'url': nzb['nzb'], 'name': nzb['name'], 'age': self.calculateAge(int(nzb['postdate'])), 'size': tryInt(nzb['size']) / 1024 / 1024, + 'description': '', + 'extra_score': extra_score, + 'votes': nzb['votes'], 'check_nzb': True, } @@ -89,4 +98,4 @@ class Nzbx(NZBProvider, RSS): return results def isEnabled(self): - return NZBProvider.isEnabled(self) and self.conf('enabled') + return NZBProvider.isEnabled(self) and self.conf('enabled') \ No newline at end of file From b8e86b378fb2481b50dd70faef641f307ea89fbb Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 20 Dec 2012 15:45:04 +0100 Subject: [PATCH 3/3] NZBx provider --- .../core/providers/nzb/nzbx/__init__.py | 4 +-- couchpotato/core/providers/nzb/nzbx/main.py | 32 +++++++------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/couchpotato/core/providers/nzb/nzbx/__init__.py b/couchpotato/core/providers/nzb/nzbx/__init__.py index 9d794e3d..129fba02 100644 --- a/couchpotato/core/providers/nzb/nzbx/__init__.py +++ b/couchpotato/core/providers/nzb/nzbx/__init__.py @@ -9,8 +9,8 @@ config = [{ { 'tab': 'searcher', 'subtab': 'nzb_providers', - 'name': 'nzbx', - 'description': 'Free provider, less accurate. See nzbx', + 'name': 'nzbX', + 'description': 'Free provider, less accurate. See nzbX', 'options': [ { 'name': 'enabled', diff --git a/couchpotato/core/providers/nzb/nzbx/main.py b/couchpotato/core/providers/nzb/nzbx/main.py index 138641e9..a67f1e6f 100644 --- a/couchpotato/core/providers/nzb/nzbx/main.py +++ b/couchpotato/core/providers/nzb/nzbx/main.py @@ -1,23 +1,18 @@ from couchpotato.core.event import fireEvent -from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode, \ - simplifyString +from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.rss import RSS -from couchpotato.core.helpers.variable import tryInt, getTitle +from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider -from couchpotato.environment import Env -from dateutil.parser import parse -import re -import time -import traceback import json +import traceback log = CPLog(__name__) class Nzbx(NZBProvider, RSS): endpoint = 'https://nzbx.co/api/' - + urls = { 'search': 'https://nzbx.co/api/search', 'details': 'https://nzbx.co/api/details?guid=%s', @@ -27,27 +22,25 @@ class Nzbx(NZBProvider, RSS): 'categories': 'https://nzbx.co/api/categories', 'groups': 'https://nzbx.co/api/groups', } - + http_time_between_calls = 1 # Seconds def search(self, movie, quality): - results = [] + if self.isDisabled(): return results - q = '"%s %s" %s' % (simplifyString(getTitle(movie['library'])), movie['library']['year'], quality.get('identifier')) arguments = tryUrlencode({ - 'q': q, - 'l': 250, # Limit on number of files returned - #'i': '', # index of file - #'sf': '' # size filter + 'q': movie['library']['identifier'].replace('tt', ''), + 'sf': quality.get('size_min'), }) url = "%s?%s" % (self.urls['search'], arguments) cache_key = 'nzbx.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) data = self.getCache(cache_key, url) + if data: try: try: @@ -59,14 +52,13 @@ class Nzbx(NZBProvider, RSS): for nzb in nzbs: nzbx_guid = nzb['guid'] - + def extra_score(item): score = 0 if item['votes']['upvotes'] > item['votes']['downvotes']: score += 5 - return score - + new = { 'guid': nzbx_guid, 'type': 'nzb', @@ -97,5 +89,3 @@ class Nzbx(NZBProvider, RSS): return results - def isEnabled(self): - return NZBProvider.isEnabled(self) and self.conf('enabled') \ No newline at end of file