This is a Scheduler script that deletes history of items from specified categories. You must create a Scheduler task to use it. It is not a Post-Processing script.
CleanHistory.py
Code: Select all
#!/usr/bin/env python
#
####################################################################
### TASK TIME: *, *:00, *:15, *:30, *:45 ###
####################################################################
### NZBGET SCHEDULER SCRIPT ###
####################################################################
# Clean History
#
# A Scheduler script that removes items matching a Category list
# from history. You must create a Scheduler Task to run this script.
#
# Suggested TaskX.Time is "*, *:00, *:15, *:30, *:45".
#
# Why not a Post-Processing script you ask? Because a
# post-processing script cannot act upon the history of an item
# currently being processed in queue. In other words, it can't
# delete itself.
####################################################################
### OPTIONS ###
# Category List
#
# A comma-delimited list of Categories to match for history removal. Matches are case-sensitive.
#Categories=Adult, XXX
# Category History Delete Method (hide, delete).
#
# Select whether to permanently delete items from history, or
# just simply hide them.
#Method=hide
### NZBGET SCHEDULER SCRIPT ###
####################################################################
import os
import sys
from urllib2 import quote
from xmlrpclib import ServerProxy
host = os.environ['NZBOP_CONTROLIP']
port = os.environ['NZBOP_CONTROLPORT']
username = os.environ['NZBOP_CONTROLUSERNAME']
password = os.environ['NZBOP_CONTROLPASSWORD']
categories = [item.strip() for item in os.environ['NZBPO_CATEGORIES'].split(',')]
if os.environ['NZBPO_METHOD'] == 'delete':
delete_method = 'HistoryFinalDelete'
else:
delete_method = 'HistoryDelete'
if host == '0.0.0.0': host = '127.0.0.1'
rpcUrl = 'http://%s:%s@%s:%s/xmlrpc' % (quote(username), quote(password), host, port)
server = ServerProxy(rpcUrl)
for item in server.history():
for this_category in categories:
if item['Category'] == this_category:
result = server.editqueue(delete_method, '', item['ID'])
sys.exit(93)