See also: Heapify

Go back to post Create new comment

RSS Be notified of new comments on this post with the RSS feed for this post.


Saw you watched my moovy project on github. Seems we have the same ideas in mind! I discovered tvdb last night and was going to write pretty much exactly what you've done in ruby to rename all my tv shows.

I don't actually store or watch my tv shows off my mac and instead sit on a 2TB vista file server / htpc. Was playing around with making a rails app to run of the HTPC which provided a nice listing of all my tv shows -- displaying banners, episode summaries/ratings and try to find a way to make it also a controller for media center or a vlc instance to stream it....

I"ll be watching your stuff on github. looks awesome. too bad i don't speak python :S


Hi, your script is great and works brilliantly most of the time, however I have noticed that the script seems to break when the new episode name has a question mark (or one of those of the characters that windows won't allow in a file name). Would it be easy to add a couple of lines to your script to just ignore question marks?


Chris: Just edit line 69, ( config['valid_filename_chars'] ) and remove the question-mark character.

Bodaniel: Indeed, we do seem to have similar plans. The moovy application seems interesting - with consistently named files it shouldn't be difficult at all to write a web-interface to organise files, allow it to add new files from a "completed downloads/rips" directory, warn of missing files and such... moovy seems like a good starting point for this, but I have never gotten into Ruby/Rails, although I am reconsidering it with the (somewhat absurd) number of interesting modules/projects that have sprung up around ruby..


Great script!

It did exactly what I wanted it to do.

Thank you for your effort.


Can't get it to work properly on Windows:

F:\Media\TV\Smallville - 8x05 - Committed>tvnamer smallville.s08e05.720p.hdtv.x2
# Starting tvnamer
# Processing 1 files
# tvdb mirrors
# Starting to process files
# Processing smallville (season: 8, episode 5)
TVDB Search Results:
Traceback (most recent call last):
  File "d:\program files (x86)\python26\scripts\", line 8, in <module> load_entry_point('tvnamer==0.5.1', 'console_scripts', 'tvnamer')()
  File "build\bdist.win32\egg\", line 337, in main
  File "build\bdist.win32\egg\", line 183, in processFile
  File "build\bdist.win32\egg\", line 492, in __getitem__
  File "build\bdist.win32\egg\", line 477, in _nameToSid
  File "build\bdist.win32\egg\", line 395, in _getSeries
  File "build\bdist.win32\egg\", line 59, in selectSeries
  File "build\bdist.win32\egg\", line 55, in _displaySeries
TypeError: encode() takes at most 2 arguments (3 given)
F:\Media\TV\Smallville - 8x05 - Committed>

Could this be extended to move files within a directory structure aswell?

For example something like:


So it would move it to the correct folder as well as renaming the file?


I use the command line in Linux allot and as such spaces in my file names are a bit of a pain, as such I added this to your script to allow it to strip spaces from the file names and replace them with underscores.

Thought you might be interested in including it.

-c and --clean where used mostly because the other letters were already used.

<     # Replace spaces with uderscores
<     if opts.cleanspace:
<         newname = newname.replace(" ","_")
<     #end if cleanspace;
<     parser.add_option(  "-c", "--clean", action="store_true", default=False, dest="cleanspace",
<                         help="Clean spaces. replace with underscores")

Dude this script is awesome!

Exactly what I was going to do myself, and now, thanks to you, I got additional freetime :)

Thank you very much! :)


Since it's been almost a year since this was released, and it haven't been updated with an auto-move feature, I made it myself: Download

Just run tvnamer file -m and it will rename and move the file to the location specified in the top of

For example if you set the target directory to /TV-Shows/ and run tvnamer House.S05E13.hdtv.random.crap.avi -m the script will create a new folder called House in /TV-Shows/ (if it doesn't already exist) and a subfolder called Season 5(also if it doesn't exist). Then move the file to /TV-Shows/House/Season 5/

Remember to edit before you run the script.

I have also made some changes to the name format, so it's compatible with XBMC.


I searched and searched for something like this, to fit within my workflow.

