You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.1 KiB

13 years ago
from couchpotato.core.event import fireEvent
13 years ago
from couchpotato.core.helpers.encoding import tryUrlencode
13 years ago
from couchpotato.core.helpers.rss import RSS
13 years ago
from couchpotato.core.helpers.variable import tryInt
13 years ago
from couchpotato.core.logger import CPLog
from couchpotato.core.providers.nzb.base import NZBProvider
import json
13 years ago
import traceback
13 years ago
log = CPLog(__name__)
class Nzbx(NZBProvider, RSS):
13 years ago
endpoint = 'https://nzbx.co/api/'
13 years ago
13 years ago
urls = {
13 years ago
'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',
13 years ago
}
13 years ago
13 years ago
http_time_between_calls = 1 # Seconds
def search(self, movie, quality):
results = []
13 years ago
13 years ago
if self.isDisabled():
return results
arguments = tryUrlencode({
13 years ago
'q': movie['library']['identifier'].replace('tt', ''),
'sf': quality.get('size_min'),
13 years ago
})
url = "%s?%s" % (self.urls['search'], arguments)
cache_key = 'nzbx.%s.%s' % (movie['library']['identifier'], quality.get('identifier'))
data = self.getCache(cache_key, url)
13 years ago
13 years ago
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']
13 years ago
13 years ago
def extra_score(item):
score = 0
if item['votes']['upvotes'] > item['votes']['downvotes']:
score += 5
return score
13 years ago
13 years ago
new = {
'guid': nzbx_guid,
'type': 'nzb',
'provider': self.getName(),
13 years ago
'download': self.download,
'url': nzb['nzb'],
13 years ago
'name': nzb['name'],
'age': self.calculateAge(int(nzb['postdate'])),
'size': tryInt(nzb['size']) / 1024 / 1024,
13 years ago
'description': '',
'extra_score': extra_score,
'votes': nzb['votes'],
13 years ago
'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