C# for post-download scripts?
Forum rules
Help us help you:
Help us help you:
- Are you using the latest stable version of SABnzbd? Downloads page.
- Tell us what system you run SABnzbd on.
- Adhere to the forum rules.
- Do you experience problems during downloading?
Check your connection in Status and Interface settings window.
Use Test Server in Config > Servers.
We will probably ask you to do a test using only basic settings. - Do you experience problems during repair or unpacking?
Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
C# for post-download scripts?
Hey all, I've been using Sabnzbd for a long time, but I've never taken a look at writing custom download scripts. The examples I can find are in Python but I'm a .Net/C# dev. Modern versions of .Net run fine in Linux (my server runs Ubuntu 22.04), so I'm wondering if I can get Sab to run a C# file for a post-download script. I've searched around but can't seem to find any examples. Anyone know if this is possible, and if so, where I might find some guidance or examples?
Re: C# for post-download scripts?
I don't think anyone has done it, especially since Python is such a simple language to learn for anyone, especially those with programming experience.
From the top of my head I would suggest to either write a wrapper shell file that calls your program or just call it directly. SABnzbd will call anything you want with the parameters as described, as long as it has the excutable bit set.
From the top of my head I would suggest to either write a wrapper shell file that calls your program or just call it directly. SABnzbd will call anything you want with the parameters as described, as long as it has the excutable bit set.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
Re: C# for post-download scripts?
Yeah, certainly not complaining about Python, it's definitely uncomplicated. But if I already have the skills in C#, might as well try to use that if I can Did I miss documentation for how scripts are executed? I saw the wiki page about post-processing scripts but I don't see it saying anything about how to choose between bash scripts, python, etc. Writing a bash script to call a dotnet console app is pretty straightforward, so I might do that. But if I can get Sab to execute it directly, that would be the optimal approach.
Appreciate the reply!
Appreciate the reply!
Re: C# for post-download scripts?
We just call them (on Linux), just as you would through the command line.
With the parameters as described in the wiki.
Just set the Scripts Directory to the folder that holds your application and select it in the Queue or for your category in the config.
With the parameters as described in the wiki.
Just set the Scripts Directory to the folder that holds your application and select it in the Queue or for your category in the config.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
Re: C# for post-download scripts?
If you can write a C# program that works like this
with output
... then I'm quite sure you can write a post processing script in C#.
Code: Select all
C:\ mycsharpprogram.exe This That
Code: Select all
The first input is This
The second input is that
Re: C# for post-download scripts?
I have written one in VB NET, so it should be possible in C#.
The basic info you need is at - I can't post the link as new user, so you'll have to search the wiki for "Post-processing scripts"
You have to make it in C#, but in VB NET I started with a command-line template.
Here's some VB NET code. If you can't translate it yourself, just use a VB NET to C# converter and that should get you far enough to start converting it to proper C#.
It'll get those as per above URL:
Position Description
1 The final directory of the job (full path)
2 The original name of the NZB file
3 Clean version of the job name (no path info and ".nzb" removed)
4 Indexer's report number (if supported)
5 User-defined category
6 Group that the NZB was posted
7 Status of post processing.
0 = OK
1 = Failed verification
2 = Failed unpack
3 = 1+2
-1 = Failed post processing
...
Writing to the command-line will be captured by sab and logged/emailed:
And then I do some checking like:
And if everything works right, I set
The basic info you need is at - I can't post the link as new user, so you'll have to search the wiki for "Post-processing scripts"
You have to make it in C#, but in VB NET I started with a command-line template.
Here's some VB NET code. If you can't translate it yourself, just use a VB NET to C# converter and that should get you far enough to start converting it to proper C#.
Code: Select all
Dim clArgs() As String
clArgs = Environment.GetCommandLineArgs()
Position Description
1 The final directory of the job (full path)
2 The original name of the NZB file
3 Clean version of the job name (no path info and ".nzb" removed)
4 Indexer's report number (if supported)
5 User-defined category
6 Group that the NZB was posted
7 Status of post processing.
0 = OK
1 = Failed verification
2 = Failed unpack
3 = 1+2
-1 = Failed post processing
...
Writing to the command-line will be captured by sab and logged/emailed:
Code: Select all
Console.WriteLine("The final directory of the job (full path) " + clArgs(1))
Console.WriteLine("The original name of the NZB file " + clArgs(2))
Console.WriteLine("User-defined category " + clArgs(5))
Console.WriteLine("Status of post processing " + clArgs(7))
Console.WriteLine("SAB_COMPLETE_DIR: " + Environment.GetEnvironmentVariable("SAB_COMPLETE_DIR"))
Console.WriteLine("SAB_FINAL_NAME: " + Environment.GetEnvironmentVariable("SAB_FINAL_NAME"))
Console.WriteLine("SAB_FAIL_MSG: " + Environment.GetEnvironmentVariable("SAB_FAIL_MSG"))
Console.WriteLine("SAB_CAT: " + Environment.GetEnvironmentVariable("SAB_CAT"))
Code: Select all
If clArgs(7) <> 0 Then
Console.WriteLine("Failed download - nothing to do here")
Environment.ExitCode = 1
End
End If
Code: Select all
Environment.ExitCode = 0