postprocess - NotifyXBMC

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
johnsmith453
Posts: 4
Joined: 15 Jun 2014, 21:52

Re: postprocess - NotifyXBMC

Post by johnsmith453 » 21 Jun 2014, 17:19

Thank you very much pizzaking, that works perfectly.

danny_ice
Posts: 1
Joined: 19 Sep 2014, 06:35

Re: postprocess - NotifyXBMC

Post by danny_ice » 19 Sep 2014, 06:42

hi all, i'm having problems getting xbmc notify to work. Please see below log, i get the same errors with full scan and targeted scan. I am using xbmc14 Helix could this be the reason?
INFO Fri Sep 19 2014 07:32:26 Collection Bound_1996_English_XviD added to history
INFO Fri Sep 19 2014 07:32:26 Cleaning up download queue for Bound_1996_English_XviD
INFO Fri Sep 19 2014 07:32:26 Post-process-script NotifyXBMC.py for Bound_1996_English_XviD successful
INFO Fri Sep 19 2014 07:32:26 NotifyXBMC: Succeeded.
INFO Fri Sep 19 2014 07:32:26 NotifyXBMC: [b'{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}']
INFO Fri Sep 19 2014 07:32:26 NotifyXBMC: Sending update command: {"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":"F:\Videos\Movies\Bound_1996_English_XviD"},"id":1} to xbmc:xbmc@192.168.0.2:8080
INFO Fri Sep 19 2014 07:32:25 Executing post-process-script NotifyXBMC.py for Bound_1996_English_XviD
INFO Fri Sep 19 2014 07:32:25 Move for Bound_1996_English_XviD successful
Cheers
Dan

henrikhoe
Posts: 6
Joined: 26 Oct 2014, 21:00

Re: postprocess - NotifyXBMC

Post by henrikhoe » 26 Oct 2014, 21:25

i have this working but only with a full rescan of xbmc, really want targeted scan.

xbmc is on a mac mini connected to the TV
media is on a NAS

but i dont understand Local root path and remote path.

my media is in volume2/Movies 2, volume2/Shows and volume1/Movies, those are setup with smb in xbmc. but yes need those final settings to get targeted scan working

henrikhoe
Posts: 6
Joined: 26 Oct 2014, 21:00

Re: postprocess - NotifyXBMC

Post by henrikhoe » 26 Oct 2014, 23:17

im using NFS btw dont know if that ruins things

I noticed it worked now, but for some reason, recently added/new movies isn't picking up that a new movie was scanned

should i change to SMB?

war59312
Posts: 47
Joined: 12 Feb 2013, 04:52
Location: U.S.A
Contact:

Re: postprocess - NotifyXBMC

Post by war59312 » 22 Nov 2014, 16:54

Anyone know how to make the script not "PP-FAILURE" just because it cant connect to XBMC?

I'm only using this as a notification.

My modified version below:

Code: Select all

#!/usr/bin/env python

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

# Quick-update XBMC Frodo (12.x) library after a download completes successfully.
# Can optionally display an on-screen notification on XBMC as well.
#
# NOTE: This script requires Python to be installed on your system.

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

# Your XBMC host IP/hostname
#
# Use commas to separate multiple hosts. E.g.: 192.168.0.2,192.168.0.3
#Host=

# Username (if authorization is required)
#Username=

# Password (if authorization is required)
#Password=

# Display a notification on XBMC (yes, no).
#DisplayNotification=yes

# Notification title
#NotificationTitle=NZBGet download finished

# Notification message
#
# %nzbname% is the NZB name that was downloaded (without path or extension)
#NotificationMessage=%nzbname% successfully downloaded.

# Notification image
#
# Path to the image you want to send with the notification e.g. ${MainDir}/ppscripts/nzbget.png 
#NotificationImage=

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

import sys
try:
        import urllib.request as urllibRequest
        import urllib.parse as urllibParse
except:
        import urllib
        urllibRequest = urllib
        urllibParse = urllib
import os
import re

# 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 '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_HOST', 'NZBPO_USERNAME', 'NZBPO_PASSWORD', 'NZBPO_DISPLAYNOTIFICATION',
        'NZBPO_NOTIFICATIONTITLE', 'NZBPO_NOTIFICATIONMESSAGE')
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)

if os.path.exists(os.environ['NZBPP_FINALDIR']):
    print('[DETAIL] FINALDIR found. Using %s as updateDir' % os.environ['NZBPP_FINALDIR'])
    updateDir = os.environ['NZBPP_FINALDIR']
else:
    updateDir = os.environ['NZBPP_DIRECTORY']
host = os.environ['NZBPO_HOST']
username = os.environ['NZBPO_USERNAME']
password = os.environ['NZBPO_PASSWORD']
displayNotification = os.environ['NZBPO_DISPLAYNOTIFICATION']
title = os.environ['NZBPO_NOTIFICATIONTITLE']
imagepath = os.environ['NZBPO_NOTIFICATIONIMAGE']
body = os.environ['NZBPO_NOTIFICATIONMESSAGE'].replace('%nzbname%', os.environ['NZBPP_NZBNAME'])

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

class AuthURLOpener(urllibRequest.FancyURLopener):
        def __init__(self, user, pw):
                self.username = user
                self.password = pw
                self.numTries = 0
                urllibRequest.FancyURLopener.__init__(self)

        def prompt_user_passwd(self, host, realm):
                if self.numTries == 0:
                        self.numTries = 1
                        return (self.username, self.password)
                else:
                        return ('', '')

        def openit(self, url, params=None):
                self.numTries = 0
                return urllibRequest.FancyURLopener.open(self, url, params)

def sendToXbmc(inHost, inUsername, inPassword, inCommand):
        myOpener = AuthURLOpener(inUsername, inPassword)

        try:
                urlObj = myOpener.openit('http://%s/jsonrpc?request=%s' % (inHost, inCommand.encode('utf-8')))
        except IOError as e:
                print('[ERROR] Unable to open URL: ' + str(e))
                return False

        if urlObj.getcode() != 200:
                print('[ERROR] Unexpected error code returned: ' + str(urlObj.getcode()))
                print(urlObj.readlines())
                return False

        print(urlObj.readlines())
        return True

def lreplace(pattern, sub, string):
        return re.sub('^%s' % pattern, sub, string)

#  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.
parSuccess = os.environ['NZBPP_PARSTATUS'] == '0' or os.environ['NZBPP_PARSTATUS'] == '2'
unpackSuccess = os.environ['NZBPP_UNPACKSTATUS'] == '2'

if parSuccess and unpackSuccess:
        bSuccess = True
        for currhost in host.split(','):

                if displayNotification == 'yes':
                        print("Displaying notification...")
                        notifyCommand = '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"%s","image":"%s","message":"%s","displaytime":10000},"id":1}' % (title.encode("utf-8"), imagepath, body.encode("utf-8"))
                        if not sendToXbmc(currhost, username, password, notifyCommand):
                                bSuccess = False
#                               sys.exit(POSTPROCESS_ERROR)

                if bSuccess:
                        print("Succeeded.")
                else:
                        print("Failed.")

        if not bSuccess:
                sys.exit(POSTPROCESS_ERROR)
else:
        print("Not doing anything due to par or unpack failure.")

sys.exit(POSTPROCESS_SUCCESS)
If I comment out line 159 then no ""PP-FAILURE" just like I want, but then if there really is an error it does not error out either then.

binreader
Posts: 20
Joined: 07 Oct 2014, 03:00

Re: postprocess - NotifyXBMC

Post by binreader » 23 Nov 2014, 03:02

Hey theparnic, can you add a silentfailure option to your script. The notifyplex author added such feature to that script so you can compare to see what can be added. the feature suppresses PP Failure simply cuz xbmc is not available. since this script is not a core feature like unpack and par repair i think it making the failure status should be optional. cuz those of us that get notified on nzbget failures will get too many false positives with this script. also could you mod this to support the dnzb friendly name instead of the plain ole nzb name?

also on windows the image path generates an error i had to use double backslashes in the image path to get it to work so perhaps something is not being encoded

tested in a web browser until this worked

Code: Select all

http://user:pass@IP:PORTNUM/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"NZBGet download finished","image":"C:\\Apps\\nzbget\\scripts\\nzbget.png","message":"South Park successfully downloaded.","displaytime":10000},"id":1}
otherwise it generates
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

magiin83
Posts: 1
Joined: 30 Dec 2014, 17:12

Re: postprocess - NotifyXBMC

Post by magiin83 » 30 Dec 2014, 17:24

Bump.

Hi all, long time fan of nzbget, just new to the forums.

Recently added and started using the NotifyXBMC script, but it seems like I can't actually get a targeted scan to work.
It's definitely more of a preference over a full scan. Sonarr/NZBdrone is a program as an example that handles this perfectly.

Has anyone been able to get targeted specific folders to update with this script?
Any help would be greatly appreciated.

My current local path points to /mnt/user/Movies which is where all downloads go after being renamed by VIdeoSort script.
Remote Path - smb://serverip/Movies which is exactly how they're created on xbmc file list

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests