mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-11 14:19:29 +01:00
Commented out nzbmatrix and newzbin code, added in nzbsrus api - but service appears to be offline so can't test it right now - might need to switch to rss feed
This commit is contained in:
@@ -173,65 +173,65 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
||||
|
||||
resultlist = []
|
||||
|
||||
if headphones.NZBMATRIX:
|
||||
provider = "nzbmatrix"
|
||||
if headphones.PREFERRED_QUALITY == 3 or losslessOnly:
|
||||
categories = "23"
|
||||
elif headphones.PREFERRED_QUALITY:
|
||||
categories = "23,22"
|
||||
else:
|
||||
categories = "22"
|
||||
|
||||
# Search Audiobooks/Singles/etc
|
||||
if albums['Type'] == "Other":
|
||||
categories = "49"
|
||||
logger.info("Album type is audiobook/spokenword. Using audiobook category")
|
||||
if albums['Type'] == "Single":
|
||||
categories = "47"
|
||||
logger.info("Album type is 'Single'. Using singles category")
|
||||
|
||||
# For some reason NZBMatrix is erroring out/timing out when the term starts with a "The" right now
|
||||
# so we'll strip it out for the time being. This may get fixed on their end, it may not, but
|
||||
# hopefully this will fix it for now. If you notice anything else it gets stuck on, please post it
|
||||
# on Github so it can be added
|
||||
if term.lower().startswith("the "):
|
||||
term = term[4:]
|
||||
|
||||
|
||||
params = { "page": "download",
|
||||
"username": headphones.NZBMATRIX_USERNAME,
|
||||
"apikey": headphones.NZBMATRIX_APIKEY,
|
||||
"subcat": categories,
|
||||
"maxage": headphones.USENET_RETENTION,
|
||||
"english": 1,
|
||||
"ssl": 1,
|
||||
"scenename": 1,
|
||||
"term": term
|
||||
}
|
||||
|
||||
searchURL = "https://rss.nzbmatrix.com/rss.php?" + urllib.urlencode(params)
|
||||
logger.info(u'Parsing results from <a href="%s">NZBMatrix</a>' % searchURL)
|
||||
try:
|
||||
data = urllib2.urlopen(searchURL, timeout=20).read()
|
||||
except urllib2.URLError, e:
|
||||
logger.warn('Error fetching data from NZBMatrix: %s' % e)
|
||||
data = False
|
||||
|
||||
if data:
|
||||
|
||||
d = feedparser.parse(data)
|
||||
|
||||
for item in d.entries:
|
||||
try:
|
||||
url = item.link
|
||||
title = item.title
|
||||
size = int(item.links[1]['length'])
|
||||
|
||||
resultlist.append((title, size, url, provider))
|
||||
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||
|
||||
except AttributeError, e:
|
||||
logger.info(u"No results found from NZBMatrix for %s" % term)
|
||||
# if headphones.NZBMATRIX:
|
||||
# provider = "nzbmatrix"
|
||||
# if headphones.PREFERRED_QUALITY == 3 or losslessOnly:
|
||||
# categories = "23"
|
||||
# elif headphones.PREFERRED_QUALITY:
|
||||
# categories = "23,22"
|
||||
# else:
|
||||
# categories = "22"
|
||||
#
|
||||
# # Search Audiobooks/Singles/etc
|
||||
# if albums['Type'] == "Other":
|
||||
# categories = "49"
|
||||
# logger.info("Album type is audiobook/spokenword. Using audiobook category")
|
||||
# if albums['Type'] == "Single":
|
||||
# categories = "47"
|
||||
# logger.info("Album type is 'Single'. Using singles category")
|
||||
#
|
||||
# # For some reason NZBMatrix is erroring out/timing out when the term starts with a "The" right now
|
||||
# # so we'll strip it out for the time being. This may get fixed on their end, it may not, but
|
||||
# # hopefully this will fix it for now. If you notice anything else it gets stuck on, please post it
|
||||
# # on Github so it can be added
|
||||
# if term.lower().startswith("the "):
|
||||
# term = term[4:]
|
||||
#
|
||||
#
|
||||
# params = { "page": "download",
|
||||
# "username": headphones.NZBMATRIX_USERNAME,
|
||||
# "apikey": headphones.NZBMATRIX_APIKEY,
|
||||
# "subcat": categories,
|
||||
# "maxage": headphones.USENET_RETENTION,
|
||||
# "english": 1,
|
||||
# "ssl": 1,
|
||||
# "scenename": 1,
|
||||
# "term": term
|
||||
# }
|
||||
#
|
||||
# searchURL = "https://rss.nzbmatrix.com/rss.php?" + urllib.urlencode(params)
|
||||
# logger.info(u'Parsing results from <a href="%s">NZBMatrix</a>' % searchURL)
|
||||
# try:
|
||||
# data = urllib2.urlopen(searchURL, timeout=20).read()
|
||||
# except urllib2.URLError, e:
|
||||
# logger.warn('Error fetching data from NZBMatrix: %s' % e)
|
||||
# data = False
|
||||
#
|
||||
# if data:
|
||||
#
|
||||
# d = feedparser.parse(data)
|
||||
#
|
||||
# for item in d.entries:
|
||||
# try:
|
||||
# url = item.link
|
||||
# title = item.title
|
||||
# size = int(item.links[1]['length'])
|
||||
#
|
||||
# resultlist.append((title, size, url, provider))
|
||||
# logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||
#
|
||||
# except AttributeError, e:
|
||||
# logger.info(u"No results found from NZBMatrix for %s" % term)
|
||||
|
||||
if headphones.NEWZNAB:
|
||||
|
||||
@@ -359,89 +359,149 @@ def searchNZB(albumid=None, new=False, losslessOnly=False):
|
||||
|
||||
except Exception, e:
|
||||
logger.error(u"An unknown error occurred trying to parse the feed: %s" % e)
|
||||
|
||||
if headphones.NEWZBIN:
|
||||
provider = "newzbin"
|
||||
providerurl = "https://www.newzbin2.es/"
|
||||
|
||||
if headphones.NZBSRUS:
|
||||
|
||||
provider = "nzbsrus"
|
||||
categories = "54"
|
||||
|
||||
if headphones.PREFERRED_QUALITY == 3 or losslessOnly:
|
||||
categories = "7" #music
|
||||
format = "2" #flac
|
||||
sub = "16"
|
||||
elif headphones.PREFERRED_QUALITY:
|
||||
categories = "7" #music
|
||||
format = "10" #mp3+flac
|
||||
sub = ""
|
||||
else:
|
||||
categories = "7" #music
|
||||
format = "8" #mp3
|
||||
|
||||
sub = "15"
|
||||
|
||||
if albums['Type'] == 'Other':
|
||||
categories = "13"
|
||||
format = "16"
|
||||
logger.info("Album type is audiobook/spokenword. Using audiobook category")
|
||||
|
||||
params = {
|
||||
"fpn": "p",
|
||||
'u_nfo_posts_only': 0,
|
||||
'u_url_posts_only': 0,
|
||||
'u_comment_posts_only': 0,
|
||||
'u_show_passworded': 0,
|
||||
"searchaction": "Search",
|
||||
#"dl": 1,
|
||||
"category": categories,
|
||||
"retention": headphones.USENET_RETENTION,
|
||||
"ps_rb_audio_format": format,
|
||||
"feed": "rss",
|
||||
"u_post_results_amt": 50, #this can default to a high number per user
|
||||
"hauth": 1,
|
||||
"q": term
|
||||
}
|
||||
searchURL = providerurl + "search/?%s" % urllib.urlencode(params)
|
||||
try:
|
||||
data = getNewzbinURL(searchURL)
|
||||
except exceptions.NewzbinAPIThrottled:
|
||||
#try again if we were throttled
|
||||
data = getNewzbinURL(searchURL)
|
||||
if data:
|
||||
logger.info(u'Parsing results from <a href="%s">%s</a>' % (searchURL, providerurl))
|
||||
|
||||
try:
|
||||
d = minidom.parseString(data)
|
||||
node = d.documentElement
|
||||
items = d.getElementsByTagName("item")
|
||||
except ExpatError:
|
||||
logger.info('Unable to get the NEWZBIN feed. Check that your settings are correct - post a bug if they are')
|
||||
items = []
|
||||
|
||||
if len(items):
|
||||
|
||||
for item in items:
|
||||
|
||||
sizenode = item.getElementsByTagName("report:size")[0].childNodes
|
||||
titlenode = item.getElementsByTagName("title")[0].childNodes
|
||||
linknode = item.getElementsByTagName("link")[0].childNodes
|
||||
|
||||
for node in sizenode:
|
||||
size = int(node.data)
|
||||
for node in titlenode:
|
||||
title = node.data
|
||||
for node in linknode:
|
||||
url = node.data
|
||||
|
||||
#exract the reportid from the link nodes
|
||||
id_regex = re.escape(providerurl) + 'browse/post/(\d+)/'
|
||||
id_match = re.match(id_regex, url)
|
||||
if not id_match:
|
||||
logger.info("Didn't find a valid Newzbin reportid in linknode")
|
||||
else:
|
||||
url = id_match.group(1) #we have to make a post request later, need the id
|
||||
if url:
|
||||
resultlist.append((title, size, url, provider))
|
||||
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||
else:
|
||||
logger.info('No url link found in nzb. Skipping.')
|
||||
|
||||
else:
|
||||
logger.info('No results found from NEWZBIN for %s' % term)
|
||||
sub = ""
|
||||
logger.info("Album type is audiobook/spokenword. Searching all music categories")
|
||||
|
||||
params = { "uid": headphones.NZBSRUS_UID,
|
||||
"key": headphones.NZBSRUS_APIKEY,
|
||||
"cat": categories,
|
||||
"sub": sub,
|
||||
"age": headphones.USENET_RETENTION,
|
||||
"searchtext": term
|
||||
}
|
||||
|
||||
searchURL = 'https://www.nzbsrus.com/api.php?' + urllib.urlencode(params)
|
||||
|
||||
# Add a user-agent
|
||||
request = urllib2.Request(searchURL)
|
||||
request.add_header('User-Agent', 'headphones/0.0 +https://github.com/rembo10/headphones')
|
||||
opener = urllib2.build_opener()
|
||||
|
||||
logger.info(u'Parsing results from <a href="%s">NZBsRus</a>' % searchURL)
|
||||
|
||||
try:
|
||||
data = opener.open(request).read()
|
||||
except Exception, e:
|
||||
logger.warn('Error fetching data from NZBsRus: %s' % e)
|
||||
data = False
|
||||
|
||||
if data:
|
||||
|
||||
d = feedparser.parse(data)
|
||||
|
||||
if not len(d.entries):
|
||||
logger.info(u"No results found from NZBsRus for %s" % term)
|
||||
pass
|
||||
|
||||
else:
|
||||
for item in d.entries:
|
||||
try:
|
||||
url = item.link
|
||||
title = item.title
|
||||
size = int(item.links[1]['length'])
|
||||
|
||||
resultlist.append((title, size, url, provider))
|
||||
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||
|
||||
except Exception, e:
|
||||
logger.error(u"An unknown error occurred trying to parse the feed: %s" % e)
|
||||
|
||||
# if headphones.NEWZBIN:
|
||||
# provider = "newzbin"
|
||||
# providerurl = "https://www.newzbin2.es/"
|
||||
# if headphones.PREFERRED_QUALITY == 3 or losslessOnly:
|
||||
# categories = "7" #music
|
||||
# format = "2" #flac
|
||||
# elif headphones.PREFERRED_QUALITY:
|
||||
# categories = "7" #music
|
||||
# format = "10" #mp3+flac
|
||||
# else:
|
||||
# categories = "7" #music
|
||||
# format = "8" #mp3
|
||||
#
|
||||
# if albums['Type'] == 'Other':
|
||||
# categories = "13"
|
||||
# format = "16"
|
||||
# logger.info("Album type is audiobook/spokenword. Using audiobook category")
|
||||
#
|
||||
# params = {
|
||||
# "fpn": "p",
|
||||
# 'u_nfo_posts_only': 0,
|
||||
# 'u_url_posts_only': 0,
|
||||
# 'u_comment_posts_only': 0,
|
||||
# 'u_show_passworded': 0,
|
||||
# "searchaction": "Search",
|
||||
# #"dl": 1,
|
||||
# "category": categories,
|
||||
# "retention": headphones.USENET_RETENTION,
|
||||
# "ps_rb_audio_format": format,
|
||||
# "feed": "rss",
|
||||
# "u_post_results_amt": 50, #this can default to a high number per user
|
||||
# "hauth": 1,
|
||||
# "q": term
|
||||
# }
|
||||
# searchURL = providerurl + "search/?%s" % urllib.urlencode(params)
|
||||
# try:
|
||||
# data = getNewzbinURL(searchURL)
|
||||
# except exceptions.NewzbinAPIThrottled:
|
||||
# #try again if we were throttled
|
||||
# data = getNewzbinURL(searchURL)
|
||||
# if data:
|
||||
# logger.info(u'Parsing results from <a href="%s">%s</a>' % (searchURL, providerurl))
|
||||
#
|
||||
# try:
|
||||
# d = minidom.parseString(data)
|
||||
# node = d.documentElement
|
||||
# items = d.getElementsByTagName("item")
|
||||
# except ExpatError:
|
||||
# logger.info('Unable to get the NEWZBIN feed. Check that your settings are correct - post a bug if they are')
|
||||
# items = []
|
||||
#
|
||||
# if len(items):
|
||||
#
|
||||
# for item in items:
|
||||
#
|
||||
# sizenode = item.getElementsByTagName("report:size")[0].childNodes
|
||||
# titlenode = item.getElementsByTagName("title")[0].childNodes
|
||||
# linknode = item.getElementsByTagName("link")[0].childNodes
|
||||
#
|
||||
# for node in sizenode:
|
||||
# size = int(node.data)
|
||||
# for node in titlenode:
|
||||
# title = node.data
|
||||
# for node in linknode:
|
||||
# url = node.data
|
||||
#
|
||||
# #exract the reportid from the link nodes
|
||||
# id_regex = re.escape(providerurl) + 'browse/post/(\d+)/'
|
||||
# id_match = re.match(id_regex, url)
|
||||
# if not id_match:
|
||||
# logger.info("Didn't find a valid Newzbin reportid in linknode")
|
||||
# else:
|
||||
# url = id_match.group(1) #we have to make a post request later, need the id
|
||||
# if url:
|
||||
# resultlist.append((title, size, url, provider))
|
||||
# logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||
# else:
|
||||
# logger.info('No url link found in nzb. Skipping.')
|
||||
#
|
||||
# else:
|
||||
# logger.info('No results found from NEWZBIN for %s' % term)
|
||||
#
|
||||
#attempt to verify that this isn't a substring result
|
||||
#when looking for "Foo - Foo" we don't want "Foobar"
|
||||
#this should be less of an issue when it isn't a self-titled album so we'll only check vs artist
|
||||
|
||||
Reference in New Issue
Block a user