def add(self, nzo: NzbObject, save=True, quiet=False) -> str: if not nzo.nzo_id: nzo.nzo_id = sabnzbd.get_new_id("nzo", nzo.admin_path, self.__nzo_table) # If no files are to be downloaded anymore, send to postproc if not nzo.files and not nzo.futuretype: self.end_job(nzo) return nzo.nzo_id # Reset try_lists, markers and evaluate the scheduling settings nzo.reset_try_list() nzo.deleted = False priority = nzo.priority if sabnzbd.Scheduler.analyse(False, priority): nzo.status = Status.PAUSED self.__nzo_table[nzo.nzo_id] = nzo if priority > HIGH_PRIORITY: # Top and repair priority items are added to the top of the queue self.__nzo_list.insert(0, nzo) elif priority == LOW_PRIORITY: self.__nzo_list.append(nzo) else: # for high priority we need to add the item at the bottom # of any other high priority items above the normal priority # for normal priority we need to add the item at the bottom # of the normal priority items above the low priority if self.__nzo_list: pos = 0 added = False for position in self.__nzo_list: if position.priority < priority: self.__nzo_list.insert(pos, nzo) added = True break pos += 1 if not added: # if there are no other items classed as a lower priority # then it will be added to the bottom of the queue self.__nzo_list.append(nzo) else: # if the queue is empty then simple append the item to the bottom self.__nzo_list.append(nzo) if save: self.save(nzo) if not (quiet or nzo.status == Status.FETCHING): notifier.send_notification(T("NZB added to queue"), nzo.filename, "download", nzo.cat) if not quiet and cfg.auto_sort(): try: field, direction = cfg.auto_sort().split() self.sort_queue(field, direction) except ValueError: pass return nzo.nzo_id
def end_job(self, nzo: NzbObject): """ Send NZO to the post-processing queue """ # Notify assembler to call postprocessor if not nzo.deleted: logging.info("[%s] Ending job %s", caller_name(), nzo.final_name) nzo.deleted = True if nzo.precheck: nzo.save_to_disk() # Check result enough, _ = nzo.check_availability_ratio() if enough: # Enough data present, do real download self.send_back(nzo) return else: # Not enough data, let postprocessor show it as failed pass sabnzbd.Assembler.process(nzo)