Rename filter and Kodi notify

Come up with a useful post-processing script? Share it here!
Post Reply
Richard63
Newbie
Newbie
Posts: 17
Joined: January 18th, 2015, 3:58 pm

Rename filter and Kodi notify

Post by Richard63 »

Hello i made a pre-processing script witch clean up the file names parsed to sabnzbd

It fetches the job_name and searches for a 4 digit number (wich could be the year) and places it in Klammers like

"Star Trek 2009 x264 web-dl" becomes "Star Trek (2009")

most cleanup is done on the adult category files

TV category is left out because i let Sonarr do the naming.

let me know if you like this script please.

Code: Select all

#!/usr/bin/python
#
import sys
import os
import re
import urllib
import json
from urllib.request import urlopen
from urllib.request import Request
from urllib.parse import unquote
from urllib.parse import urlparse

try:
	(full_path, job_name, PP, category, script_name, prio, dl_size, group_list, show_name, season_name, episode_nr, episode_name) = sys.argv
	dl_size = int(dl_size)
except:
	print ("No commandline parameters found")
	sys.exit(1)                                                                                         # exit with 1 causes SabNzbd to ignore this script.	
   
#put some parameters here yourself if you need too.

if category == "adult":
	regex = re.compile(r'(?=(.))(?: \d\d \d\d \d\d|AP |xxx |1080.*|720.*|webrip |web-dl|dvdrip |part.*|rar.*|par.*|x264.*)', flags=re.IGNORECASE)
	new_nzb_name = regex.sub('', job_name)	
elif category == "tv":
	print("TV category need no renaming ")
	sys.exit(1)
else:
	find_year    	= re.search("\d\d\d\d", job_name).start()                  # position where year begins
	movie_name   	= job_name[0:find_year-1].replace("."," ")		      # replace "dots" in job_name with "spaces" 
	movie_year   	= job_name[find_year:find_year+4]			      # find year in job_name
	new_nzb_name    = movie_name + " (" + movie_year + ")"                  # put Year in "(" and put name of movie in front of the year

new_nzb_name = new_nzb_name.replace("."," ")	   			             # Delete dots in the name

# Don't Change Anything Under This Line!!!!!!!!
# send results to SabNZBD
print ("1")    # 0=Refuse, 1=Accept (correct me if i am wrong)
print (new_nzb_name)
print (PP)
print (category)
print (script_name)
print ("-100")
print (group_list)

#Notify Kodi

sentence = new_nzb_name

new = sentence.replace(" ", "%20")

#send notify to KODI  PUT IN YOUR OWN IP ADRESS FROM KODI
url = 'http://192.168.2.4/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22GUI.ShowNotification%22,%22params%22:{%22displaytime%22:10000,%22title%22:%22SABNzbd%22,%22message%22:%22Start%20Download%20'+new+'%22,%22image%22:%22http://sabnzbd.org/icon/sab2_512.png%22},%22id%22:1}'

response_stream = urlopen(url)

#print (url)

json_response = response_stream.read()

sys.exit(0)  # 0 means OK
Last edited by Richard63 on October 14th, 2016, 5:28 am, edited 1 time in total.
Richard63
Newbie
Newbie
Posts: 17
Joined: January 18th, 2015, 3:58 pm

Re: Rename filter and Kodi notify

Post by Richard63 »

i use the sabnzbd console to catch errors realtime
Last edited by Richard63 on October 14th, 2016, 5:31 am, edited 1 time in total.
.maxx
Release Testers
Release Testers
Posts: 70
Joined: April 10th, 2008, 6:32 am

Re: Rename filter and Kodi notify

Post by .maxx »

Hi Richard63,

can you please help me to get your pre-queue script running on OS X?
I'm only interested in the renaming part.

This is what I use from your script. Is this right?

Code: Select all

#!/usr/bin/python
#
import sys
import os
import re
import urllib
import json
from urllib.request import urlopen
from urllib.request import Request
from urllib.parse import unquote
from urllib.parse import urlparse
#

try:
   (full_path, job_name, PP, category, script_name, prio, dl_size, group_list, show_name, season_name, episode_nr, episode_name) = sys.argv
   dl_size = int(dl_size)
except:
   sys.exit(1) # exit with 1 causes SabNzbd to ignore this script.


# Determine new file name
#find_hd       = re.search("\d\d\d\d\a", job_name).start()           # doesnt work

find_year    = re.search("\d\d\d\d", job_name).start()                 # position where year begins

movie_name   = job_name[0:find_year-1].replace("."," ")               # replace "dots" in job_name with "spaces"

movie_year   = job_name[find_year:find_year+4]                     # find year in job_name

new_nzb_name    = movie_name + " (" + movie_year + ")"                 # put Year in "(" and put name of movie in front of the year

#demo = new_nzb_name.replace(" ", "%20")
#print (demo)

# send results to SabNZBD
print ("1")    # 0=Refuse, 1=Accept (correct me if i am wrong)
print (new_nzb_name)
print (PP)
print (category)
print (script_name)
print ("-100")
print (group_list)

sys.exit(0)
Then I created a executable "rename.py" file an set it in the sabnzbd preferences.
But when I upload a nzb nothing happens.
Any ideas?
Richard63
Newbie
Newbie
Posts: 17
Joined: January 18th, 2015, 3:58 pm

Re: Rename filter and Kodi notify

Post by Richard63 »

i just finished a new script:
hope you get it working too
otherwise use the console output to check what is happening in SAB.
for windows its like:
STOP Sabnzbd task first
open up a terminal (command window)
type:
"c:\program files (x86)\sabnzbdplus\sabnzbd-console.exe" -l2 (check your path)
sab is back on running and output is flowing on the console window.

Code: Select all

#!/usr/bin/python
#
import sys
import os
import re
import urllib
import json
from urllib.request import urlopen
from urllib.request import Request
from urllib.parse import unquote
from urllib.parse import urlparse

try:
	(full_path, job_name, PP, category, script_name, prio, dl_size, group_list, show_name, season_name, episode_nr, episode_name) = sys.argv
	dl_size = int(dl_size)
except:
	print ("No commandline parameters found")
	sys.exit(1)                                         # exit with 1 causes SabNzbd to ignore this script.	
   
if category == "adult":
	regex = re.compile(r'(?=(.))(?: \d\d \d\d \d\d|AP |xxx |1080.*|720.*|webrip |web-dl|dvdrip |part.*|rar.*|par.*|x264.*)', flags=re.IGNORECASE)
	new_nzb_name = regex.sub('', job_name)	
elif category == "tv":
	print("TV category need no renaming ")
	sys.exit(1)
else:
	find_year    	= re.search("\d\d\d\d", job_name).start()                  # position where year begins
	movie_name   	= job_name[0:find_year-1].replace("."," ")				   # replace "dots" in job_name with "spaces" 
	movie_year   	= job_name[find_year:find_year+4]						   # find year in job_name
	new_nzb_name    = movie_name + " (" + movie_year + ")"                     # put Year in "(" and put name of movie in front of the year

new_nzb_name = new_nzb_name.replace("."," ")	   							   # Delete dots in the name

# Don't Change Anything Under This Line!!!!!!!!
# send results to SabNZBD
print ("1")    # 0=Refuse, 1=Accept (correct me if i am wrong)
print (new_nzb_name)
print (PP)
print (category)
print (script_name)
print ("-100")
print (group_list)
sys.exit(0)  # 0 means OK
this code is working for me to clean up file names
TV category is untouched

and normal movies renamed (if possible) to IE: Star Trek (2009)
Post Reply