Anime TheTVDB Rename Script

Come up with a useful post-processing script? Share it here!
Wernerbuck
Newbie
Newbie
Posts: 1
Joined: December 4th, 2008, 8:16 am

Anime TheTVDB Rename Script

Post by Wernerbuck »

I'd like to share my post-proccessing that renames anime files in a directory to a proper to be scraped tv episode for use in for example XBMC.

Anime Rename Script 1.0

Transforms  
[Conclave-Mendoi]_Mobile_Suit_Gundam_00_S2_-_02_[1280x720_H.264_AAC][C1A7E11B].mkv
to
[Conclave-Mendoi]_Mobile_Suit_Gundam_00_S2_-_02_[1280x720_H.264_AAC][C1A7E11B].S02E02.mkv

It searches www.thetvdb.com for the show and absolute episode number and renames the file accordingly.
It can handle subdirectories and only handles .mkv/.avi/.mp4 files.

Help output:
Anime Rename script v1.0

Searches directory recursively for .mkv/.avi/.mp4 video files.
When found it tries to find the season and episode on www.thetvdb.com to rename
the file so it can be correctly scraped by XBMC's TvDB scraper.

Can be used for SABnzbd and or as standalone script
Requires:
- PHP-CLI (ubuntu apt-get install php5-cli)
- Correct permissions.
Could work for windows not tested.

Example command:
php -f procanime.php -- '/storage/Anime/Mobile Suit Gundam 00/'

How to install?
Unfortunately this is a php script.
So you have to install php5-cli (apt-get install php5-cli) to use the phpscript.

Shell script:
Create a file procanime.sh and give it proper permissions.
Copy these three lines to it:
#!/bin/bash
# $1 (source path) is provided by sabnzbd+ upon execution
php -f procanime.php -- $1

PHP script:
Download the php script from http://pastebin.com/f126072bd
Rename it to procanime.php
Give it proper permissions.

And your ready to go!

Here's an example:
[DB]_Bleach_196_[3FDE9706].avi
Show name: Bleach 196
Possible season number:
Episode number: 196
Clean Show Name: Bleach
TheTVDB Series Name: Bleach
TheTVDB Series ID: 74796
TheTVDB Series Season: 9
TheTVDB Series Episode: 7
SUCCESS, Renamed from /storage/Anime/Bleach/[DB]_Bleach_196_[3FDE9706].avi to  /storage/Anime/Bleach/[DB]_Bleach_196_[3FDE9706].S09E07.avi

[DB]_Bleach_197_[6578B411].avi
Show name: Bleach 197
Possible season number:
Episode number: 197
Clean Show Name: Bleach
TheTVDB Series Name: Bleach
TheTVDB Series ID: 74796
TheTVDB Series Season: 9
TheTVDB Series Episode: 8
SUCCESS, Renamed from /storage/Anime/Bleach/[DB]_Bleach_197_[6578B411].avi to  /storage/Anime/Bleach/[DB]_Bleach_197_[6578B411].S09E08.avi

[gSS]_Gundam_00_S2_-_08_[1D99B542].mkv
Show name: Gundam 00 S2 08
Possible season number: 2
Episode number: 08
Clean Show Name: Gundam 00
TheTVDB Series Name: Mobile Suit Gundam 00
TheTVDB Series ID: 80675
TheTVDB Series Season: 2
TheTVDB Series Episode: 08
SUCCESS, Renamed from /storage/Anime/Mobile Suit Gundam 00/Season 2/[gSS]_Gundam_00_S2_-_08_[1D99B542].mkv to  /storage/Anime/Mobile Suit Gundam 00/Season 2/[gSS]_Gundam_00_S2_-_08_[1D99B542].S02E08.mkv

Things to know:
1. It only renames if there is no 'S02E08' tag in the filename, it also returns an error if the anime can't be found on www.thetvdb.com same with the absolute episode number.
2. It doesn't find your show or episode? then add it to www.thetvdb.com!
3. It doesn't handle double episodes yet, something for the near future :)

If you use this script in your own package or script please send me an email ;)

Greetz
Sinnocence
Newbie
Newbie
Posts: 23
Joined: April 6th, 2009, 3:45 am

Re: Anime TheTVDB Rename Script

Post by Sinnocence »

Thanks for your script. I've modified it a little for non-anime purposes, as a general renaming script for my files. The modified copy is at http://pastebin.com/m73bc200f

The above modification looks for *x* named files (e.g. "ShowTitle 1x01.avi") and renames it to "ShowTitle - S01E01 - EpisodeTitle.avi".

