[Q] How to PP a script after all downloads are complete

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.
Post Reply
bb165
Posts: 2
Joined: 07 May 2018, 10:47

[Q] How to PP a script after all downloads are complete

Post by bb165 » 07 May 2018, 10:55

I am trying to execute a script when all downloads are complete i.e when the queue is empty. I did a search and found an old post but that didn't seem to work because of errors. I have got as far as:

Code: Select all

#!/usr/bin/env python
###########################################
### NZBGET POST-PROCESSING SCRIPT       ###

# Update media library if queue is empty.

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

import os
import sys
try:
	from xmlrpclib import ServerProxy # python 2
except ImportError:
	from xmlrpc.client import ServerProxy # python 3

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

# To get the item log we connect to NZBGet via XML-RPC and call
# method "loadlog", which returns the log for a given nzb item.
# For more info visit http://nzbget.net/RPC_API_reference

# First we need to know connection info: host, port and password of NZBGet server.
# NZBGet passes all configuration options to post-processing script as
# environment variables.
host = os.environ['NZBOP_CONTROLIP'];
port = os.environ['NZBOP_CONTROLPORT'];
username = os.environ['NZBOP_CONTROLUSERNAME'];
password = os.environ['NZBOP_CONTROLPASSWORD'];

if host == '0.0.0.0': host = '127.0.0.1'

# Build an URL for XML-RPC requests
rpcUrl = 'http://%s:%s@%s:%s/xmlrpc' % (username, password, host, port);

# Create remote server object
server = ServerProxy(rpcUrl)

# Call remote method 'listgroups'.
groups = server.listgroups()

# Check if queue is not empty
if len(groups) > 0:
    # Queue is not empty, exiting
    sys.exit(POSTPROCESS_NONE)

# Here insert your code to update library

#call a bat script
os.system('C:\\Users\\Software\\Scripts\\Delete.bat')

sys.exit(POSTPROCESS_SUCCESS)
however each time I get "Post-process-script UpdateLibrary.py for '...' skipped" even though it is that last item in the queue being downloaded.

I am not a coder and this is from trial and error.

Can somebody point me in the right direction? Thanks

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [Q] How to PP a script after all downloads are complete

Post by hugbug » 07 May 2018, 11:43

Try changing

Code: Select all

if len(groups) > 0:
to

Code: Select all

if len(groups) > 1:
because current processing item is still in queue and should not be counted.

bb165
Posts: 2
Joined: 07 May 2018, 10:47

Re: [Q] How to PP a script after all downloads are complete

Post by bb165 » 07 May 2018, 11:58

Hi,

I tried your suggestion but still experiencing the same problem. Any other suggestions?

Thanks

Edit: SOLVED - your suggestion worked, Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests