def main(): """ We need to check to make sure the script can run in the provided environment and that certain status checks have occurred. All of the calls here will exit with an exit code if the check fails. """ try: # If the script state was set to Disabled, we don't need to run. if SCRIPT_STATE == 'Disabled': nzb.exit(nzb.PROCESS_SUCCESS) # Check the version NZBGet we're running on. nzb.check_nzb_version(13.0) nzb.log_info('CURRENT EVENT: %s' % nzb.get_nzb_event()) # Wire up your event handlers before the call. # User the form nzb.set_handler(<event>, <function>) nzb.set_handler('FILE_DOWNLOADED', on_file_downloaded) nzb.set_handler('NZB_ADDED', on_nzb_added) nzb.set_handler('NZB_DOWNLOADED', on_nzb_downloaded) nzb.set_handler('POST_PROCESSING', on_post_processing) nzb.set_handler('QUEUEING', on_queueing) nzb.set_handler('SCANNING', on_scanning) nzb.set_handler('SCHEDULED', on_scheduled) # Do not change this line, it checks the current event # and executes any event handlers. nzb.execute() except Exception as e: traceback.print_exc() nzb.exit(nzb.PROCESS_ERROR, e) nzb.exit(nzb.PROCESS_SUCCESS)
def log_environment(): if SCRIPT_OUTPUT == 'Disabled': return elif SCRIPT_OUTPUT == 'Keys': keys = [] for key in os.environ.keys(): if not key_filtered(key): for prefix in PREFIX_FILTERS: if key.startswith(prefix): keys.append(key) nzb.log_info(' '.join(keys)) elif SCRIPT_OUTPUT == 'Pairs': variables = [] for key in os.environ.keys(): if not key_filtered(key): for prefix in PREFIX_FILTERS: if key.startswith(prefix): variables.append('%s = %s' % (key, os.environ[key])) variables.sort() for variable in variables: nzb.log_info(variable)
def reorder_queued_items(nzbid): """ Finds the last part of the RAR archive and moves to the top of the queue. """ # If another script already sorted, then we can skip sorting. if bool(nzb.get_script_variable('RAR_SORTED')): nzb.log_info('Last RAR file was already sorted.') return # Get the list of files for this NZB. proxy = nzb.proxy() filelist = proxy.listfiles(0, 0, nzbid) # Enumerate the RAR files from the NZB and try to parse the part number. files = nzb.get_rar_xmlfiles(filelist) # If we found RAR files, we need to sort so that the last RAR file is the first # item in the list. if files: files_sorted = sorted(files, key=operator.itemgetter('number'), reverse=True) filename = files_sorted[0]['filename'] fileid = int(files_sorted[0]['fileid']) if proxy.editqueue('FileMoveTop', 0, '', [fileid]): nzb.log_detail('Moved last RAR file %s to the top.' % filename) nzb.set_script_variable('RAR_SORTED', True) else: nzb.log_warning('Failed to move the last RAR file %s.' % filename) else: nzb.log_warning('Failed to get list of files to sort.')
def main(): """ We need to check to make sure the script can run in the provided environment and that certain status checks have occurred. All of the calls here will exit with an exit code if the check fails. """ try: # If the script state was set to Disabled, we don't need to run. if SCRIPT_STATE == 'Disabled': nzb.exit(nzb.PROCESS_SUCCESS) # Determine if we have features enabled. DiscImageEnabled = REJECT_DISC_IMAGES != 'Disabled' FakeCheckEnabled = REJECT_FAKES != 'Disabled' PasswordCheckEnabled = REJECT_PASSWORD != 'Disabled' if not (DiscImageEnabled and FakeCheckEnabled and PasswordCheckEnabled): nzb.log_info('No features enabled. Skipping script execution.') nzb.exit(nzb.PROCESS_SUCCESS) # Check version of NZBGet to make sure we can run. nzb.check_nzb_version(13.0) # Wire up your event handlers before the call. # Use the form nzb.set_handler(<event>, <function>) nzb.set_handler('FILE_DOWNLOADED', on_file_downloaded) nzb.set_handler('NZB_ADDED', on_nzb_added) nzb.set_handler('NZB_DOWNLOADED', on_nzb_downloaded) # Do not change this line, it checks the current event # and executes any event handlers. nzb.execute() except Exception as e: traceback.print_exc() nzb.exit(nzb.PROCESS_ERROR, e) clean_up()
def on_scheduled(): categories = get_categories() proxy = nzb.proxy() histories = proxy.history() nzb.log_info('Processing histories...') for history in histories: category = history['Category'] finaldir = history['FinalDir'] status = history['Status'] nzbid = int(history['NZBID']) if finaldir and category in categories and status == 'SUCCESS/ALL': if not proxy.editqueue('HistoryDelete', 0, '', [nzbid]): nzb.log_warning('Failed to mark %s as hidden.' % nzbid) nzb.log_info('Completed processing histories.')
def on_scheduled(): categories = get_categories() proxy = nzb.proxy() histories = proxy.history() nzb.log_info("Processing histories...") for history in histories: category = history["Category"] finaldir = history["FinalDir"] status = history["Status"] nzbid = int(history["NZBID"]) if finaldir and category in categories and status == "SUCCESS/ALL": if not proxy.editqueue("HistoryDelete", 0, "", [nzbid]): nzb.log_warning("Failed to mark %s as hidden." % nzbid) nzb.log_info("Completed processing histories.")
def main(): """ We need to check to make sure the script can run in the provided environment and that certain status checks have occurred. All of the calls here will exit with an exit code if the check fails. """ try: # If the script state was set to Disabled, we don't need to run. if SCRIPT_STATE == 'Disabled': nzb.exit(nzb.PROCESS_SUCCESS) # Check the status before we decide if we can continue. nzb.check_nzb_status() # Check if lock exists. if nzb.lock_exists('FileMover'): nzb.log_info('Lock exists, skipping execution.') nzb.exit(nzb.PROCESS_SUCCESS) else: nzb.lock_create('FileMover') # Check version of NZBGet to make sure we can run. nzb.check_nzb_version(13.0) # Wire up your event handlers before the call. # User the form nzb.set_handler(<event>, <function>) nzb.set_handler('POST_PROCESSING', on_post_processing) nzb.set_handler('SCHEDULED', on_scheduled) # Do not change this line, it checks the current event # and executes any event handlers. nzb.execute() except Exception as e: traceback.print_exc() nzb.exit(nzb.PROCESS_ERROR, e) finally: clean_up()
def main(): """ We need to check to make sure the script can run in the provided environment and that certain status checks have occurred. All of the calls here will exit with an exit code if the check fails. """ try: # If the script state was set to Disabled, we don't need to run. if SCRIPT_STATE == "Disabled": nzb.exit(nzb.PROCESS_SUCCESS) # Check the status before we decide if we can continue. nzb.check_nzb_status() # Check if lock exists. if nzb.lock_exists("FileMover"): nzb.log_info("Lock exists, skipping execution.") nzb.exit(nzb.PROCESS_SUCCESS) else: nzb.lock_create("FileMover") # Check version of NZBGet to make sure we can run. nzb.check_nzb_version(13.0) # Wire up your event handlers before the call. # User the form nzb.set_handler(<event>, <function>) nzb.set_handler("POST_PROCESSING", on_post_processing) nzb.set_handler("SCHEDULED", on_scheduled) # Do not change this line, it checks the current event # and executes any event handlers. nzb.execute() except Exception as e: traceback.print_exc() nzb.exit(nzb.PROCESS_ERROR, e) finally: clean_up()