Obviously it doesn't do what your original does any more - I'm posting it just in case it is of any use to you/the community (seeing as you wrote and shared the original!).

Thanks again,

Sinno

[edit] FYI I've linked to here from the XBMC forums, http://xbmc.org/forum/showthread.php?p= ... post432714 [/edit]
Last edited by Sinnocence on November 7th, 2009, 1:03 pm, edited 1 time in total.
Sinnocence
Newbie
Newbie
Posts: 23
Joined: April 6th, 2009, 3:45 am

Re: Anime TheTVDB Rename Script

Post by Sinnocence »

No you're right I think, I edited my post on the XBMC forums. I'm only using a .bat, just typed up the .sh as a ref. Thanks for that.
Heratiki
Newbie
Newbie
Posts: 2
Joined: January 10th, 2010, 9:35 pm

Re: Anime TheTVDB Rename Script

Post by Heratiki »

Sinnocence wrote: Thanks for your script. I've modified it a little for non-anime purposes, as a general renaming script for my files. The modified copy is at http://pastebin.com/m73bc200f

The above modification looks for *x* named files (e.g. "ShowTitle 1x01.avi") and renames it to "ShowTitle - S01E01 - EpisodeTitle.avi".

Obviously it doesn't do what your original does any more - I'm posting it just in case it is of any use to you/the community (seeing as you wrote and shared the original!).

Thanks again,

Sinno

[edit] FYI I've linked to here from the XBMC forums, http://xbmc.org/forum/showthread.php?p= ... post432714 [/edit]
Any chance this is still around somewhere?  The link to Pastebin on the modified one no longer works and I would desperately like to be able to get this working.

Heratiki
beckstown
Newbie
Newbie
Posts: 2
Joined: January 1st, 2010, 6:36 pm

Re: Anime TheTVDB Rename Script

Post by beckstown »

Hi,

I would love to use this script and got it running. However, I always get the error: "FAILED, Absolute number not found on TheTVDB.com for this show."

This happens for shows that definitely have an absolute numbering on thetvdb.com.

So I can only assume that something changed with the API for absolute numbering as the rest of the script works. Does anybody have a clue and could help me out?
th3joker
Jr. Member
Jr. Member
Posts: 64
Joined: January 25th, 2008, 8:15 am

Re: Anime TheTVDB Rename Script

Post by th3joker »

How would you modify the code to rename an episode like this:

From=

TVSeries - 1x01 - 720p HDTV x264 CTU.mkv

To=

TVSeries - 1x01 - Episode Name.mkv

Is that possible?
squareatom
Newbie
Newbie
Posts: 26
Joined: February 17th, 2011, 6:40 pm

Re: Anime TheTVDB Rename Script

Post by squareatom »

beckstown wrote: Hi,

I would love to use this script and got it running. However, I always get the error: "FAILED, Absolute number not found on TheTVDB.com for this show."

This happens for shows that definitely have an absolute numbering on thetvdb.com.

So I can only assume that something changed with the API for absolute numbering as the rest of the script works. Does anybody have a clue and could help me out?
I modified original script and it's now working.

http://forums.sabnzbd.org/http://forums ... 796#p43796
th3joker wrote: How would you modify the code to rename an episode like this:

From=

TVSeries - 1x01 - 720p HDTV x264 CTU.mkv

To=

TVSeries - 1x01 - Episode Name.mkv

Is that possible?
Check out the sick beard addon. It will do that.
Last edited by squareatom on February 17th, 2011, 6:59 pm, edited 1 time in total.
airtraxx
Newbie
Newbie
Posts: 3
Joined: March 1st, 2011, 9:14 pm

Re: Anime TheTVDB Rename Script

Post by airtraxx »

Hi Guys,

I was wondering if you guys can help me out?  I am such a noob at this.  Where do you put the procanime.sh and procanime.php respectively?  I really would like to use this script because it would save me a ton of time renaming my anime properly.  I place them in my script folder that is setup in SAB but every time I get an  -1 error at the end.

I am running SAB on Snow Leopard 10.6.6.  Thanks for you help.
squareatom
Newbie
Newbie
Posts: 26
Joined: February 17th, 2011, 6:40 pm

Re: Anime TheTVDB Rename Script

Post by squareatom »

airtraxx wrote: Hi Guys,

I was wondering if you guys can help me out?  I am such a noob at this.  Where do you put the procanime.sh and procanime.php respectively?  I really would like to use this script because it would save me a ton of time renaming my anime properly.  I place them in my script folder that is setup in SAB but every time I get an  -1 error at the end.

