Newznab feed
This commit is contained in:
@@ -136,6 +136,10 @@ class NZBProvider(YarrProvider):
|
|||||||
addEvent('provider.yarr.search', self.search)
|
addEvent('provider.yarr.search', self.search)
|
||||||
|
|
||||||
addEvent('provider.nzb.feed', self.feed)
|
addEvent('provider.nzb.feed', self.feed)
|
||||||
|
|
||||||
|
def feed(self):
|
||||||
|
return []
|
||||||
|
|
||||||
def search(self, movie, quality):
|
def search(self, movie, quality):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -36,21 +36,52 @@ class Newznab(NZBProvider, RSS):
|
|||||||
|
|
||||||
self.registerStatic(__file__)
|
self.registerStatic(__file__)
|
||||||
|
|
||||||
def getUrl(self, host, type):
|
addEvent('app.load', self.feed)
|
||||||
return cleanHost(host) + 'api?t=' + type
|
|
||||||
|
def feed(self):
|
||||||
|
|
||||||
|
hosts = self.getHosts()
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for host in hosts:
|
||||||
|
result = self.singleFeed(host)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
results.extend(result)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def singleFeed(self, host):
|
||||||
|
|
||||||
|
results = []
|
||||||
|
if self.isDisabled(host) or not self.isAvailable(self.getUrl(host['host'], self.urls['search'])):
|
||||||
|
return results
|
||||||
|
|
||||||
|
arguments = urlencode({
|
||||||
|
't': self.cat_backup_id,
|
||||||
|
'r': host['api_key'],
|
||||||
|
'i': 58,
|
||||||
|
})
|
||||||
|
url = "%s?%s" % (cleanHost(host['host']) + 'rss', arguments)
|
||||||
|
cache_key = 'newznab.%s.feed.%s' % (host['host'], arguments)
|
||||||
|
|
||||||
|
results = self.createItems(url, cache_key, host, for_feed = True)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def search(self, movie, quality):
|
def search(self, movie, quality):
|
||||||
|
|
||||||
uses = str(self.conf('use')).split(',')
|
hosts = self.getHosts()
|
||||||
hosts = self.conf('host').split(',')
|
|
||||||
api_keys = self.conf('api_key').split(',')
|
|
||||||
|
|
||||||
for nr in range(len(hosts)):
|
results = []
|
||||||
self.singleSearch({
|
for host in hosts:
|
||||||
'use': uses[nr],
|
result = self.singleSearch(host, movie, quality)
|
||||||
'host': hosts[nr],
|
|
||||||
'api_key': api_keys[nr]
|
if result:
|
||||||
}, movie, quality)
|
results.extend(result)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
def singleSearch(self, host, movie, quality):
|
def singleSearch(self, host, movie, quality):
|
||||||
|
|
||||||
@@ -71,6 +102,13 @@ class Newznab(NZBProvider, RSS):
|
|||||||
cache_key = 'newznab.%s.%s.%s' % (host['host'], movie['library']['identifier'], cat_id[0])
|
cache_key = 'newznab.%s.%s.%s' % (host['host'], movie['library']['identifier'], cat_id[0])
|
||||||
single_cat = (len(cat_id) == 1 and cat_id[0] != self.cat_backup_id)
|
single_cat = (len(cat_id) == 1 and cat_id[0] != self.cat_backup_id)
|
||||||
|
|
||||||
|
results = self.createItems(url, cache_key, host, single_cat = single_cat, movie = movie, quality = quality)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def createItems(self, url, cache_key, host, single_cat = False, movie = None, quality = None, for_feed = False):
|
||||||
|
results = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = self.getCache(cache_key)
|
data = self.getCache(cache_key)
|
||||||
if not data:
|
if not data:
|
||||||
@@ -109,22 +147,43 @@ class Newznab(NZBProvider, RSS):
|
|||||||
'detail_url': (self.getUrl(host['host'], self.urls['detail']) % id) + self.getApiExt(host),
|
'detail_url': (self.getUrl(host['host'], self.urls['detail']) % id) + self.getApiExt(host),
|
||||||
'content': self.getTextElement(nzb, "description"),
|
'content': self.getTextElement(nzb, "description"),
|
||||||
}
|
}
|
||||||
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
|
||||||
|
|
||||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
if not for_feed:
|
||||||
nzb = new, movie = movie, quality = quality,
|
new['score'] = fireEvent('score.calculate', new, movie, single = True)
|
||||||
imdb_results = True, single_category = single_cat, single = True)
|
|
||||||
|
|
||||||
if is_correct_movie:
|
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||||
|
nzb = new, movie = movie, quality = quality,
|
||||||
|
imdb_results = True, single_category = single_cat, single = True)
|
||||||
|
|
||||||
|
if is_correct_movie:
|
||||||
|
results.append(new)
|
||||||
|
self.found(new)
|
||||||
|
else:
|
||||||
results.append(new)
|
results.append(new)
|
||||||
self.found(new)
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
log.error('Failed to parse XML response from Newznab')
|
log.error('Failed to parse XML response from Newznab: %s' % host)
|
||||||
return False
|
return results
|
||||||
|
|
||||||
return results
|
def getHosts(self):
|
||||||
|
|
||||||
|
uses = str(self.conf('use')).split(',')
|
||||||
|
hosts = self.conf('host').split(',')
|
||||||
|
api_keys = self.conf('api_key').split(',')
|
||||||
|
|
||||||
|
list = []
|
||||||
|
for nr in range(len(hosts)):
|
||||||
|
list.append({
|
||||||
|
'use': uses[nr],
|
||||||
|
'host': hosts[nr],
|
||||||
|
'api_key': api_keys[nr]
|
||||||
|
})
|
||||||
|
|
||||||
|
return list
|
||||||
|
|
||||||
|
def getUrl(self, host, type):
|
||||||
|
return cleanHost(host) + 'api?t=' + type
|
||||||
|
|
||||||
def isDisabled(self, host):
|
def isDisabled(self, host):
|
||||||
return not self.isEnabled(host)
|
return not self.isEnabled(host)
|
||||||
|
|||||||
Reference in New Issue
Block a user