GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Simple to use TVDB (thetvdb.com) API in Python, and automatic TV episode namer

TVNamer

What is it?

TVNamer is a realtivly simple command line tool to parse TV episode filenames into something more consistent and nicer to read. It uses data from http://www.thetvdb.com to grab episode names.

What does it do?

my.name.is.earl.s02.e04.dsr.avi
to
My Name Is Earl - [02x04] - Larceny Of A Kitty Cat.avi
or, if it cannot find an episode name
My Name Is Earl - [02x04].avi

How do I use it?

At its simplest:
tvnamer some.episode.s01e02.avi
It then starts up in interactive mode. First you will be prompted to select the correct show. Enter the appropriate number. Then it will prompt you to confirm the new name. If you press “n” it will skip the file and end, “y” will rename the file and end (as it’s the last file)

If you want to name multiple files, you can either list them by doing tvnamer file1.avi file2.avi etc, or simply do tvnamer *, or tvnamer *.avi.

You can also pass directories, and it will descend one level and list all files (not recursively). tvnamer . will rename all files in the current directory.

I trust the script completely, can I skip the confirmations?

Yep, there are a few ways you can reduce the human intervention needed.

Batch mode

Run with --batch or -b

This mode requires no intervention at all. It chooses the first search result as the showname, and renames all files with no confirmation (although it does show the before-and-after names).

Always

Run with --always or -a

This mode always renames files, but allows you to select the correct show from a list. This allows you to check it’s found the correct show, then chances are it will get the correct episode names (assuming the season/episode numbers are correct)

This can be set during run time. Select the correct show, and hit “a” instead of “y” or “n” and it will rename all remaining files without confirmation. This is how I normally use the script – select the correct show, make sure the first few episodes are being named correctly, then enter “a” and automatically name the rest of the files.

I don’t use that naming scheme

The output name-format can be change quite easily:
config['with_ep_name'] = '%(showname)s - [%(seasno)02dx%(epno)02d] - %(epname)s.%(ext)s'
config['without_ep_name'] = '%(showname)s - [%(seasno)02dx%(epno)02d].%(ext)s'

Current options are: - %(showname)s # the showname, as it is on TVDB - %(seasno)d # the season number, use )2d to pad the number to two significant figures - %(epno)d # episode number - %(epname) # The episode name. Only use this in config[‘with_ep_name’]

It won’t recognise my files

Currently supported input file-names are:

  • show.name.s01e21.dsr.nf.avi
  • show.name.s01.e21.avi
  • show.name-s01e21.avi
  • show.name-s01e21.the.wrong.ep.name.avi
  • show.name.s01e21.dsr.nf.avi
  • s-how.name.S01E21.Some.Episode.avi
  • s-how.name.S01E21.avi
  • show name – [01×21].avi
  • show name – [1×21].avi
  • show name – [1×21].avi
  • show name – [01×021].avi
  • show name-[01×21].avi
  • show name [01×21].avi
  • show name [01×21] – the wrong ep name.avi
  • show name [01×21] the wrong ep name.avi
  • show.name.1×21.The_Wrong_ep_name.avi
  • 123 – [02×24].avi

If you come across a name format it cannot process (It will say “Invalid name the_file_name.ext”), you can add new regular expressions to parse it.

To do so, you must add another re.compile() statement to the config[‘name_parse’] array.

They must have 3 groups, showname, season number and episode number. Use (?: optional) non-capturing groups if you need others groups for any reason (For example, (?:something|else) would allow the group to be used for alternation, but not be the captured as showname/episode number etc)

It is recommended to add your new input filename to the names array in the UnitTest named “test_name_parser”. Then run tvnamer -t to check it is working correctly. Use the dummy show name “show name” and season 1, episode 21.

Last edited by dbr, 5 months ago
Versions: