def on_nzb_added():
    # Clean up any previous runs.
    clean_up()

    # Lock the script from running again.
    nzb.lock_create(SCRIPT_NAME)
    nzbid = nzb.get_nzb_id()

    # Move the last RAR file to the top.
    reorder_queued_items(nzbid)
def on_nzb_added():
    # Clean up any previous runs.
    clean_up()

    # Lock the script from running again.
    nzb.lock_create(SCRIPT_NAME)
    nzbid = nzb.get_nzb_id()

    # Move the last RAR file to the top.
    reorder_queued_items(nzbid)
def process_download(directory, filename):
    if not os.path.isdir(directory):
        nzb.log_warning('Directory %s does not appear valid.' % directory)

    filepath = os.path.join(directory, filename)
    cache_filepath = get_cache_filepath('%s-contents' % nzb.get_nzb_id())
    contentlist = nzb.get_rar_filelist(filepath)
    filelist = nzb.get_new_files(contentlist, cache_filepath)

    with open(cache_filepath, 'a') as cachefile:
        for file in filelist:
            inspect_rar_content(directory, file)
            cachefile.write(file + '\n')
        cachefile.close()
def process_download(directory, filename):
    if not os.path.isdir(directory):
        nzb.log_warning('Directory %s does not appear valid.' % directory)

    filepath = os.path.join(directory, filename)
    cache_filepath = get_cache_filepath('%s-contents' % nzb.get_nzb_id())
    contentlist = nzb.get_rar_filelist(filepath)
    filelist = nzb.get_new_files(contentlist, cache_filepath)

    with open(cache_filepath, 'a') as cachefile:
        for file in filelist:
            inspect_rar_content(directory, file)
            cachefile.write(file + '\n')
        cachefile.close()
def clean_up():
    """
    Perform any script cleanup that is required here.
    """
    nzbid = nzb.get_nzb_id()

    # Remove the state file.
    update_filepath = get_update_filepath(nzbid)
    if os.path.isfile(update_filepath):
        os.remove(update_filepath)

    if SCRIPT_STATE == "Debug":
        # Check if the script path has no other files and delete it.
        # NOTE: We can't blindly remove the directory because there might be
        #       other instances waiting for their retries and need the state.
        tempdir = nzb.get_script_tempfolder(SCRIPT_NAME)
        if len(os.path.listdir(tempdir)) == 0:
            os.rmdirs(tempdir)
Exemple #6
0
def clean_up():
    """
    Perform any script cleanup that is required here.
    """
    nzbid = nzb.get_nzb_id()

    # Remove the state file.
    update_filepath = get_update_filepath(nzbid)
    if os.path.isfile(update_filepath):
        os.remove(update_filepath)

    if SCRIPT_STATE == 'Debug':
        # Check if the script path has no other files and delete it.
        # NOTE: We can't blindly remove the directory because there might be
        #       other instances waiting for their retries and need the state.
        tempdir = nzb.get_script_tempfolder(SCRIPT_NAME)
        if len(os.path.listdir(tempdir)) == 0:
            os.rmdirs(tempdir)
Exemple #7
0
def on_post_processing():
    # Create a lock so that the scheduler also doesn't try to run.
    nzb.lock_reset(SCRIPT_NAME)

    status = nzb.get_nzb_status()

    if status != 'FAILURE/HEALTH':
        nzb.log_detail('Nothing to do, status was %s.' % status)
        nzb.exit(nzb.PROCESS_SUCCESS)

    try:
        nzbid = nzb.get_nzb_id()
        nzbname = nzb.get_nzb_name()

        nzb.log_detail('Performing health check on %s (%s).' %
                       (nzbname, status))

        check_limit_age(nzbid, nzbname)
        check_limit_retries(nzbid, nzbname)

        # Stop all other post-processing because we need to requeue the file.
        nzb.log_warning('Pausing %s due to status of %s.' % (nzbname, status))
        proxy = nzb.proxy()

        # Pause the file group.
        if not proxy.editqueue('GroupPause', 0, '', [nzbid]):
            reason = 'Failed to pause %s (%s).' % (nzbname, nzbid)
            nzb.exit(nzb.PROCESS_FAIL_PROXY, reason)

        # Send the file back to the queue.
        if not proxy.editqueue('HistoryReturn', 0, '', [nzbid]):
            reason = 'Failed to requeue %s (%s).' % (nzbname, nzbid)
            nzb.exit(nzb.PROCESS_FAIL_PROXY, reason)
    except Exception as e:
        traceback.print_exc()
        nzb.exit(nzb.PROCESS_ERROR, e)
    finally:
        nzb.lock_release(SCRIPT_NAME)
        clean_up()
