I don't understand how SABnzbd proccesses scripts

Come up with a useful post-processing script? Share it here!
Post Reply
fabiorzfreitas
Newbie
Newbie
Posts: 4
Joined: May 31st, 2020, 2:39 pm

I don't understand how SABnzbd proccesses scripts

Post 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!
User avatar
safihre
Administrator
Administrator
Posts: 5523
Joined: April 30th, 2015, 7:35 am
Contact:

Re: I don't understand how SABnzbd proccesses scripts

Post 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.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
fabiorzfreitas
Newbie
Newbie
Posts: 4
Joined: May 31st, 2020, 2:39 pm

Re: I don't understand how SABnzbd proccesses scripts

Post 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...
User avatar
safihre
Administrator
Administrator
Posts: 5523
Joined: April 30th, 2015, 7:35 am
Contact:

Re: I don't understand how SABnzbd proccesses scripts

Post 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
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
fabiorzfreitas
Newbie
Newbie
Posts: 4
Joined: May 31st, 2020, 2:39 pm

Re: I don't understand how SABnzbd proccesses scripts

Post 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...
User avatar
safihre
Administrator
Administrator
Posts: 5523
Joined: April 30th, 2015, 7:35 am
Contact:

Re: I don't understand how SABnzbd proccesses scripts

Post by safihre »

I think the naming got lost in translation, from Dutch-to-English :P
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
fabiorzfreitas
Newbie
Newbie
Posts: 4
Joined: May 31st, 2020, 2:39 pm

Re: I don't understand how SABnzbd proccesses scripts

Post 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 :)
User avatar
safihre
Administrator
Administrator
Posts: 5523
Joined: April 30th, 2015, 7:35 am
Contact:

Re: I don't understand how SABnzbd proccesses scripts

Post by safihre »

https://github.com/sabnzbd/sabnzbd.github.io
You can even submit a pull-request to change the names if you want!
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
Post Reply