WIP Correcting TVH's absolute episode numbering.
#1
Tongue 
Firstly, I'd just like to point out that I have only recently switched to TVH from a mythtv backend, and that therefore I might have set things up wrongly !! Blush

Anyway, background.

My wife is an avid soap fan !! To further increase SAF, I set up TVH to record some episodes, noticing that it's able to append the episode number to the filename. Having recorded a couple, I scanned them with XBMC. Unfortunately, the episode numbers were all absolute numbers, of the form EXXXX instead of SXXEXX Sad Because the wife couldn't find them in the TV Shows library (show name showed up but with no episodes inside) SAF rapidly decreased !!

Scouting around on t'interweb for a solution, I found that TVrage lists the absolute episode number, and, the season/episode number as well.

So, what I have done is to write a small bash script to enumerate through a directory and rename the files to something XBMC can scrape.

What it does so far.

Looks through a directory for .mkv files and strips out the absolute episode number from each file in turn.
Looks up the tvrage show-id from the first filename using the tvrage API, matches the absolute episode number to the season/episode number using tvrage's episode list for that show-id and renames each file accordingly.

EG emmerdale.E6661.mkv becomes emmerdale.S43E11.mkv
coronation-street.E8287.mkv becomes coronation-street.S55E09.mkv

What it doesn't do (yet !!)

Move any of the renamed files into show/season matched directories.
Error check !! The script expects a filename in the form 'showname.episode.mkv'. It doesn't do any error checking if your files are named in a different format or if they have already been renamed. If you use it and it trashes your files/hdd/xbmc hard luck!! I make no warranties about it's suitability for use. I wrote it for me, but then decided to share it in case it comes in useful for anyone else.

Stuff still to do

Add much more error checking for things like not being able to find a show-id, files already renamed etc
Skip files that are already correctly named !!
Add the ability to move files to the correct directory based on the base path of TVH's recording path (and assuming it's set to create a directory for each show).
Add the ability to create a season folder under the show directory if one doesn't already exist. This would mean on first run or the addition of a new show that directories would be auto created.
Add the ability to run it from the base directory specified in TVH's recording config. This would make it possible to call it with TVH's post-processor command and have everything handled automatically at the end of the recording.

How to use it

Currently the script is only recursive in one directory so you need to drop it into your required directory, make it executable and then run it.

I've tested it against Coronation street, Emmerdale & eastenders and in all cases it has worked as expected although YMMV Laugh

Comments welcome, as is scripting help !!!

UPDATE

Added the ability to run from the root directory containing your TV shows. Script now steps through each directory in turn.
Added more error checking. Already renamed files are skipped.
Changed the way the script obtains the show title. It was from the first filename in the directory but now takes the name of the directory as the show title. This is more in line with XBMC's scraper expectations anyway.

Still to do - Move files to the correct season directories when processed.

Link updated to current version.
Link to script http://pastebin.com/ZeRufs7X
Learning Linux the hard way !!
Reply
#2
Thank you for posting this! I am trying to convert to TVHeadend from SageTv and I've been looking for something that does exactly this. Please update this thread when/if you make more updates. I'll give feedback when I get a chance to try it.
Reply
#3
Just tried the script. Seems it doesn't handle spaces in directory names well:

Code:
root@debian# \ls
Ask This Old House  Small Soldiers  livetvbuffer  renamer.sh
( /mnt/data/data/tvrecordings )
root@debian# ls
Ask This Old House  Small Soldiers  livetvbuffer  renamer.sh
( /mnt/data/data/tvrecordings )
root@debian# ./renamer.sh
changing directory to Ask This Old House/
./renamer.sh: line 6: cd: Ask: No such file or directory
Filname not correct format - skipping
0 files renamed
changing directory to Small Soldiers/
./renamer.sh: line 6: cd: Small: No such file or directory
Filname not correct format - skipping
0 files renamed
changing directory to livetvbuffer/
./renamer.sh: line 6: cd: livetvbuffer/: No such file or directory
Unable to find show-id.  Exiting !!

I tried changing line 6 to read:
Code:
cd "$file"

But that didn't work either. Any thoughts?
Reply

Logout Mark Read Team Forum Stats Members Help
Correcting TVH's absolute episode numbering.0