def on_post_processing():
    # Create a lock so that the scheduler also doesn't try to run.
    nzb.lock_reset(SCRIPT_NAME)

    status = nzb.get_nzb_status()

    if status != "FAILURE/HEALTH":
        nzb.log_detail("Nothing to do, status was %s." % status)
        nzb.exit(nzb.PROCESS_SUCCESS)

    try:
        nzbid = nzb.get_nzb_id()
        nzbname = nzb.get_nzb_name()

        nzb.log_detail("Performing health check on %s (%s)." % (nzbname, status))

        check_limit_age(nzbid, nzbname)
        check_limit_retries(nzbid, nzbname)

        # Stop all other post-processing because we need to requeue the file.
        nzb.log_warning("Pausing %s due to status of %s." % (nzbname, status))
        proxy = nzb.proxy()

        # Pause the file group.
        if not proxy.editqueue("GroupPause", 0, "", [nzbid]):
            reason = "Failed to pause %s (%s)." % (nzbname, nzbid)
            nzb.exit(nzb.PROCESS_FAIL_PROXY, reason)

        # Send the file back to the queue.
        if not proxy.editqueue("HistoryReturn", 0, "", [nzbid]):
            reason = "Failed to requeue %s (%s)." % (nzbname, nzbid)
            nzb.exit(nzb.PROCESS_FAIL_PROXY, reason)
    except Exception as e:
        traceback.print_exc()
        nzb.exit(nzb.PROCESS_ERROR, e)
    finally:
        nzb.lock_release(SCRIPT_NAME)
        clean_up()
def reject(reason):
    nzbid = nzb.get_nzb_id()
    nzbname = nzb.get_nzb_name()
    nzb.log_error('Rejecting %s. %s.' % (nzbname, reason))

    response = None

    if REJECT_ACTION == 'Pause':
        nzb.log_error('File %s was rejected, pausing download.' % nzbname)
        response = nzb.proxy().editqueue('GroupPause', 0, '', [nzbid])
    elif REJECT_ACTION == 'Bad':
        nzb.log_error('File %s was rejected, marking as bad.' % nzbname)
        nzb.set_nzb_bad()
        response = True
    elif REJECT_ACTION == 'Fail':
        nzb.log_error('File %s was rejected, marking as failed.' % nzbname)
        response = nzb.set_nzb_fail(nzbid)

    if not response:
        nzb.log_error('Failed to apply the reject action.')
        nzb.exit(nzb.PROCESS_ERROR)

    nzb.exit(nzb.PROCESS_ERROR)
def reject(reason):
    nzbid = nzb.get_nzb_id()
    nzbname = nzb.get_nzb_name()
    nzb.log_error('Rejecting %s. %s.' % (nzbname, reason))

    response = None

    if REJECT_ACTION == 'Pause':
        nzb.log_error('File %s was rejected, pausing download.' % nzbname)
        response = nzb.proxy().editqueue('GroupPause', 0, '', [nzbid])
    elif REJECT_ACTION == 'Bad':
        nzb.log_error('File %s was rejected, marking as bad.' % nzbname)
        nzb.set_nzb_bad()
        response = True
    elif REJECT_ACTION == 'Fail':
        nzb.log_error('File %s was rejected, marking as failed.' % nzbname)
        response = nzb.set_nzb_fail(nzbid)

    if not response:
        nzb.log_error('Failed to apply the reject action.')
        nzb.exit(nzb.PROCESS_ERROR)

    nzb.exit(nzb.PROCESS_ERROR)
def on_file_downloaded():
    nzbid = nzb.get_nzb_id()

    # Update the file caches and run the inspection methods.
    update_filelist(nzbid)
def on_file_downloaded():
    nzbid = nzb.get_nzb_id()

    # Update the file caches and run the inspection methods.
    update_filelist(nzbid)