Browse Source

Keep retrying when nzbmatrix sends nonsense data.

tags/0.6.0
ShyPike 15 years ago
parent
commit
ae90471c80
  1. 198
      sabnzbd/urlgrabber.py

198
sabnzbd/urlgrabber.py

@ -74,104 +74,112 @@ class URLGrabber(Thread):
if not url: if not url:
continue continue
# If nzo entry deleted, give up
try: try:
deleted = future_nzo.deleted # If nzo entry deleted, give up
except: try:
deleted = True deleted = future_nzo.deleted
if deleted: except:
logging.debug('Dropping URL %s, job entry missing', url) deleted = True
continue if deleted:
logging.debug('Dropping URL %s, job entry missing', url)
# Add nzbmatrix credentials if needed continue
url, matrix_id = _matrix_url(url)
# Add nzbmatrix credentials if needed
# _grab_url cannot reside in a function, because the tempfile url, matrix_id = _matrix_url(url)
# would not survive the end of the function
logging.info('Grabbing URL %s', url) # _grab_url cannot reside in a function, because the tempfile
opener = urllib.FancyURLopener({}) # would not survive the end of the function
opener.prompt_user_passwd = None logging.info('Grabbing URL %s', url)
opener.addheaders = [] opener = urllib.FancyURLopener({})
opener.addheader('User-Agent', 'SABnzbd+/%s' % sabnzbd.version.__version__) opener.prompt_user_passwd = None
opener.addheader('Accept-encoding','gzip') opener.addheaders = []
filename = None opener.addheader('User-Agent', 'SABnzbd+/%s' % sabnzbd.version.__version__)
category = None opener.addheader('Accept-encoding','gzip')
nzo_info = {} filename = None
try: category = None
fn, header = opener.retrieve(url) nzo_info = {}
except: try:
fn = None fn, header = opener.retrieve(url)
except:
if fn: fn = None
for tup in header.items():
try: if fn:
item = tup[0].lower() for tup in header.items():
value = tup[1].strip() try:
except: item = tup[0].lower()
continue value = tup[1].strip()
if item in ('category_id', 'x-dnzb-category'): except:
category = value continue
elif item in ('x-dnzb-moreinfo',): if item in ('category_id', 'x-dnzb-category'):
nzo_info['more_info'] = value category = value
elif item in ('x-dnzb-name',): elif item in ('x-dnzb-moreinfo',):
filename = value nzo_info['more_info'] = value
if not filename.endswith('.nzb'): elif item in ('x-dnzb-name',):
filename += '.nzb' filename = value
if not filename.endswith('.nzb'):
if not filename: filename += '.nzb'
for item in tup:
if "filename=" in item: if not filename:
filename = item[item.index("filename=") + 9:].strip(';').strip('"') for item in tup:
if "filename=" in item:
if matrix_id: filename = item[item.index("filename=") + 9:].strip(';').strip('"')
fn, msg, retry = _analyse_matrix(fn, matrix_id)
category = map_matrix(category) if matrix_id:
else: fn, msg, retry = _analyse_matrix(fn, matrix_id)
msg = '' category = map_matrix(category)
retry = True
# Check if the filepath is specified, if not, check if a retry is allowed.
if not fn:
retry_count -= 1
if retry_count > 0 and retry:
logging.info('Retry URL %s', url)
self.queue.put((url, future_nzo, retry_count))
else: else:
misc.bad_fetch(future_nzo, url, msg, retry=True) msg = ''
continue retry = True
if not filename: # Check if the filepath is specified, if not, check if a retry is allowed.
filename = os.path.basename(url) + '.nzb' if not fn:
filename = misc.sanitize_foldername(filename) retry_count -= 1
pp = future_nzo.pp if retry_count > 0 and retry:
script = future_nzo.script logging.info('Retry URL %s', url)
cat = future_nzo.cat self.queue.put((url, future_nzo, retry_count))
if cat is None and category: else:
cat = misc.cat_convert(category) misc.bad_fetch(future_nzo, url, msg, retry=True)
priority = future_nzo.priority continue
nzbname = future_nzo.custom_name
if not filename:
# Check if nzb file filename = os.path.basename(url) + '.nzb'
if os.path.splitext(filename)[1].lower() in ('.nzb', '.gz'): filename = misc.sanitize_foldername(filename)
res = dirscanner.ProcessSingleFile(filename, fn, pp=pp, script=script, cat=cat, priority=priority, \ pp = future_nzo.pp
nzbname=nzbname, nzo_info=nzo_info) script = future_nzo.script
if res == 0: cat = future_nzo.cat
nzbqueue.remove_nzo(future_nzo.nzo_id, add_to_history=False, unload=True) if cat is None and category:
elif res == -2: cat = misc.cat_convert(category)
self.add(url, future_nzo) priority = future_nzo.priority
else: nzbname = future_nzo.custom_name
misc.bad_fetch(future_nzo, url, retry=True, content=True)
# Check if a supported archive # Check if nzb file
else: if os.path.splitext(filename)[1].lower() in ('.nzb', '.gz'):
if dirscanner.ProcessArchiveFile(filename, fn, pp, script, cat, priority=priority) == 0: res = dirscanner.ProcessSingleFile(filename, fn, pp=pp, script=script, cat=cat, priority=priority, \
nzbqueue.remove_nzo(future_nzo.nzo_id, add_to_history=False, unload=True) nzbname=nzbname, nzo_info=nzo_info)
if res == 0:
nzbqueue.remove_nzo(future_nzo.nzo_id, add_to_history=False, unload=True)
elif res == -2:
self.add(url, future_nzo)
elif matrix_id:
# Keep retrying NzbMatrix forever
self.add(url, future_nzo)
else:
misc.bad_fetch(future_nzo, url, retry=True, content=True)
# Check if a supported archive
else: else:
# Not a supported filetype, not an nzb (text/html ect) if dirscanner.ProcessArchiveFile(filename, fn, pp, script, cat, priority=priority) == 0:
try: nzbqueue.remove_nzo(future_nzo.nzo_id, add_to_history=False, unload=True)
os.remove(fn) else:
except: # Not a supported filetype, not an nzb (text/html ect)
pass try:
misc.bad_fetch(future_nzo, url, retry=True, content=True) os.remove(fn)
except:
pass
misc.bad_fetch(future_nzo, url, retry=True, content=True)
except:
logging.error('URLGRABBER CRASHED', exc_info=True)
logging.debug("URLGRABBER Traceback: ", exc_info=True)
# Don't pound the website! # Don't pound the website!
time.sleep(5.0) time.sleep(5.0)

Loading…
Cancel
Save