Page 1 of 1

[PP-Script] Pushover notifications

Posted: 08 May 2013, 22:08
by bgoldie
This script sends a Pushover (http://pushover.net) notification when a job is finished.

To get an application token/key you have to log into your account, go to "Apps & Plugins", select "Create a new application" and enter a name e.g. NZBGet and select an icon (or it will use the default Pushover icon). I use the icon from here: http://www.qnap.com/images/products/App ... et_100.gif

In the script options, you can leave 'Device' blank to send to all your registered devices, or enter a particular device you want to send to.

URL is optional but if you enter the NZBGet URL you can easily open the webpage if a download fails.

You can choose different sounds to play on success or failure or leave blank for the default sound (list of sounds here: https://pushover.net/api#sounds)

Success and failure Priority can be low (silent), normal, or high (this will bypass your set quiet times).

I've borrowed heavily from hugbug's email script so credit to him.

Code: Select all

#!/usr/bin/env python

##############################################################################
### NZBGET POST-PROCESSING SCRIPT                                          ###

# Send Pushover notification.
#
# This script sends a Pushover notification when the job is finished.
#
# NOTE: This script requires Python to be installed on your system.

##############################################################################
### OPTIONS                                                                ###

# Pushover user key 
#UserKey=

# Application token/key (register application here: http://pushover.net/apps)
#AppToken=

# Device to send notification to (optional)
#Device=

# Supplementary URL to show with your message (optional)
#Url=

# Success Sound (optional)
#
# Sound to play on success. Lists of sounds here: http://pushover.net/api#sounds.
#SuccessSound=

# Failure Sound (optional)
#
# Sound to play on failure. Lists of sounds here: http://pushover.net/api#sounds.
#FailureSound=

# Priority of success notification (low, normal, high).
#
# Low priority (quiet notification)
#
# Normal priority
#
# High priority (bypasses users quiet times)
#SuccessPriority=normal

# Priority of failure notification (low, normal, high).
#
# Low priority (quiet notification)
#
# Normal priority
#
# High priority (bypasses users quiet times)
#FailurePriority=normal

# Append Par-Status and Unpack-Status to the message (yes, no).
#
# Add the Par and Unpack status.
#AppendParUnpack=no

# Append list of files to the message (yes, no).
#
# Add the list of downloaded files (the content of destination directory).
#FileList=no

### NZBGET POST-PROCESSING SCRIPT                                          ###
##############################################################################


import os
import sys
import httplib
import urllib

# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94

# Check if the script is called from nzbget 11.0 or later
if not os.environ.has_key('NZBOP_SCRIPTDIR'):
	print('*** NZBGet post-processing script ***')
	print('This script is supposed to be called from nzbget (11.0 or later).')
	sys.exit(POSTPROCESS_ERROR)

required_options = ('NZBPO_USERKEY', 'NZBPO_APPTOKEN')
for	optname in required_options:
	if (not os.environ.has_key(optname)):
		print('[ERROR] Option %s is missing in configuration file. Please check script settings' % optname[6:])
		sys.exit(POSTPROCESS_ERROR)

print('[DETAIL] Script successfully started')
sys.stdout.flush()

userkey = os.environ['NZBPO_USERKEY']
apptoken = os.environ['NZBPO_APPTOKEN']
device = os.environ['NZBPO_DEVICE']
url = os.environ['NZBPO_URL']

# Check par and unpack status for errors and set message

#  NZBPP_PARSTATUS    - result of par-check:
#                       0 = not checked: par-check is disabled or nzb-file does
#                           not contain any par-files;
#                       1 = checked and failed to repair;
#                       2 = checked and successfully repaired;
#                       3 = checked and can be repaired but repair is disabled.
#                       4 = par-check needed but skipped (option ParCheck=manual);

#  NZBPP_UNPACKSTATUS - result of unpack:
#                       0 = unpack is disabled or was skipped due to nzb-file
#                           properties or due to errors during par-check;
#                       1 = unpack failed;
#                       2 = unpack successful.

success=False
if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_UNPACKSTATUS'] == '1':
	message = 'Download of "%s" has failed.' % (os.environ['NZBPP_NZBNAME'])
elif os.environ['NZBPP_PARSTATUS'] == '4':
	message = 'Download of "%s" requires par-repair.' % (os.environ['NZBPP_NZBNAME'])
else:
	message = 'Download of "%s" has successfully completed.' % (os.environ['NZBPP_NZBNAME'])
	success=True

#Set requested success or failure sound 	
if not success and 'NZBPO_FAILURESOUND' in os.environ:
	sound = os.environ['NZBPO_FAILURESOUND']	
elif success and 'NZBPO_SUCCESSSOUND' in os.environ:
	sound = os.environ['NZBPO_SUCCESSSOUND']
else:
	sound=""

#Set success priority	
if os.environ['NZBPO_SUCCESSPRIORITY'] == 'low':
	successpriority = "-1"
elif os.environ['NZBPO_SUCCESSPRIORITY'] == 'normal':
	successpriority = "0"
elif os.environ['NZBPO_SUCCESSPRIORITY'] == 'high':	
	successpriority = "1"

#set failure priority	
if os.environ['NZBPO_FAILUREPRIORITY'] == 'low':
	failurepriority = "-1"
elif os.environ['NZBPO_FAILUREPRIORITY'] == 'normal':
	failurepriority = "0"
elif os.environ['NZBPO_FAILUREPRIORITY'] == 'high':	
	failurepriority = "1"	

#set priority to success or failure priority	
if success:	
	priority = successpriority
else:
	priority = failurepriority

# add par and unpack status to the message
if os.environ['NZBPO_APPENDPARUNPACK'] == 'yes':		
	parStatus = { '0': 'skipped', '1': 'failed', '2': 'repaired', '3': 'repairable', '4': 'manual' }
	message += '\nPar-Status: %s' % parStatus[os.environ['NZBPP_PARSTATUS']]

	unpackStatus = { '0': 'skipped', '1': 'failed', '2': 'success' }
	message += '\nUnpack-Status: %s' % unpackStatus[os.environ['NZBPP_UNPACKSTATUS']]

# add list of downloaded files to the message
if os.environ['NZBPO_FILELIST'] == 'yes':
	message += '\n\nFiles:'
	for dirname, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']):
		for filename in filenames:
			message += '\n' + os.path.join(dirname, filename)[len(os.environ['NZBPP_DIRECTORY']) + 1:]

# Send message
print('[DETAIL] Sending Pushover notification')
sys.stdout.flush()
try:
	conn = httplib.HTTPSConnection("api.pushover.net:443")
	conn.request("POST", "/1/messages.json",
	  urllib.urlencode({
		"token": apptoken,
		"user": userkey,
		"device": device,
		"url": url,
		"sound": sound,
		"priority": priority,
		"message": message,
	  }), { "Content-type": "application/x-www-form-urlencoded" })
	conn.getresponse()
except Exception, err:
	print('[ERROR] %s' % err)
	sys.exit(POSTPROCESS_ERROR)

# All OK, returning exit status 'POSTPROCESS_SUCCESS' (int <93>) to let NZBGet know
# that our script has successfully completed.
sys.exit(POSTPROCESS_SUCCESS)

Re: [PP-Script] Pushover notifications

Posted: 09 May 2013, 06:44
by picardtux
No Monthly Fees
Pushover has no monthly subscription fees and users will always be able to receive unlimited messages for free.
in contrast to postprocess - NotifyMyAndroid
this costs nothing appears here, great!

edit: but the app costs for ios ~4,49 € and android ~3,82€ :roll:

Re: [PP-Script] Pushover notifications

Posted: 16 May 2013, 18:46
by bgoldie
Modified code in first post (and attached script) to allow the choice of different success and failure sounds and priorities.

Re: [PP-Script] Pushover notifications

Posted: 09 Feb 2015, 04:07
by danofun
Great addon!!!

Request:
To allow multiple, not just all or a singe, devices to receive push notifications.

Re: [PP-Script] Pushover notifications

Posted: 04 Nov 2015, 20:55
by cmdrmdc
I've updated the script to give the option to send a success and/or failure message instead of always sending a message. I also updated it to use the newer "NZBPP_TOTALSTATUS" and NZBPP_STATUS" output as it seemed to be more reliable in my testing (on version 16.3).

Cheers!

Re: [PP-Script] Pushover notifications

Posted: 05 Nov 2015, 23:37
by schumi2004
Great.

Just a idea. Would it be possible to have custom messages or links in the push itself?
For example imdb links for movies and tvdb for series?
Custom layout?

Re: [PP-Script] Pushover notifications

Posted: 11 Sep 2016, 13:53
by thatoneguy99
I know this post is a little older but it is the only one that I can find. My question is if there is a way to turn off the "Success" notification. I only want to be notified upon a failure, but I don't know how to only get that notification. Any help is appreciated.

EDIT: I did not read the post two above that closely and it looks like that functionality is in there. I am trying it now.

Re: [PP-Script] Pushover notifications

Posted: 26 Sep 2016, 06:22
by phairplay
Hi,
Is it possible to have the failures to be sent to a different token
a successfull download sends a green nzbget icon message
A failure download sends a red nzbget icon message

Re: [PP-Script] Pushover notifications

Posted: 22 Oct 2016, 22:09
by sleepy
Just getting setup with NZBGet and I'm having issues getting this script to work.

Keep getting the following error:

Code: Select all

ERROR	Sat Oct 22 2016 14:55:27	Post-process-script Pushover.py for xxxxxxxxx failed (terminated with unknown status)
INFO	Sat Oct 22 2016 14:55:27	Pushover: NameError: name 'xxxxxxxxxxxxx' is not defined
INFO	Sat Oct 22 2016 14:55:27	Pushover: UserKey=xxxxxxxxxxxxxx
INFO	Sat Oct 22 2016 14:55:27	Pushover: File "/usr/local/nzbget/share/nzbget/scripts/Pushover.py", line 16, in <module>
INFO	Sat Oct 22 2016 14:55:27	Pushover: Traceback (most recent call last):
INFO	Sat Oct 22 2016 14:55:25	Executing post-process-script Pushover.py for xxxxxxxxxxxx
Im running NZBGet 16.4 on Synology DS1812+ with DSM 5.2-5644 Update 5

I've triple checked the UserKey and created a new Appwith AppToken. Any help would be greatly appreciated.

Re: [PP-Script] Pushover notifications

Posted: 02 Jun 2020, 14:25
by Martidjen
Hi,
I also updated the code to get it up to date, the script is now working on my system running Ubuntu 20.04 LTS with Python 3.8, NZBGet version 21.0.

Also added message titles, I think this makes the different kind of notifcations easier to distinguish.

Code: Select all

#!/usr/bin/python3

##############################################################################
### NZBGET POST-PROCESSING SCRIPT                                          ###

# Send Pushover notification.
#
# This script sends a Pushover notification when the job is finished.
#
# NOTE: This script requires Python to be installed on your system.

##############################################################################
### OPTIONS                                                                ###

# Pushover user key
#UserKey=

# Application token/key (register application here: http://pushover.net/apps)
#AppToken=

# Device to send notification to (optional)
#Device=

# Supplementary URL to show with your message (optional)
#Url=

# Success Sound (optional)
#
# Sound to play on success. Lists of sounds here: http://pushover.net/api#sounds.
#SuccessSound=

# Failure Sound (optional)
#
# Sound to play on failure. Lists of sounds here: http://pushover.net/api#sounds.
#FailureSound=

# Send success notification (yes, no).
#
# Send the success notification
#NotifySuccess=yes

# Send failure notification (yes, no).
#
# Send the failure notification
#NotifyFailure=yes

# Priority of success notification (low, normal, high).
#
# Low priority (quiet notification)
#
# Normal priority
#
# High priority (bypasses users quiet times)
#SuccessPriority=normal

# Priority of failure notification (low, normal, high).
#
# Low priority (quiet notification)
#
# Normal priority
#
# High priority (bypasses users quiet times)
#FailurePriority=normal

# Append Par-Status and Unpack-Status to the message (yes, no).
#
# Add the Par and Unpack status.
#AppendParUnpack=no

# Append list of files to the message (yes, no).
#
# Add the list of downloaded files (the content of destination directory).
#FileList=no

### NZBGET POST-PROCESSING SCRIPT                                          ###
##############################################################################


import os
import sys
import http.client
import urllib

# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95

# Check if the script is called from nzbget 11.0 or later
if not 'NZBOP_SCRIPTDIR' in os.environ:
    print('*** NZBGet post-processing script ***')
    print('This script is supposed to be called from nzbget (11.0 or later).')
    sys.exit(POSTPROCESS_ERROR)

required_options = ('NZBPO_USERKEY', 'NZBPO_APPTOKEN')
for optname in required_options:
    if (not optname in os.environ):
        print('[ERROR] Option %s is missing in configuration file. Please check script settings' % optname[6:])
        sys.exit(POSTPROCESS_ERROR)

print('[DETAIL] Script successfully started')
sys.stdout.flush()

userkey = os.environ['NZBPO_USERKEY']
apptoken = os.environ['NZBPO_APPTOKEN']
device = os.environ['NZBPO_DEVICE']
url = os.environ['NZBPO_URL']

# Check par and unpack status for errors and set message

#  NZBPP_PARSTATUS    - result of par-check:
#                       0 = not checked: par-check is disabled or nzb-file does
#                           not contain any par-files;
#                       1 = checked and failed to repair;
#                       2 = checked and successfully repaired;
#                       3 = checked and can be repaired but repair is disabled.
#                       4 = par-check needed but skipped (option ParCheck=manual);

#  NZBPP_UNPACKSTATUS - result of unpack:
#                       0 = unpack is disabled or was skipped due to nzb-file
#                           properties or due to errors during par-check;
#                       1 = unpack failed;
#                       2 = unpack successful.

success=False
if os.environ['NZBPP_TOTALSTATUS'] == 'FAILURE':
    title = 'Download failed'
    message = 'Download of "%s" has failed: %s' % (os.environ['NZBPP_NZBNAME'], os.environ['NZBPP_STATUS'])
elif os.environ['NZBPP_TOTALSTATUS'] == 'WARNING':
    title = 'Action needed'
    message = 'User intervention required for download of "%s": %s' % (os.environ['NZBPP_NZBNAME'], os.environ['NZBPP_STATUS'])
else:
    title = 'Download succesful'
    message = 'Download of "%s" has successfully completed: %s' % (os.environ['NZBPP_NZBNAME'], os.environ['NZBPP_STATUS'])
    success=True

#Set requested success or failure sound
if not success and 'NZBPO_FAILURESOUND' in os.environ:
    sound = os.environ['NZBPO_FAILURESOUND']
elif success and 'NZBPO_SUCCESSSOUND' in os.environ:
    sound = os.environ['NZBPO_SUCCESSSOUND']
else:
    sound=""

#Set success priority
if os.environ['NZBPO_SUCCESSPRIORITY'] == 'low':
    successpriority = "-1"
elif os.environ['NZBPO_SUCCESSPRIORITY'] == 'normal':
    successpriority = "0"
elif os.environ['NZBPO_SUCCESSPRIORITY'] == 'high':
    successpriority = "1"

#set failure priority
if os.environ['NZBPO_FAILUREPRIORITY'] == 'low':
    failurepriority = "-1"
elif os.environ['NZBPO_FAILUREPRIORITY'] == 'normal':
    failurepriority = "0"
elif os.environ['NZBPO_FAILUREPRIORITY'] == 'high':
    failurepriority = "1"

#set priority to success or failure priority
if success:
    priority = successpriority
else:
    priority = failurepriority

# add par and unpack status to the message
if os.environ['NZBPO_APPENDPARUNPACK'] == 'yes':
    parStatus = { '0': 'skipped', '1': 'failed', '2': 'repaired', '3': 'repairable', '4': 'manual' }
    message += '\nPar-Status: %s' % parStatus[os.environ['NZBPP_PARSTATUS']]

    unpackStatus = { '0': 'skipped', '1': 'failed', '2': 'success' }
    message += '\nUnpack-Status: %s' % unpackStatus[os.environ['NZBPP_UNPACKSTATUS']]

# add list of downloaded files to the message
if os.environ['NZBPO_FILELIST'] == 'yes':
    message += '\n\nFiles:'
    for dirname, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']):
        for filename in filenames:
            message += '\n' + os.path.join(dirname, filename)[len(os.environ['NZBPP_DIRECTORY']) + 1:]

sendMessage = False
if os.environ['NZBPO_NOTIFYSUCCESS'] == 'yes' and success:
    sendMessage = True
elif os.environ['NZBPO_NOTIFYFAILURE'] == 'yes' and not success:
    sendMessage = True

if sendMessage:
    # Send message
    print('[DETAIL] Sending Pushover notification')
    sys.stdout.flush()
    try:
        conn = http.client.HTTPSConnection("api.pushover.net:443")
        conn.request("POST", "/1/messages.json",
          urllib.parse.urlencode({
            "token": apptoken,
            "user": userkey,
            "device": device,
            "url": url,
            "sound": sound,
            "priority": priority,
            "title": title,
            "message": message,
          }), { "Content-type": "application/x-www-form-urlencoded" })
        conn.getresponse()
        sys.exit(POSTPROCESS_SUCCESS)
    except Exception as err:
        print('[ERROR] %s' % err)
        sys.exit(POSTPROCESS_ERROR)
else:
    # Send message
    print('[DETAIL] Skipping Pushover notification')
    sys.stdout.flush()

    # All OK, returning exit status 'POSTPROCESS_NONE' (int <95>) to let NZBGet know
    # that our script has successfully completed without action.
    sys.exit(POSTPROCESS_NONE)