File: Sample-PostProc.py

package info (click to toggle)
sabnzbdplus 4.5.4%2Bdfsg-4
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,972 kB
  • sloc: javascript: 36,731; python: 33,071; xml: 536; sh: 249; makefile: 38
file content (43 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
# Example Post-Processing Script for SABnzbd (3.0.0 and higher), written in Python.
# For Linux, MacOS, Windows and any other platform with Python
# See https://sabnzbd.org/wiki/scripts/post-processing-scripts for details
#
# Example test run on Linux:
# env SAB_VERSION=X.Y SAB_AVG_BPS=666 python3 ./Sample-PostProc.py somedir222 nzbname CleanJobName123 Index12 Cat88 MyGroup PP0 https://example.com/

import sys, os

# Raw parsing of input parameters en SABnzbd environment variables
counter = 0
print("INPUT from argv:")
for item in sys.argv:
    print("Argument", counter, ":", item)
    counter += 1

print("INPUT from environment variables (only SAB specifics):")
for item in os.environ:
    if item.find("SAB_") == 0:
        print(item, os.environ[item])

# More intelligent parsing:
try:
    (scriptname, directory, orgnzbname, jobname, reportnumber, category, group, postprocstatus, url) = sys.argv
except Exception:
    print("No SAB compliant number of commandline parameters found (should be 8):", len(sys.argv) - 1)
    sys.exit(1)  # non-zero return code

# Some examples:
print("Examples of some specific values:")
print("jobname is:", jobname)
try:
    sabversion = os.environ["SAB_VERSION"]
    print("SAB_VERSION is:", sabversion)
except Exception:
    pass

""" your code here """

# We're done:
print("Script done. All OK.")  # the last line will appear in the SABnzb History GUI
sys.exit(0)  # The result code towards SABnzbd