[Python] Corrie TV (Coronation Street)/Enders renamer script

Come up with a useful post-processing script? Share it here!
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

[Python] Corrie TV (Coronation Street)/Enders renamer script

Post by J03 8LACK »

Corrie Fans Python script with Sabnzbd RSS setup

To all those Corrie fans (Coronation Street Fans)
I have found it very hard to use Sickbeard to gather Coronation Street episodes as they are release by date and not episodes. Even if you turn on air by date and setup Coronation Street it will not find anything. As it will not match with the way TVdb.org is labeling the Episodes. So of course the only way around this is to have Sabnzbd do the work for you. With the setup below I will show you how to setup the RSS feed and with the Python Script take the file downloaded and rename it and move it to a new folder named something Sickbeard will recognize and update the Show list.

Things you will need:
Sabnzbd – installed, Python 2.7- installed, Sickbeard – installed with sabtosickbeard setup, Binsearch
And a text editor – notepad or my Favorite notepad++ http://notepad-plus-plus.org/
CorrieTVrename.py - the script

Windows Setup
(It’s a python script so it should work on other OS’s. You may have to change Directory names \\ to \)

PATHEXT Setup
In Windows to run a python script from Sabnzbd you have to add .py and .pyw to your PATHEXT
Click Start – Right Click My Computer – Click Properties – Click Advance tab or Advance System Settings in Vista/7
Click Environment Variables …… Under system Variables find PATHEXT – Highlight PATHEXT - Click Edit and add; .PY; .PYW …… Click OK and Restart your system.

If the above is confusing try this link - http://www.voidspace.org.uk/python/arti ... line.shtml

Setup Sickbeard
Just add Coronation Street as a new show and setup as you would for any other shows. (You don’t need it set as Active)
http://code.google.com/p/sickbeard/wiki/PostProcessing

Create a CorrieTVTemp Category in Sabnzbd
Setup a new SABnzbd Category for CorrieTV ( 1 ) and under folder/path create a CorrieTVTemp folder\* ( 2 ) to save to.
(remember to add the * so it doesn’t create any folders when saving). Also remember to make a CorrieTV folder in your watch folder and make sure your CorrieTVTemp folder\* is a real folder.

Note: Add a Failed folder in the same location as CorrieTVTempfolder to catch any mislabeled files.

Image
Image1
Now copy CorrieTVrename.py to your Sabnzbd script folder location with your sabtosickbeard files as stated here. - http://code.google.com/p/sickbeard/wiki/PostProcessing
Open CorrieTVrename.py with your Text editor and change the setup Info.
Image
Image2

Remember to select your new script (CorrieTVrename.py) ( 3 )in your new CorrieTV category.
Image
Image1

