def ProcessArchiveFile(filename, path, pp=None, script=None, cat=None, catdir=None, keep=False, priority=None, url='', nzbname=None): """ Analyse ZIP file and create job(s). Accepts ZIP files with ONLY nzb/nfo/folder files in it. returns (status, nzo_ids) status: -1==Error/Retry, 0==OK, 1==Ignore """ from sabnzbd.nzbqueue import add_nzo nzo_ids = [] if catdir is None: catdir = cat filename, cat = name_to_cat(filename, catdir) if zipfile.is_zipfile(path): try: zf = zipfile.ZipFile(path) except: return -1, [] elif is_rarfile(path): try: zf = RarFile(path) except: return -1, [] else: return 1, [] status = 1 names = zf.namelist() names.sort() nzbcount = 0 for name in names: name = name.lower() if not (name.endswith('.nzb') or name.endswith('.nfo') or name.endswith('/')): status = 1 break elif name.endswith('.nzb'): status = 0 nzbcount += 1 if status == 0: if nzbcount != 1: nzbname = None for name in names: if name.lower().endswith('.nzb'): try: data = zf.read(name) except: zf.close() return -1, [] name = re.sub(r'\[.*nzbmatrix.com\]', '', name) name = os.path.basename(name) name = misc.sanitize_foldername(name) if data: try: nzo = nzbstuff.NzbObject(name, 0, pp, script, data, cat=cat, url=url, priority=priority, nzbname=nzbname) except: nzo = None if nzo: nzo_ids.append(add_nzo(nzo)) nzo.update_rating() zf.close() try: if not keep: os.remove(path) except: logging.error(Ta('Error removing %s'), path) logging.info("Traceback: ", exc_info = True) status = 1 else: zf.close() status = 1 return status, nzo_ids
def ProcessArchiveFile(filename, path, pp=None, script=None, cat=None, catdir=None, keep=False, priority=None, url='', nzbname=None, password=None, nzo_id=None): """ Analyse ZIP file and create job(s). Accepts ZIP files with ONLY nzb/nfo/folder files in it. returns (status, nzo_ids) status: -1==Error/Retry, 0==OK, 1==Ignore """ from sabnzbd.nzbqueue import add_nzo nzo_ids = [] if catdir is None: catdir = cat filename, cat = name_to_cat(filename, catdir) if zipfile.is_zipfile(path): try: zf = zipfile.ZipFile(path) except: return -1, [] elif is_rarfile(path): try: zf = RarFile(path) except: return -1, [] elif is_sevenfile(path): try: zf = SevenZip(path) except: return -1, [] else: return 1, [] status = 1 names = zf.namelist() names.sort() nzbcount = 0 for name in names: name = name.lower() if not (name.endswith('.nzb') or name.endswith('.nfo') or name.endswith('/')): status = 1 break elif name.endswith('.nzb'): status = 0 nzbcount += 1 if status == 0: if nzbcount != 1: nzbname = None for name in names: if name.lower().endswith('.nzb'): try: data = zf.read(name) except: zf.close() return -1, [] name = os.path.basename(name) if data: try: nzo = nzbstuff.NzbObject(name, pp, script, data, cat=cat, url=url, priority=priority, nzbname=nzbname) if not nzo.password: nzo.password = password except: nzo = None if nzo: if nzo_id: # Re-use existing nzo_id, when a "future" job gets it payload sabnzbd.nzbqueue.NzbQueue.do.remove(nzo_id, add_to_history=False) nzo.nzo_id = nzo_id nzo_ids.append(add_nzo(nzo)) nzo.update_rating() zf.close() try: if not keep: os.remove(path) except: logging.error(T('Error removing %s'), misc.clip_path(path)) logging.info("Traceback: ", exc_info=True) status = 1 else: zf.close() status = 1 return status, nzo_ids