C# for post-download scripts?

Get help with all aspects of SABnzbd
Forum rules
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.
Post Reply
dochoss
Newbie
Newbie
Posts: 2
Joined: October 11th, 2023, 12:26 pm

C# for post-download scripts?

Post by dochoss »

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

Re: C# for post-download scripts?

Post by safihre »

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.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
dochoss
Newbie
Newbie
Posts: 2
Joined: October 11th, 2023, 12:26 pm

Re: C# for post-download scripts?

Post by dochoss »

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

Re: C# for post-download scripts?

Post by safihre »

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.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: C# for post-download scripts?

Post by sander »

If you can write a C# program that works like this

Code: Select all

C:\ mycsharpprogram.exe This That
with output

Code: Select all

The first input is This
The second input is that
... then I'm quite sure you can write a post processing script in C#.
M77
Newbie
Newbie
Posts: 7
Joined: January 23rd, 2024, 12:17 am

Re: C# for post-download scripts?

Post by M77 »

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#.

Code: Select all

  Dim clArgs() As String
  clArgs = Environment.GetCommandLineArgs()
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:

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"))
And then I do some checking like:

Code: Select all

        If clArgs(7) <> 0 Then
            Console.WriteLine("Failed download - nothing to do here")
            Environment.ExitCode = 1
            End
        End If
And if everything works right, I set

Code: Select all

Environment.ExitCode = 0
Post Reply