Page 1 of 1

I don't understand how SABnzbd proccesses scripts

Posted: May 31st, 2020, 2:52 pm
by fabiorzfreitas
I'd like to learn how to write my own pre-queue and post-processing scripts in batch, but I found that the documentation wasn't really clear.

I understand perfectly how the parameters and variables can be used with batch syntax to conditionally generate output, but I don't get how input or return parameters are differentiated, what exactly is the 7 lines thing (if SABnzbd will only read echo from above, then why even use echo below it?) and the general syntax of it.

The available example, as well as a few other on the forum, gives me an idea of what's happening, but I can't quite grasp the concept.

Could someone do me the kindness of pointing me to some reading or perhaps explaining it to me?

Thank you!

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 1st, 2020, 4:16 am
by safihre
What kind of script are you trying to write? A pre-queue script or a post-processing script?
Pre-queue scripts indeed read the last 7 lines from your output and parse that.
Post-scripts only care about the exit() code.
Maybe if you share what you have so far, we can help out.

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 1st, 2020, 4:49 pm
by fabiorzfreitas
Well, right now, I intend to write a pre-queue script to auto pause NZBs containing a certain string, but what I'm really after is learning how this works, so I can easily write scripts as I have new needs.

e.g. I've been trying to comprehend this script from user newsleecher, which auto-pauses every new NZB:

Code: Select all

@echo off
echo 1
echo.
echo.
echo.
echo.

set nothing=""
set pauseit=false

IF %3==%nothing% set pauseit=true
IF %3==* set pauseit=true
IF /i %3==default set pauseit=true
IF /i %3==movie set pauseit=true
IF /i %3==tv set pauseit=true

IF %pauseit%==true (
  GOTO PAUSE_ITEM
) ELSE (
  GOTO LEAVE_IT_BE
)

:PAUSE_ITEM
echo -2

:LEAVE_IT
Here, I can see how the parameters and batch commands do the redirection, but I don't understand how the output is given. I know that -2 is pause, but I don't know how it's explicited that it refers to %5. Nor do I know how differentiate input and return parameters...

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 4th, 2020, 4:02 am
by safihre
SABnzbd uses 7 parameters, of which the 6th is the pause paramter
So first it prints the first 5 parameters to accept the job (that's the number 1)

Code: Select all

@echo off
echo 1
echo.
echo.
echo.
echo.
And then it does the logic, which only goes to this part if needed;

Code: Select all

:PAUSE_ITEM
echo -2

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 4th, 2020, 2:57 pm
by fabiorzfreitas
Ah, now I see it. I didn't get that the return parameters were called sequentially!

But I think that the naming scheme chosen for this is quite confusing. Shouldn't the input parameters be called input variables? I think they relate way more to the environment variables than to the return parameters...

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 7th, 2020, 3:46 am
by safihre
I think the naming got lost in translation, from Dutch-to-English :P

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 7th, 2020, 11:05 am
by fabiorzfreitas
That makes sense. Is there an issue tracker for the wiki/documentation? I'd like to open an issue. Otherwise, I guess since you're Administrator, the matter is already in good hands :)

Re: I don't understand how SABnzbd proccesses scripts

Posted: June 9th, 2020, 8:28 am
by safihre
https://github.com/sabnzbd/sabnzbd.github.io
You can even submit a pull-request to change the names if you want!