While it works flawlessly when I do individual files, when I try and apply it to a folder, I get this error - not sure what to do.

File "/usr/local/bin/tvnamer", line 338, in <module>
  File "/usr/local/bin/tvnamer", line 332, in main
    print "# Processing %(file_seriesname)s (season: %(seasno)d, episode %(epno)d)" % (cfile)
TypeError: format requires a mapping




Works very well on Snow Leopard--thank you!


Just a note to say a) thanks! and b) it might be useful to OSX users if the script ignored filenames that begin with '._'

It's only really an issue on non-hfs volumes (I have most of my video on a SMB mounted drobo) but it's pretty irritating when the random resource fork file (the ._show.s02e04.random.avi) gets renamed and the ACTUAL file gets skipped due to duplicate filename!

Last edited by the original poster on Mon, 5th Oct 2009 19:37:53

How difficult would it be to change the formatting?

I like [Show].s??e??.[Episode].avi. It also integrates great in XBMC.


Ignore that :).

Although one suggestion. Is there anyway you could move the config to a .tvrenamer file in our home directory that way when we do an update we don't have to fix it manually each time? Thanks.


Hi everybody.

This script is awesome!

I have only a question. I'm Italian, so I would like to have episodes names in Italian.

In there are also in italian. So I need only to change language ID from english to Italian.

Where can I do this in the script if it's possible? Thanks a lot

Please reply to me also by email if you want. Thanks Bye Carlo


Thank you for a great script. It would be great if it could do something similar for movies. Thanks in advance.




I've noticed your building Tvnamer 2.0 with config files

Firstly I'd like to say a big thanks for looking into wishes of the users above.

Secondly are you intrested in testers for this.

I would be glad to help out with testing


I am very interessted in getting the move script working. I have tested the autoPathTv script, but I am not using the same naming standard and I am unable to understand how to change from [01x23] to S01E23 or get the tvnamer.move.mod part of the script.


Anyone interested in a GUI application for this kind of job?

Check it out:


So ... that's why there are so many dead torrents out there ... because of idiots like you who can't bear a file name which does not "look nice" and rename their files, breaking the torrents. I suppose you also move the files in a safe place before renaming, and deleting the torrents. God forbid to continue seeding. Idiot.


Just found this TVRenamer and it sounds slick, can it be set to use SxxExx format in the renamed file instead of xxXxx format?

And does it work with shows that where the filenames don't have Season and Episode numbers, say something like: Travel.Channel.Chef.Abroad.Holiday.Traditions.Greece.PDTV.XviD-NANO (I am wondering if it would convert that Travel Channel show to a name that does include Season and Episode information.)



Just found this TVRenamer and it sounds slick, can it be set to use SxxExx format in the renamed file instead of xxXxx format?

Yes, you can customise the output name's format quite easily. Check the "Custom output filenames" section of the readme on

And does it work with shows that where the filenames don't have Season and Episode numbers, say something like: Travel.Channel.Chef.Abroad.Holiday.Traditions.Greece.PDTV.XviD-NANO

No. There's no reliable way to parse such filenames (in a generic enough manner), it only works if it can find a series/episode number. You could use tvdb_api and a custom script to rename such files, assuming they are on


great script - can't wait for movie support. But there's a featurerequest i just thought would be very handy for XBMC users.

Please make a param for outputting an xbmc-compatible xml mit all the relevant information already grabbed from the tvdb ans save it under the same name as the tvshow.mkv

That would be soo cool


I would love to see the automatic renaming and placing into a given directory. That would make my rtorrent solution almost flawless. Any idea when you might implement that feature?


@K. Callis The move-files feature is already implemented, it's just not very stable currently.


can't wait for movie support

I think this would be best done as a separate script, as I'd like to keep tvnamer relatively simple. I wrote a Python interface for themoviedb, which should make this fairly trivial, but usually renaming films is easy to do manually.

I'm not too sure about adding XBMC support either - again I'd rather keep it simple.

