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