Setup RSS in SABnzbd+
Click on the RSS tab at the top
Click Add feed if you already have feeds setup to add new feed.
Change your feed name to Coronation Street 1
Paste ( http://rss.binsearch.net/rss.php?max=50 ... tish.drama ) URL in the box provided 2
Now Click the Add Feed below your URL you just entered. 3
Image
image3

Click Coronation Street
Image
Image4

Select your new category you created ( corrie_tv ) ( 1 ) then click Filters.
Image
Image5

Setup your Filters as shown below
Image
Image6

0 -- Requires -- Coronation Street ---- remember to save setting on each line.
1 -- Accept -- .2012
2 -- Accept -- .2013

Click Read Feed you can select Force Download now to download all matches or Download each by itself.
Or click the arrow ( 2 ) and Save Settings to turn on the automatic download.
Image
Image5

Everything should be setup. You now should have a RSS feed that filters out Coronation street . After Sabnzbd downloads the file it will run the corrie script and move to your TV downloads that you have setup with Sickbeard.

I Hope this setup not only helps the Coronation Street fans download and track there shows but also shows how you can use the RSS feeds to help download what the Big guns aren’t . As for the Script it’s just a simple code that takes the file name changes the air date to an easier to read format and uses the Thetvdb API to find the correct season/episode and renames the file so Sickbeard can process the file.

This is not a sure fire way to download Coronation Street but as long as the uploader is using his current file naming scheme everything should work.

Updated 05/20/2012 - will delete all files but AVI's correcting left over files problem.
Download the script here : http://www.mediafire.com/download.php?mve3ja45730qve0
Download these steps here: http://www.mediafire.com/download.php?yshnxxea1xkvotw

Updated 07/30/2012
New EastEnders Renamer setup

Create a Ender_TV Category in Sabnzbd - (same as the corrie_tv but change the name to enders)
Now copy EndersTVrename.py to your Sabnzbd script folder - (same as the corrie_tv but change the name to enders)
Open EndersTVrename.py with your Text editor and change the setup Info. - (same as the corrie_tv but change the name to enders)

Setup your RSS feed like this -

Feed - http://rss.binsearch.net/rss.php?max=10 ... multimedia
Category - enders_tv or what you created in your category settings

your filters should be -

0 --- Requires ----- EastEnders -------- default default default default
1 --- Requires ----- WS/PDTV/XviD --- default default default default
2 --- Accept ------- .2012 --------------- default default default default
3 --- Accept ------- .2013 --------------- default default default default


Here is the new EastEnder Script - ( setup the same as corrie_tv )
http://www.mediafire.com/?g7fewqqymjc05wz


Just Giving Back
J03
Last edited by J03 8LACK on July 30th, 2012, 10:58 pm, edited 4 times in total.
enigma333
Newbie
Newbie
Posts: 1
Joined: April 9th, 2012, 2:34 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by enigma333 »

Worked great for me - running on my Synology NAS.
Alrizz
Newbie
Newbie
Posts: 1
Joined: May 19th, 2012, 1:11 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by Alrizz »

This script works great. The only hiccup I had was that I had my cleanup list formatted incorrectly in SabNZB. I forgot the ","'s between the file extrensions. This script errors out if there are other files in the temp directory with different extensions ie. .nfo .svf and such.

Thanks
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by J03 8LACK »

Alrizz wrote:This script works great. The only hiccup I had was that I had my cleanup list formatted incorrectly in SabNZB. I forgot the ","'s between the file extrensions. This script errors out if there are other files in the temp directory with different extensions ie. .nfo .svf and such.

Thanks
Hey Alrizz,

Thanks for finding this bug

I added some code to check if the files are AVI's and delete if not.

I have updated the main page with new script.
Thanks
J03
steppedup
Newbie
Newbie
Posts: 3
Joined: February 22nd, 2011, 8:38 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by steppedup »

Thanks for this - not quite working yet for me, but almost there.

Quick note - I might have missed this in the instructions, but according to the comments in the actual script, the script has to be in the same folder as autoProcesstv folder of sickbeard - which is: C:\Program Files\SickBeard\autoProcessTV

#****************************************************************************************************
# the below code is from sickbeard (sabtosickbeard.py)
# you will have to have the sab to sickbeard files in the same folder as this script.
# Also remember to setup your autoProcessTV.cfg
# if you already have sab to sickbeard setup just make sure this is script is in the same folder.
#*************************************************************************************************


I had to actually copy the C:\Program Files\SickBeard\autoProcessTV\autoProcessTV.cfg.sample and make a new one called:
C:\Program Files\SickBeard\autoProcessTV\autoProcessTV.cfg ( I don't have a username or password set, so didn't have to make any adjustments).

This will affect where you've downloaded the script to - and where you are setting the PATH variable to (just include it).
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by J03 8LACK »

steppedup wrote:Thanks for this - not quite working yet for me, but almost there.

Quick note - I might have missed this in the instructions, but according to the comments in the actual script, the script has to be in the same folder as autoProcesstv folder of sickbeard - which is: C:\Program Files\SickBeard\autoProcessTV

#****************************************************************************************************
# the below code is from sickbeard (sabtosickbeard.py)
# you will have to have the sab to sickbeard files in the same folder as this script.
# Also remember to setup your autoProcessTV.cfg
# if you already have sab to sickbeard setup just make sure this is script is in the same folder.
#*************************************************************************************************


I had to actually copy the C:\Program Files\SickBeard\autoProcessTV\autoProcessTV.cfg.sample and make a new one called:
C:\Program Files\SickBeard\autoProcessTV\autoProcessTV.cfg ( I don't have a username or password set, so didn't have to make any adjustments).

This will affect where you've downloaded the script to - and where you are setting the PATH variable to (just include it).
Hey steppedup,

Did you get it working?
Thanks for pointing this out I just assumed that everyone new how to setup sabtosickbeard. I will add a link to the Sickbeard instructions and hope this helps others with the same problem. - http://code.google.com/p/sickbeard/wiki/PostProcessing

Thanks again
J03
jamesjfa
Jr. Member
Jr. Member
Posts: 50
Joined: June 15th, 2012, 9:37 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by jamesjfa »

Thank You

I have just applied this to my Synology NAS. Will wait on a new download to check it and make sure I have it working. Do you have something similar for Eastenders?

Cheers,
James
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by J03 8LACK »

jamesjfa wrote:Thank You

I have just applied this to my Synology NAS. Will wait on a new download to check it and make sure I have it working. Do you have something similar for Eastenders?

Cheers,
James
Hey James,

Does Sickbeard have problems finding new episodes of Eastenders?
It seems it has a lot simpler naming convention I will test.
If Sickbeard does have problems the Corrie TV script could easily be changed to handle Eastenders.

Let me Know if you get the Corrie TV script working.

Thanks
J03
jamesjfa
Jr. Member
Jr. Member
Posts: 50
Joined: June 15th, 2012, 9:37 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by jamesjfa »

Hi J03

Well an episode of corrie downloaded but didn't process. I received the following error:

/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 1: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 2: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 3: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 4: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 5: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 6: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 7: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 8:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 10:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 11: yourPath: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 12: failedPath: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 13:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 15:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 20: goodcount: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 21: badcount: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 22: syntax error: unexpected "("


Also, I am running Sab on a Synology DS212J. I don't have problem with downloads however when Sab first starts and also when the corrie script runs, I receive the following error:

012-07-27 10:03:32,642 ERROR: Cannot change permissions of /volume1/Downloads/Incomplete
jamesjfa
Jr. Member
Jr. Member
Posts: 50
Joined: June 15th, 2012, 9:37 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by jamesjfa »

Should have posted the script too:

import glob, os
import httplib
import shutil
import urllib
import re
import sys
import autoProcessTV

#*************** Enter your Setup Info ******************************************************************************

yourPath = '/volume1/Downloads/CorrieTVTemp' # this is the temp folder you have to create for Sabnzbd categories setup
failedPath = '/volume1/Downloads/CorrieTVFailed' # this is the Failed folder you added when you created your categories

#********************************************************************************************************************

##################################################################################
# searchs yourPath for files, renames the date order from mm/dd/yy to yyyy/mm/dd #
# then uses TheTVdb.org to rename to season/episode so Sickbeard can process #
##################################################################################
goodcount = 0
badcount = 0
for filename in glob.glob(os.path.join(yourPath, "*coronation.street.*")):
name = filename
print name
nameoffile = os.path.basename(name)
print "Orginal filename : " + nameoffile
pathname = os.path.dirname(name)
parts = nameoffile.split('.') # gives you ["coronation","street","date"]
AirDate = "20" + parts[4] + "-" + parts[3] + "-" + parts[2]
print parts[-1]
if parts[-1] == 'avi':
print "File is an avi OK to rename" # checks if it an avi or not #
goodname = ' '
failedname = ' '

###########################################
# get info from thetvdb from the Air date #
###########################################

ThetvdbAPIurl = 'http://www.thetvdb.com/api/GetEpisodeBy ... 5&airdate=' + AirDate
f = urllib.urlopen(ThetvdbAPIurl)
contents = f.read()
f.close()

#########################
# get the season number #
#########################

r = re.compile('<SeasonNumber>(.*?)</SeasonNumber>')
m = r.search(contents)
if m:
seasonNum = m.group(1)
try:
seasonNum
except NameError:
print ' Unable to find correct episode from the orginal filename '
print ' will move to failed folder for manual renaming '
failedname = failedPath + nameoffile
print failedname
print ''
os.rename(filename, failedname)
badcount = badcount + 1
continue

########################
# get a Episode number #
########################

r = re.compile('<EpisodeNumber>(.*?)</EpisodeNumber>')
m = r.search(contents)

if m:
episodeNum = m.group(1)
try:
episodeNum
except NameError:
print ' Unable to find correct episode from the orginal filename '
print ' will move to failed folder for manual renaming '
failedname = failedPath + nameoffile
print failedname
print ''
os.rename(filename, failedname)
continue
r = 0

##################################################
# check if there are multiple parts per Air date #
##################################################

if parts[5] == 'part':
print 'This is a multi - part Air Date'
episode = (int(episodeNum)- 1) + int(parts[6]) # corrects the episode number due to multiple parts
episodeNum = str(episode)

##################################################################
# Rename file S**E**.avi so Sickbeard will be able to process it #
##################################################################

newname = parts[0] + " " + parts[1] + " - S" + seasonNum + 'E' + episodeNum + ".avi" # renames the file to a file Sickbeard will be able to find
print "New filename : " + newname
goodname = yourPath + newname
del seasonNum
del episodeNum
if len(goodname) > 2: # checks if all files failed renaming
goodcount = goodcount + 1
os.rename(filename, goodname)
else :
print "not an avi deleting file"
os.remove(name)
if goodcount == 0:
sys.exit('All files failed renaming please check Failed folder')
if badcount > 0:
print 'Some files caused errors and have been moved to your Failed Folder'

#****************************************************************************************************
# the below code is from sickbeard (sabtosickbeard.py)
# you will have to have the sab to sickbeard files in the same folder as this script.
# Also remember to setup your autoProcessTV.cfg
# if you already have sab to sickbeard setup just make sure this is script is in the same folder.
#*************************************************************************************************

if len(sys.argv) < 2:
print "No folder supplied - is this being called from SABnzbd?"
sys.exit()
elif len(sys.argv) >= 3:
autoProcessTV.processEpisode(sys.argv[1], sys.argv[2])
else:
autoProcessTV.processEpisode(sys.argv[1])
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by J03 8LACK »

HI James,
have you tried running the script from the Prompt ~ python CorrieTVrename.py

You may need to add a shebang to the script when running in a Linux / UNIX environment.
First line of the script must have -

#!/usr/bin/env python

This will tell the script how to run it.
as for the permission error have you tried this

SABnzbd has the option to set permissions for the final result.
See Config->Folders.

Also i did create a EastEnders script if anyone is interested.

Tell me how it goes?
J03

PS . when posting code use the code tool in the editor.
jamesjfa
Jr. Member
Jr. Member
Posts: 50
Joined: June 15th, 2012, 9:37 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by jamesjfa »

away to try it right now
jamesjfa
Jr. Member
Jr. Member
Posts: 50
Joined: June 15th, 2012, 9:37 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by jamesjfa »

J03 8LACK wrote:HI James,
have you tried running the script from the Prompt ~ python CorrieTVrename.py

You may need to add a shebang to the script when running in a Linux / UNIX environment.
First line of the script must have -

#!/usr/bin/env python

This will tell the script how to run it.
as for the permission error have you tried this

SABnzbd has the option to set permissions for the final result.
See Config->Folders.

Also i did create a EastEnders script if anyone is interested.

Tell me how it goes?
J03

PS . when posting code use the code tool in the editor.
I added the line but received another error. I am guessing this is not where python is.

env: python
: No such file or directory
jamesjfa
Jr. Member
Jr. Member
Posts: 50
Joined: June 15th, 2012, 9:37 pm

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by jamesjfa »

Also when I try to run it from the command line I get this error:

volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 1: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 2: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 3: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 4: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 5: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 6: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 7: import: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 8:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 10:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 11: yourPath: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 12: failedPath: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 13:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 15:
: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 20: goodcount: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 21: badcount: not found
/volume1/Downloads/SabNZbd Scripts/CorrieTVrename.py: line 22: syntax error: unexpected "("
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Python] Corrie TV (Coronation Street) renamer script

Post by J03 8LACK »

Hey James
have you tryed just running sabtosickbeard.py and see what errors come up.

try it from the command line.

J03
Post Reply