mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-21 16:34:01 +01:00
Newznab - require all search term words in title
- Skip Newznab result if not all the search word terms are in the result title - removed old newzbin and no longer required usenet retention code
This commit is contained in:
+9
-74
@@ -436,9 +436,11 @@ def searchNZB(album, new=False, losslessOnly=False, albumlength=None):
|
|||||||
url = item.link
|
url = item.link
|
||||||
title = item.title
|
title = item.title
|
||||||
size = int(item.links[1]['length'])
|
size = int(item.links[1]['length'])
|
||||||
|
if all(word.lower() in title.lower() for word in term.split()):
|
||||||
resultlist.append((title, size, url, provider, 'nzb'))
|
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
||||||
logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size)))
|
resultlist.append((title, size, url, provider, 'nzb'))
|
||||||
|
else:
|
||||||
|
logger.info('Skipping %s, not all search term words found' % title)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("An unknown error occurred trying to parse the feed: %s" % e)
|
logger.exception("An unknown error occurred trying to parse the feed: %s" % e)
|
||||||
@@ -880,49 +882,6 @@ def verifyresult(title, artistterm, term, lossless):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getresultNZB(result):
|
|
||||||
nzb = None
|
|
||||||
|
|
||||||
if result[3] == 'newzbin':
|
|
||||||
response = request.request_response(
|
|
||||||
url='https://www.newzbin2.es/api/dnzb/',
|
|
||||||
auth=(headphones.HPUSER, headphones.HPPASS),
|
|
||||||
params={"username": headphones.NEWZBIN_UID, "password": headphones.NEWZBIN_PASSWORD, "reportid": result[2]},
|
|
||||||
headers={'User-Agent': USER_AGENT},
|
|
||||||
whitelist_status_code=400
|
|
||||||
)
|
|
||||||
|
|
||||||
if response is not None:
|
|
||||||
if response.status_code == 400:
|
|
||||||
error_code = int(response.headers.header['X-DNZB-RCode'])
|
|
||||||
|
|
||||||
if error_code == 450:
|
|
||||||
result = re.search("wait (\d+) seconds", response.headers['X-DNZB-RText'])
|
|
||||||
seconds = int(result.group(1))
|
|
||||||
|
|
||||||
logger.info("Newzbin throttled our NZB downloading, pausing for %d seconds", seconds)
|
|
||||||
time.sleep(seconds)
|
|
||||||
|
|
||||||
# Try again -- possibly forever :(
|
|
||||||
getresultNZB(result)
|
|
||||||
else:
|
|
||||||
logger.info("Newzbin error code %d", error_code)
|
|
||||||
else:
|
|
||||||
nzb = response.content
|
|
||||||
elif result[3] == 'headphones':
|
|
||||||
nzb = request.request_content(
|
|
||||||
url=result[2],
|
|
||||||
auth=(headphones.HPUSER, headphones.HPPASS),
|
|
||||||
headers={'User-Agent': USER_AGENT}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
nzb = request.request_content(
|
|
||||||
url=result[2],
|
|
||||||
headers={'User-Agent': USER_AGENT}
|
|
||||||
)
|
|
||||||
|
|
||||||
return nzb
|
|
||||||
|
|
||||||
def searchTorrent(album, new=False, losslessOnly=False, albumlength=None):
|
def searchTorrent(album, new=False, losslessOnly=False, albumlength=None):
|
||||||
global gazelle # persistent what.cd api object to reduce number of login attempts
|
global gazelle # persistent what.cd api object to reduce number of login attempts
|
||||||
|
|
||||||
@@ -1468,37 +1427,13 @@ def preprocess(resultlist):
|
|||||||
return request.request_content(url=result[2], headers=headers), result
|
return request.request_content(url=result[2], headers=headers), result
|
||||||
|
|
||||||
else:
|
else:
|
||||||
usenet_retention = int(headphones.USENET_RETENTION or 2000)
|
|
||||||
nzb = getresultNZB(result)
|
|
||||||
|
|
||||||
if nzb:
|
headers = {'User-Agent': USER_AGENT}
|
||||||
try:
|
|
||||||
d = minidom.parseString(nzb)
|
|
||||||
node = d.documentElement
|
|
||||||
nzbfiles = d.getElementsByTagName("file")
|
|
||||||
skipping = False
|
|
||||||
for nzbfile in nzbfiles:
|
|
||||||
if int(nzbfile.getAttribute("date")) < (time.time() - usenet_retention * 86400):
|
|
||||||
logger.info('NZB contains a file out of your retention. Skipping.')
|
|
||||||
skipping = True
|
|
||||||
break
|
|
||||||
if skipping:
|
|
||||||
continue
|
|
||||||
|
|
||||||
#TODO: Do we want rar checking in here to try to keep unknowns out?
|
if result[3] == 'headphones':
|
||||||
#or at least the option to do so?
|
return request.request_content(url=result[2], headers=headers, auth=(headphones.HPUSER, headphones.HPPASS)), result
|
||||||
except Exception as e:
|
|
||||||
logger.exception('Unhandled exception. Unable to parse the best result NZB. Error: %s. (Make sure your username/password/API is correct for provider: %s', e ,result[3])
|
|
||||||
continue
|
|
||||||
|
|
||||||
return nzb, result
|
|
||||||
else:
|
else:
|
||||||
logger.error("Couldn't retrieve the best nzb. Skipping.")
|
return request.request_content(url=result[2], headers=headers), result
|
||||||
continue
|
|
||||||
|
|
||||||
return (None, None)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def CalculateTorrentHash(link, data):
|
def CalculateTorrentHash(link, data):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user