Page 1 of 3

History auto-purge

Posted: 07 Jan 2016, 21:11
by ubt
UPDATED

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)

Re: History auto-purge

Posted: 07 Jan 2016, 21:34
by hugbug
Very useful ;)

Make it to scheduler script:

Code: Select all

### NZBGET SCHEDULER SCRIPT
See https://github.com/nzbget/nzbget/wiki/Extension-scripts for details.

Then it can be managed from within NZBGet and you can add configurable options to define categories.
And you can read host, port username and password from passed configuration, see Logger.py as example.

Re: History auto-purge

Posted: 07 Jan 2016, 23:06
by ubt
That's a good idea, I'm looking at that now. Is there a way to tell NZBGet to run the scheduler script on demand to make testing easier?

Re: History auto-purge

Posted: 07 Jan 2016, 23:13
by hugbug
No, but you can test from terminal. Setup required environment variables, which nzbget usually do and which your script reads. Then you can start script from that terminal and the script will think it was started from nzbget.

Re: History auto-purge

Posted: 07 Jan 2016, 23:36
by ubt
<redundant>

[Scheduler-Script] CleanHistory - Remove downloads from hist

Posted: 08 Jan 2016, 17:52
by ubt
<redundant>

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Posted: 08 Jan 2016, 18:19
by hugbug
Should I merge the threads?

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Posted: 08 Jan 2016, 18:22
by ubt
Yes please, sorry for the dupe.

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Posted: 08 Jan 2016, 18:41
by hugbug
Merged.
The posts are displayed in timestamp order. Feel free to edit the first post as you like.
Thank you for the script, nice work.

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Posted: 08 Jan 2016, 23:58
by ubt
hugbug wrote:Merged.
The posts are displayed in timestamp order. Feel free to edit the first post as you like.
Thank you for the script, nice work.
Thanks, it was good to get my feet wet with Python a little bit.