I've made a ticket for this, - but again, I'm not too sure about it..

I'd recommend looking at - it will output XML metadata files (it uses tvnamer's internals to parse the files), and automatically grabs fan-art, series banner, series info etc (as well as automatically grabbing torrents/nzb files and lots more)


I liked your tutorial how to rename my torrent downloaded TV episodes. I really found it useful. Its the guys like you who make a difference by contributing so much that any other person could not. Thanks and thumbs up!


Great script! Any plans to support dates in filenames instead of series/episodes?


The Daily Show 03-04-2010 - Scott Patterson.avi



I have some files named generically: 03x01 - The Cabin Show.avi etc, but no way to give the name of the show without renaming the files by hand. Is there a way to specify a show ("i.e.: 'tvnamer -s "Arrested Development" .') with the script?

Thank you!


Is it possible to have, only the correct name as output of the script ?


Great script! Any plans to support dates in filenames instead of series/episodes?

This is implemented now

I have some files named generically: 03x01 - The Cabin Show.avi etc, but no way to give the name of the show without renaming the files by hand

Nope. About the only requirement of tvnamer is the filename must contain the series name, and the episode number (or date)

You could use the custom-replacements feature to prepend the series name to the file, e.g:

    "input_filename_replacements": [
        {"is_regex": true,
        "match": "^",
        "replacement": "Arrested Development"}

..or write a simple shell script around tvnamer to do this. Something I may add is the ability to specify the series name in the interactive prompt - when it searches, you can either select one of the results, or enter a new series name to search for.

Is it possible to have, only the correct name as output of the script ?

Nope, but it would be trivial to use tvnamer as an API to get such info:

>>> import tvnamer.utils
>>> import tvdb_api
>>> p = tvnamer.utils.FileParser('lost.s01e01.avi').parse()
>>> p.populateFromTvdb(tvdb_api.Tvdb())
>>> p.generateFilename()
u'Lost - [01x01] - Pilot (1).avi'

I tried it, it' very handy, thank you guys ! I just wanna know if is it possible move files WITHOUT renaming it ?

If I rename it, then it could be a problem to download the proper subtitle file, without any info about release group & other Tags... Otherwise, if I Had already downloaded the subtitle, is there a way to rename both the .avi & .srt in pair ?

I'm trying to integrate this tool in a chain including deluge-flexget-periscope to control everything in batch mode. This would be the cherry on the top.

Tia Enrico


I just wanna know if is it possible move files WITHOUT renaming it ?

Nope, but if you know Python, you could use bits of tvnamer to do this quite easily. Use the tvnamer.utils.FileParser class, and it should be pretty simple to construct a path

Otherwise, if I Had already downloaded the subtitle, is there a way to rename both the .avi & .srt in pair ?

Sure, just run tvnamer on the .srt - it'll handle it just like the .avi


Thank you Ben for your answer, but I really meant to ask another thing... What I'd like to do is to move the file to another directory without changing the filename, for example :

from /download/incoming/lost.s01e01.avi to /TV/Lost/S01/s01e01.avi

I tried to enable all the move options in tvnamer.json, but it always keep to rename the filename and THEN to move it.

In documentation that I found till now there are no indications about other tags apart from the ones related to showname, season number and so on.

A simple %(sourcefilename), for example could be enough...

Obviosuly I don't know python, not yet...

Thank you & bye Enrico


A simple %(sourcefilename), for example could be enough...

Oh, excellent point, will add this shortly


Hi, excellent script. Using it on Ubuntu 10.10 to tie transmission and xbmc together. I can't seem to get it to run recursively though. have tried setting the parameter to true in .tvnamer.json and tried adding both -r and --recursive options to my script but nothing seems to work. Any ideas?


I can't seem to get it to run recursively though

Odd, it's working fine for me,

$ tree a
$ tvnamer -r a/
# Processing file: lost.s01e01

Very nice! However, I can't allow it to run in batch mode automatically all the time like I would like, because thetvdb contains characters in its series and episode names that are invalid in my XFS file system.

Examples are colons, question marks, and asterixs, such as in "Shit My Dad Says", "Terminator: The Sarah Conn...", "Spartacus: Gods of the Arena" and "NOVA ScienceNOW (do they always have to end episodes with question marks?)

BTW: You guys who can't get it to run recursively, I couldn't either at first, because I was using a wildcard... I was doing /data/*.avi without recursive, but with recursive that won't work, you have to just give it the folder only... so see if that works for you.

Last edited by the original poster on Wed, 25th May 2011 13:01:27

Ok, the XFS file system on linux could handle the characters, but it was when I was trying to view the files across the network from a windows client that they looked messed up... fixed it by adding this code via a command line config file.

"output_filename_replacements": [ {"is_regex": true, "match": "\?", "replacement": ""} , {"is_regex": true, "match": ":", "replacement": " -"} , {"is_regex": true, "match": "*", "replacement": "_"} ]

Thanks a lot, this is something I have wanted for a long time. It will save me a lot of time manually renaming files.


Kissell - you probably want to set is_regex to false if matching a single character.

but with recursive that won't work, you have to just give it the folder only

Yep! The help string should explain this, "-r Descend more than one level directories supplied as arguments"

Meaning tvnamer -r mydir/ will find mydir/subdir/show.s01e01.avi (where as tvnamer mydir/ will only find mydir/show.s01e01.avi)


I am a bit of a newb to Macs and first time to use the Terminal... :/ and I am having issues getting this thing working. This is what I get when I try to test it out:

Last login: Sat Jul 23 15:06:03 on ttys003 xxxxxxxx-iMac:~ xxxxxxxx$ cd movies xxxxxxxx-iMac:movies xxxxxxxxx$ tvnamer .


Starting tvnamer

Invalid filename: Cannot parse u'/Users/xxxxxxxxx/Movies/Ironclad (2011).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/Sucker Punch (2011).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/2012 (2009).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/The Mechanic (2011).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/Limitless (2011).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/Jonah Hex (2010).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/Harry Potter and the Deathly Hallows: Part 1 (2010).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/Season of the Witch (2011).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/I Am Number Four (2011).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/The Expendables (2010).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/.localized' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/Little Fockers (2010).avi' Invalid filename: Cannot parse u'/Users/xxxxxxxxxx/Movies/The Eagle (2011).avi' Usage: tvnamer [options]

tvnamer: error: No valid files were supplied xxxxxxxxxx-iMac:movies xxxxxxxxxx$

It is also failing some of the tests in the test file.

Any help would be appreciated



Где недорого купить картридж Canon Fx 10? - заправка картриджей Canon Fx 10 для лазерных копиров. заправка картриджей brother, лазерные картриджи HP. Где недорогие лазерные картриджи Canon Fx 10? заправка картриджей OKI для лазерного картриджа заправка.


Как лучше поступить копир? Проработал не много потом не включали год тут утром попробовала напечатать, а копир не фурычит.... Вот рядом с домом нашла- - Качественный ремонт ксерокса
Кто здесь чинил копир? Заранее блогадарна!


I as well as my guys ended up going through the best recommendations found on your site pandora bracelets sale while the sudden came up with a horrible suspicion I never expressed respect to the blog owner for those techniques. Most of the ladies are already absolutely excited to study them and have now extremely been having fun with these pandora bracelets Enetteelalo,I appreciate you for genuinely so thoughtful and then for obtaining variety of cheap pandora bracelets smart pandora bracelets sale information millions of individuals are really wanting to be informed on. My personal honest regret for not saying thanks to you earlier.


Cool Offtopic: When will the new season of "Dexter"?! certified pharmacy technician study guide buy generic flomax black penis porn

Go back to post

Create a new comment

Go to the top

You can use a restricted version of markdown formatting here. You can use the toolbar above the text field to make this more painless. For more information about markdown please refer to the markdown cheatsheet.

For post: Automatically rename your torrent'd TV episodes
Your name:
Your email (optional):
Your website (optional):

A preview of your comment:

Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.