[Python] Pre-queue movie rename - need help

Come up with a useful post-processing script? Share it here!
Post Reply
.maxx
Release Testers
Release Testers
Posts: 70
Joined: April 10th, 2008, 6:32 am

[Python] Pre-queue movie rename - need help

Post by .maxx »

Hi guys,

can you please help me to get a pre-queue script running on OS X?
I took the renaming script from Richard63 but it doesn't work and I can't reach him through pm.
https://forums.sabnzbd.org/viewtopic.php?f=9&t=21184

This is what I use from from Richards 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? How can I test the script?

thanks
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: [Python] Pre-queue movie rename - need help

Post by safihre »

There was a mistake at the top, some of the modules that were imported don't exist.
The output is written to the log when you have +Info set in the Status window.

I would suggest you try CouchPotato, it handles all this for you (automatic downloading and renaming), without extra scripts :)

This worked for me:

Code: Select all

#!/usr/bin/python
#
import sys
import os
import re
#

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)
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
.maxx
Release Testers
Release Testers
Posts: 70
Joined: April 10th, 2008, 6:32 am

Re: [Python] Pre-queue movie rename - need help

Post by .maxx »

Thanks safihre,

but it doesn't work for me, no renaming after uploading a nzb, nothing happens.
Is this procedure right:
Then I created a executable "rename.py" file an set it in the sabnzbd preferences.
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: [Python] Pre-queue movie rename - need help

Post by safihre »

This is correct, if you have set it in Config>Switches and then User pre-queue script it should work.
In my case it renamed
Bridge.of.Spies.2015.1080p.BluRay.x264.DTS.DD5.1-NL.SUBS.T.U-Obfuscated.cp(tt3682448).nzb
to:
Bridge of Spies (2015)

I could see that in my log:

Code: Select all

2016-08-10 17:04:32,242::INFO::[newsunpack:1859] Running pre-queue script D:\SABnzbd\test.py Bridge.of.Spies.2015.1080p.BluRay.x264.DTS.DD5.1-NL.SUBS.T.U-Obfuscated.cp(tt3682448) "" * "" -100 13874361343 alt.binaries.cores "" "" "" ""
2016-08-10 17:04:32,404::INFO::[newsunpack:1871] Pre-queue script returns 0 and output=
1
Bridge of Spies (2015)

*

-100
alt.binaries.cores

2016-08-10 17:04:32,421::INFO::[newsunpack:1885] Pre-Q accepts Bridge.of.Spies.2015.1080p.BluRay.x264.DTS.DD5.1-NL.SUBS.T.U-Obfuscated.cp(tt3682448)
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
.maxx
Release Testers
Release Testers
Posts: 70
Joined: April 10th, 2008, 6:32 am

Re: [Python] Pre-queue movie rename - need help

Post by .maxx »

Yeah now it works.
I'm stupid. I've set the script in the categories not in the Switches.

Thank you!
Post Reply