Skip to content

Commit e44ec66

Browse files
authored
Merge pull request #96 from Safihre/env
Allow SABnzbd to pass URLs as environment variable
2 parents c4b3027 + e9c672b commit e44ec66

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

sabnzbd-notify.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def syntax():
143143
"description of the <Type> is used instead." + os.linesep +\
144144
"* All remaining arguments are treated as URLs. You can also " +\
145145
"delimit multiple" + os.linesep + "\tURLs in a single " +\
146-
"string/argument with the use of a comma (,)."
146+
"string/argument with the use of a comma (,)." + os.linesep +\
147+
"\tURLs can also be provided as the SAB_NOTIFICATION_PARAMETERS " +\
148+
"environment variable."
147149

148150

149151
def notify(ntype, title, body, urls, debug=None):
@@ -154,7 +156,7 @@ def notify(ntype, title, body, urls, debug=None):
154156
if debug is None:
155157
debug = DEBUG_MODE
156158

157-
# We use the Python interpreter that was also used by
159+
# We use the Python interpreter that was also used by
158160
# SABnzbd when it executed this script
159161
cmd = [
160162
sys.executable if sys.executable else "python",
@@ -206,8 +208,9 @@ def notify(ntype, title, body, urls, debug=None):
206208
return True
207209

208210
if __name__ == "__main__":
209-
# Simple parsing of the command line
210-
if len(sys.argv) <= 4:
211+
# Simple parsing of the command line and env variable
212+
notify_urls_string = os.environ.get("SAB_NOTIFICATION_PARAMETERS", None)
213+
if len(sys.argv) <= 3 and not notify_urls_string:
211214
logger.error('Not enough arguments specified.')
212215
print(syntax())
213216
exit(1)
@@ -233,9 +236,14 @@ def notify(ntype, title, body, urls, debug=None):
233236
# Store body (empty or not)
234237
notify_body = sys.argv[3].strip()
235238

239+
# Environment variable takes precedence over the command line parameter
236240
# The URLs are complex and very depending on what we're notifying
237241
# so we'll let Notify.py take care of them at this point.
238-
notify_urls = ','.join([ v.strip() for v in sys.argv[4:]])
242+
if notify_urls_string:
243+
notify_urls = notify_urls_string.split()
244+
else:
245+
notify_urls = sys.argv[4:]
246+
notify_urls = ','.join([v.strip() for v in notify_urls])
239247

240248
# Perform Notification
241249
exit(int(not notify(

0 commit comments

Comments
 (0)