def run(self): """ Process the queue (including waits and retries) """ from sabnzbd.nzbqueue import NzbQueue self.shutdown = False while not self.shutdown: time.sleep(5) (msgid, nzo) = self.queue.get() if self.shutdown or not msgid: break if nzo.wait and nzo.wait > time.time(): self.grab(msgid, nzo) continue logging.debug("Popping msgid %s", msgid) filename, data, newzbin_cat, nzo_info = _grabnzb(msgid) if filename and data: filename = name_fixer(filename) pp = nzo.pp script = nzo.script cat = nzo.cat if cat == '*' or not cat: cat = cat_convert(newzbin_cat) priority = nzo.priority nzbname = nzo.custom_name cat, pp, script, priority = cat_to_opts(cat, pp, script, priority) try: sabnzbd.nzbqueue.insert_future_nzo(nzo, filename, msgid, data, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname, nzo_info=nzo_info) nzo.url = format_source_url(str(msgid)) except: logging.error(Ta('Failed to update newzbin job %s'), msgid) logging.info("Traceback: ", exc_info = True) NzbQueue.do.remove(nzo.nzo_id, False) msgid = None else: if filename: self.grab(msgid, nzo, float(filename)) else: # Fatal error, give up on this one bad_fetch(nzo, msgid, msg=nzo_info, retry=True) msgid = None if msgid: growler.send_notification(T('NZB added to queue'), filename, 'download') logging.debug('Stopping MSGIDGrabber')
def build_history_info(nzo, storage='', downpath='', postproc_time=0, script_output='', script_line=''): ''' Collects all the information needed for the database ''' if not downpath: downpath = nzo.downpath path = decode_factory(downpath) storage = decode_factory(storage) script_line = decode_factory(script_line) flagRepair, flagUnpack, flagDelete = nzo.repair_opts nzo_info = decode_factory(nzo.nzo_info) # Get the url and newzbin msgid report = decode_factory(nzo_info.get('msgid', '')) if report: url = format_source_url(report) else: url = decode_factory(nzo.url) #group = nzo.group completed = int(time.time()) name = decode_factory(nzo.final_name) nzb_name = decode_factory(nzo.filename) category = decode_factory(nzo.cat) pps = ['', 'R', 'U', 'D'] try: pp = pps[sabnzbd.opts_to_pp(flagRepair, flagUnpack, flagDelete)] except: pp = '' script = decode_factory(nzo.script) status = decode_factory(nzo.status) nzo_id = nzo.nzo_id bytes = nzo.bytes_downloaded if script_output: # Compress the output of the script script_log = sqlite3.Binary(zlib.compress(script_output)) # else: script_log = '' download_time = decode_factory(nzo_info.get('download_time', 0)) downloaded = nzo.bytes_downloaded completeness = 0 fail_message = decode_factory(nzo.fail_msg) url_info = nzo_info.get('more_info', '') # Get the dictionary containing the stages and their unpack process stages = decode_factory(nzo.unpack_info) # Pack the ditionary up into a single string # Stage Name is seperated by ::: stage lines by ; and stages by \r\n lines = [] for key, results in stages.iteritems(): lines.append('%s:::%s' % (key, ';'.join(results))) stage_log = '\r\n'.join(lines) return (completed, name, nzb_name, category, pp, script, report, url, status, nzo_id, storage, path, \ script_log, script_line, download_time, postproc_time, stage_log, downloaded, completeness, \ fail_message, url_info, bytes,)
def run(self): """ Process the queue (including waits and retries) """ from sabnzbd.nzbqueue import NzbQueue self.shutdown = False while not self.shutdown: time.sleep(5) (msgid, nzo) = self.queue.get() if self.shutdown or not msgid: break if nzo.wait and nzo.wait > time.time(): self.grab(msgid, nzo) continue logging.debug("Popping msgid %s", msgid) filename, data, newzbin_cat, nzo_info = _grabnzb(msgid) if filename and data: filename = name_fixer(filename) pp = nzo.pp script = nzo.script cat = nzo.cat if cat == '*' or not cat: cat = cat_convert(newzbin_cat) priority = nzo.priority nzbname = nzo.custom_name cat, pp, script, priority = cat_to_opts( cat, pp, script, priority) try: sabnzbd.nzbqueue.insert_future_nzo(nzo, filename, msgid, data, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname, nzo_info=nzo_info) nzo.url = format_source_url(str(msgid)) except: logging.error(Ta('Failed to update newzbin job %s'), msgid) logging.info("Traceback: ", exc_info=True) NzbQueue.do.remove(nzo.nzo_id, False) msgid = None else: if filename: self.grab(msgid, nzo, float(filename)) else: # Fatal error, give up on this one bad_fetch(nzo, msgid, msg=nzo_info, retry=True) msgid = None if msgid: growler.send_notification(T('NZB added to queue'), filename, 'download') logging.debug('Stopping MSGIDGrabber')
def build_history_info(nzo, storage='', downpath='', postproc_time=0, script_output='', script_line=''): ''' Collects all the information needed for the database ''' if not downpath: downpath = nzo.downpath path = decode_factory(downpath) storage = decode_factory(storage) script_line = decode_factory(script_line) flagRepair, flagUnpack, flagDelete = nzo.repair_opts nzo_info = decode_factory(nzo.nzo_info) # Get the url and newzbin msgid report = decode_factory(nzo_info.get('msgid', '')) if report: url = format_source_url(report) else: url = decode_factory(nzo.url) #group = nzo.group completed = int(time.time()) name = decode_factory(nzo.final_name) nzb_name = decode_factory(nzo.filename) category = decode_factory(nzo.cat) pps = ['','R','U','D'] try: pp = pps[sabnzbd.opts_to_pp(flagRepair, flagUnpack, flagDelete)] except: pp = '' script = decode_factory(nzo.script) status = decode_factory(nzo.status) nzo_id = nzo.nzo_id bytes = nzo.bytes_downloaded if script_output: # Compress the output of the script script_log = sqlite3.Binary(zlib.compress(script_output)) # else: script_log = '' download_time = decode_factory(nzo_info.get('download_time', 0)) downloaded = nzo.bytes_downloaded completeness = 0 fail_message = decode_factory(nzo.fail_msg) url_info = nzo_info.get('more_info', '') # Get the dictionary containing the stages and their unpack process stages = decode_factory(nzo.unpack_info) # Pack the ditionary up into a single string # Stage Name is seperated by ::: stage lines by ; and stages by \r\n lines = [] for key, results in stages.iteritems(): lines.append('%s:::%s' % (key, ';'.join(results))) stage_log = '\r\n'.join(lines) return (completed, name, nzb_name, category, pp, script, report, url, status, nzo_id, storage, path, \ script_log, script_line, download_time, postproc_time, stage_log, downloaded, completeness, \ fail_message, url_info, bytes,)