I am running SAB on Snow Leopard 10.6.6.  Thanks for you help.
You can put the scripts anywhere. You only need the .sh script if you're using it as a post processing script. In which case you need to specify the folder in SabNAB config, Config->Folders->Post-Processing Scripts Folder. Also, you need need PHP installed. I'm using Ubuntu and not OsX, so not sure where your problem lies. Good luck.
airtraxx
Newbie
Newbie
Posts: 3
Joined: March 1st, 2011, 9:14 pm

Re: Anime TheTVDB Rename Script

Post by airtraxx »

Thanks man for the response.  yeah for some reason using the script within sab doesn't work for me.  I can run the php file manually within terminal.  im not sure what's wrong.  maybe permissions.  gonna have to dig deeper into it but at least i got some footing now.  Thanks for the help.
badboy123
Newbie
Newbie
Posts: 7
Joined: March 13th, 2011, 11:28 am

Re: Anime TheTVDB Rename Script

Post by badboy123 »

I just came across the script, tested a few files and it seems to be working perfectly...

I would like to put in a request...

Rather than renaming the file:

      [original filename].[season episode].[extension]

would it be possible to modify the script to rename the file as:

      [TheTVDB Series Name].[season episode].[extension]

e.g. [HorribleSubs]_Naruto_Shippuuden_-_202_[480p].mkv

This would be renamed to:

      [HorribleSubs]_Naruto_Shippuuden_-_202_[480p].s10e06.mkv

but I would like it to be renamed as:

      Naruto Shippuuden.s10e06.mkv

This shouldn't be too complex as 'TheTVDB Series Name' is set as an output in the original script...

Thanks
squareatom
Newbie
Newbie
Posts: 26
Joined: February 17th, 2011, 6:40 pm

Re: Anime TheTVDB Rename Script

Post by squareatom »

badboy123 wrote: I just came across the script, tested a few files and it seems to be working perfectly...

I would like to put in a request...

Rather than renaming the file:

      [original filename].[season episode].[extension]

would it be possible to modify the script to rename the file as:

      [TheTVDB Series Name].[season episode].[extension]

e.g. [HorribleSubs]_Naruto_Shippuuden_-_202_[480p].mkv

This would be renamed to:

     [HorribleSubs]_Naruto_Shippuuden_-_202_[480p].s10e06.mkv

but I would like it to be renamed as:

     Naruto Shippuuden.s10e06.mkv

This shouldn't be too complex as 'TheTVDB Series Name' is set as an output in the original script...

Thanks
Makes sense. Code updated to reflect request. http://pastebin.com/yfB1GiJf

Code: Select all

touch '[HorribleSubs]_Naruto_Shippuuden_-_202_[480p].mkv'; php5 -f animeRename.php -- .
[HorribleSubs]_Naruto_Shippuuden_-_202_[480p].mkv
Show name: Naruto Shippuuden 202
Possible season number: 
Episode number: 202
Clean Show Name: Naruto Shippuuden
TheTVDB Series Name: Naruto Shippuuden
TheTVDB Series ID: 79824
TheTVDB Series Season: 10
TheTVDB Series Episode: 6
SUCCESS, Renamed from ./[HorribleSubs]_Naruto_Shippuuden_-_202_[480p].mkv to  ./Naruto Shippuuden.S10E06.mkv
Last edited by squareatom on March 13th, 2011, 10:07 pm, edited 1 time in total.
badboy123
Newbie
Newbie
Posts: 7
Joined: March 13th, 2011, 11:28 am

Re: Anime TheTVDB Rename Script

Post by badboy123 »

Excellent work...Work perfectly  ;D
jwbrown77
Newbie
Newbie
Posts: 3
Joined: March 21st, 2011, 11:39 am

Re: Anime TheTVDB Rename Script

Post by jwbrown77 »

Removed.
Last edited by jwbrown77 on March 21st, 2011, 2:47 pm, edited 1 time in total.
squareatom
Newbie
Newbie
Posts: 26
Joined: February 17th, 2011, 6:40 pm

Re: Anime TheTVDB Rename Script

Post by squareatom »

I can appreciate your work but you should have started your own thread. It would make more sense since your script uses a different source and has different installation steps. Also, I see you wrote your wrapper in PHP which in turn calls a Perl script. I think it would make more sense to do shell or Perl wrapper. Reason being, if one does not have Perl or PHP installed, they would only have to install Perl. With you doing a PHP wrapper, someone would need to install Perl and PHP if they didn't have anything installed.

Yes, I know the OP wrote this script in PHP, but there is a whole different methodology behind it.

Anyway, good work. That API looks very robust compared to the OP's solution.
Post Reply