Naming video files/TV shows

From Official Kodi Wiki
< Naming video files
Revision as of 16:28, 7 December 2015 by Slchorne (talk | contribs) (remove circular content links)
Jump to: navigation, search
Home icon grey.png   ▶ Video library ▶ Management ▶ Naming video files ▶ TV shows

Kodi requires each TV show to be in its own folder, and for each file to contain a pattern from which Kodi can determine the season and episode number (e.g. "S01E01").

Folder name = Show title
File name = Season/Episode number

The folder name will be cleaned of commonly used strings, such as DVDRip, 1080p, x264, etc. before being passed to the scraper. If the year of release is included, this will be extracted and used by the scraper to assist in making a match.

Spaces, periods, or underscores may be used to separate words in the folder and file names, but shouldn't be mixed in the same folder name. Note also the caution below regarding file names with periods.

Note: Flat structures with files for different shows in a single directory are not supported.

1 Directories

You must set the content to TV Shows on the directory directly above the individual show folders. To ensure accurate matches for your TV shows, the folder names should match the title displayed on the site being scraped. For the default TVDB scraper this may mean including the year of release, e.g. Castle (2009) (in cases of duplicate titles), or the country of origin, e.g. Being Human (US) (in cases of foreign remakes).

Below the show folder, the files may be organized how you wish, e.g. into separate season folders, or by year. These folders will be ignored.

1.1 Simple

Typically, you will add the top-level directory as a source and set the content to TV shows when you add it.

TV Shows                  <<Source folder, Content: TV shows>>
   |----TV Show 1
   |       |----Season #
   |            |--Files
   |----TV Show 2 (year)
   |       |--Files
   |----TV Show 3
   |       |----2008
   |            |--Files

1.2 Complex

Note: This is generally discouraged as it's really easy for the sub-folders to be mistakenly picked up as false TV show matches. While it's still possible to work through such false-matches, it's a pain in the butt if you need to update the library on those same folders, as the false TV show might get re-added each time.

In more complex situations where your top-level directory is further sub-divided before the show folders, you can add the top-level as source but not set the content, and then set the content to TV shows on each sub-folder.

TV Shows                  <<Source folder, Content: None>>
   |----A-M               <<Content: TV shows>>
   |      |----TV Show 1
   |              |--Files
   |----N-Z               <<Content: TV shows>>
   |      |----TV Show 2
   |              |--Files

It's also possible to have a sub-folder group multiple shows together in an otherwise normal directory structure. Just change the content on the sub-folder and de-select the "Selected folder contains a single TV show" setting.

TV Shows                  <<Source folder, Content: TV shows>>
   |----TV Show 1
   |       |----Season #
   |            |--Files
   |----Star Trek Series  <<Content:TV shows>>
   |       |----Star Trek
   |       |       |--Files
   |       |----Star Trek The Next Generation
   |               |--Files

In these cases, it's best to refrain from scanning the files into the library until the content is set correctly for all folders, to avoid incorrect results and the need to rescan.

2 Files

Kodi uses a series of regular expressions to determine the season and episode numbers from the file name. These are checked in order with the first match being the one used. Anything else included in the file name is ignored.

There are 7 default patterns, plus a separate multi-episode pattern. Use of any other numbering scheme will require you to edit your advancedsettings.xml (see below).

Note: In the examples we will mostly use the format:


where name is the title of the show, and .ext is a recognized video file extension, but any format will work, so long as the pattern is included somewhere in it. name is optional and could just as easily be after the pattern, or excluded entirely.

2.1 Single episode

Most of the time you will only have a single episode per file.

The order in which the patterns are checked for by Kodi is included in brackets after each example below (most patterns allow some variation, hence the duplicate numbers). If your file name contains more than one pattern, only the first one checked for will be used.

All the examples will be read as season 1, episode 2.

With season
The most common scenario.
anything_s01e02.ext (1)
anything_s1e2.ext (1)
anything_s01.e02.ext (1)
anything_s01_e02.ext (1)
anything_1x02.ext (5)
anything_102.ext (6)
Without season
In cases where you only have one season (or are using absolute order in the TVDB scraper), you may want to forego the inclusion of the season number.
anything_ep02.ext (2)
anything_ep_02.ext (2)
You may also use Roman numerals (I, IV, XI, etc.), often used for mini-series or short documentary series.
anything_part.II.ext (7)
anything_pt.II.ext (7)
anything_pt_II.ext (7)
By date
Common for long-running daily shows, you can also use the date the episode aired.
anything_1996.11.14.ext (3)
anything_1996-11-14.ext (3)
anything_14.11.1996.ext (4)

2.2 Multi-episode

Note: When you use a single video file for multiple episodes you can now tell Kodi when each episode starts using episode bookmarks. In cases where your file contains more than one episode, you can specify all the episodes included. Everything after the first found pattern match will be checked for further matches to the same pattern.

anything.s01e01 1x02.ext (mixed patterns do not work)

The remainder will also be checked against a shorter form multi-episode pattern.


The ex-_ are fully interchangeable and stackable, e.g. name.1x01e02_03-x-04.ext is perfectly valid (if somewhat odd).

Note: Only the episodes in the file name will be added, e.g. name.s01e01-03.ext will not include episode 2.

2.3 Split-episode

Typical for childrens cartoons, files which only contain a distinct part of an episode may be named as to which part, if the scraper supports it.


Up to 9 sub-parts are allowed (using either .1-.9 or a-i).

These can also be combined with the multi-episode pattern, if your file contains all parts joined as a single episode.

anything.1x01.1x01.2.ext (note this is (1x01.1)x(01.2) not (1x01).(1x01.2))

Each part will be added to the library just with its full episode number, the sub-part will not be displayed.

Note: If you use periods in your file names and include material after the episode number (such as the episode title), you may get a false match to a split-episode pattern if that material begins with a number below 10, e.g.

anything.1x01.1x02.ext (i.e. (1x01.1) x (02) )

This will likely lead to the episode not being added to the library. The recommendation is to use a space or underscore instead to separate the numbers for those files, e.g.

anything.1x01 1x02.ext (i.e. (1x01) (1x02) )

2.4 Special episodes

Special episodes, if supported by your scraper, should be marked as being season 0. You should check the site being scraped to see what episode number to use, as they can be fairly arbitrary. For example, BlackAdder's Christmas Carol should have a file name that matches season 0 episode 3, e.g.:

BlackAdder.s00e03.BlackAdder's Christmas Carol.mkv

3 The TVDB scraper

The default TV show scraper uses The TVDB to scan your TV shows into the library. You should search on the site before adding a new show to ensure you're using the right title. Caution should be taken over using aliases or alternative titles, although these will work in a website search, they don't work in the API the scraper uses.

The TVDB scraper has three possible settings for determining episode order: Aired order, DVD order, and Absolute order. These will affect how you name your files, or vice versa, how you name your files will affect which setting you should use.

Aired order
The default, episodes are ordered by season and numbered as they were originally broadcast. For split-episodes, each part is given its own distinct episode number.
Visible when you click on any season link on the show page.
DVD order
Episodes are ordered by season and numbered as they appeared on DVD release. Split-episodes are numbered by episode and sub-part.
Visible when you click the "DVD Order" link on any season page for the show.
Absolute order
Episodes are ordered as a single season and numbered sequentially from start to finish. Split episodes have distinct episode numbers. Commonly used for anime.
Visible when you click the "Absolute Order" link on the All seasons page for the show.

4 Media source tags

Depending on the interface skin you are using, you can add additional media source information to a movie entry in Kodi. For example, in the default skin "Confluence" you can label when a file was ripped from a bluray disc by including BLURAY, BRRIP, BD25, or BD50 in the file name after the title. The exact options are different for each interface skin, but a list for the default Confluence skin can be seen on Media flags#Media source.

Back to the Future (1985).bluray.mkv

5 Advanced usage

5.1 3D episodes

Some 3D episodes might need an additional file name extension to be identified by Kodi as a 3D movie. See 3D for details on that additional extension, and when it is needed.

5.2 Supplemental tools

A variety of supplemental tools exist to automatically rename files and folders into Kodi compatible formats.

5.3 Changing scraper settings for one show

A very common situation, when you have one or more shows that require different scraper settings (particularly episode order) to the other shows in your folder, it is possible to change the settings for individual shows. Just navigate to the show's folder in file view and select Change content from the context menu and then alter the settings from there. If the files have already been incorrectly added to the library, you will need to refresh the folder (e.g. from the info screen).

The classic example is Firefly, whose aired order differs greatly from its DVD order:

TV Shows                         <<Source folder, Content: TV shows, Scraper: TVDB - default settings>>
   |----TV Show 1
   |       |----Season 1
   |            |--Files
   |----TV Show 2
   |       |--Files
   |----Firefly                  <<Scraper: TVDB - DVD order>>
   |       |----1x01.Serenity.ext
   |       |----1x02.The Train Job.ext

5.4 Using custom file names

It's possible to use custom file names that don't match any of the default patterns by editing your advancedsettings.xml file to include a tvshowmatching tag containing regular expressions.

A tvshowmatching regexp needs up to three capturing groups:

1 capturing group = episode number (season will default to season 1), no multi-episode matches will be attempted
2 capturing groups = season number + episode number (in that order), no multi-episode matches will be attempted
3 capturing groups = season number + episode number + multi-episode matching part (typically just the remainder of the file name)

(A capturing group is essentially a part of the regexp contained inside brackets.)

To have no season but multi-episode matching, use three groups but leave the first empty.

Date-based regexps are also possible, and are marked by a bydate="true" attribute in the regexp. These also use three capturing groups, either as year-month-day or day-month-year, the lengths must be exactly 4-2-2 or 2-2-4.

Your custom tvshowmatching regexps can be either checked for before the default set (action="prepend") or after (action="append"). Not including an action will result in only your regexps being tested. Care should be taken to ensure that the right regexp matches your file names, particularly in regard to the three digit "102" pattern seen above. The regexps should be grouped together inside a single tvshowmatching tag, although you can use two if you wish to prepend and append different regexps.

You can also change the multi-episode matching regexp by including a tvmultipartmatching tag in your advancedsettings.xml (separate from the tvshowmatching tag). There can be only one tvmultipartmatching expression, whatever you use will overwrite the default, so take care to only expand on the default pattern unless you are certain. The tvmultipartmatching requires one capturing group for the episode number.

Note: For simplicity, the split-episode pattern has been excluded from the examples below. To allow for split-episodes, replace the [0-9]+ in the episode capturing group with [0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?

5.4.1 Examples

A fairly straightforward example to begin.

Season ## - Episode ##
"Season [season#] - Episode [episode#]" anywhere in the file name
 <tvshowmatching action="prepend">
   <regexp>Season ([0-9]+) - Episode ([0-9]+)([^\\/]*)$</regexp>
Example : TV Shows\Scrubs\Season 1\Scrubs - Season 1 - Episode 01 - Pilot.avi
The first two capturing groups should be obvious, the third group ([^\\/]*) captures everything up to the end of the file name $, this allows for multi-part file names such as name.Season 1 - Episode 01 - Season 1 - Episode 02.ext as well as the simpler name.Season 1 - Episode 01-02.ext

The entire file path is passed to the regexps, so care should be taken to ensure the matches can't occur earlier in the path, but this does mean for example, you can capture the season number from a sub-folder name.

\Season #\##
Season [season#] at the end of the directory name, file name starts with [episode#]
 <tvshowmatching action="prepend">
     <regexp>Season[\._ ]([0-9]+)[\\/]([0-9]+)([^\\/]*)$</regexp>
Example : \Battlestar Galactica (2003)\Season 3\01 - Occupation.avi (Season 3, Episode 1)
Again we use three groups here to allow for multi-episode, but in this case (obviously) only the shorter multi-episode pattern can occur, e.g. Season 1\01x02 - Episode title.ext.

For numbering without a season, you should ensure that only the episode number gets matched against and not another number in the title or episode title, or a number as part of a different pattern.

- ## -
" - [episode#] - " anywhere in the file name
 <tvshowmatching action="prepend">
     <regexp> - ()([0-9]+)((?:-[0-9]+)*) - [^\\/]*$</regexp>
Example : \One Piece\One Piece - 099 - Spirit of the Fakes! Heart of the Rebel Army, Kamyu!.avi ("Season 1", Episode 99) (Using Absolute order)
Here, the first capturing group is left empty, and there is a distinct pattern before and after the episode number to ensure only it gets matched. Also instead of capturing the remainder of the file name for multi-part matching, we only capturing a single repeating pattern so only a - 01-02-03 - format will work.

It's also possible to specify a different default season for without-season regexps.

Directory name is Specials, file name starts with [episode#]
 <tvshowmatching action="prepend">
     <regexp defaultseason="0">Specials[\\/]()([0-9]+)([^\\/]*)$</regexp>
Example : \Firefly\Specials\04 - Browncoats Unite.mkv (Season 0, Episode 4)
A combination of the previous two examples, allowing special episodes to reside in a "Specials" folder rather than a "Season 0" folder.

The default date-based regexps only allow for periods or hyphens as delimiters...

[year]_[month]_[day] anywhere in the file name
 <tvshowmatching action="prepend">
     <regexp bydate="true">([0-9]{4})_([0-9]{2})_([0-9]{2})[^\\/]*$</regexp>
Example: : \The Colbert Report\2005_10_17.avi
The exact number of digits is specified for each group to ensure compliance. A separate [month]_[day]_[year] regexp would be needed if both formats are in use.

The default regexps don't allow for DVD folder structures, this can usually be remedied by replacing the final $ with (?:(?:[\\/]video_ts)?[\\/]video_ts\.ifo)$

 <tvshowmatching action="append">
     <regexp>[Ss]([0-9]+)[ ._-]*[Ee]([0-9]+)([^\\/]*)(?:(?:[\\/]VIDEO_TS)?[\\/]VIDEO_TS\.IFO)$</regexp>
Example: \Battlestar Galactica (2003)\The Mini-Series S00E01E02\VIDEO_TS\VIDEO_TS.IFO
The VIDEO_TS folder is optional, e.g. S01E01\VIDEO_TS.IFO will also work.

Similarly for Bluray folder structures, you can replace the final $ with (?:(?:[\\/]bdmv)?[\\/]index\.bdmv)$

 <tvshowmatching action="append">
     <regexp>[\\/\._ \[\(-]([0-9]+)x([0-9]+)([^\\/]*)(?:(?:[\\/]bdmv)?[\\/]index\.bdmv)$</regexp>
With Bluray folders, you'll also run into trouble with the various mpls and m2ts files incorrectly matching other patterns, so you should also exclude all the other folders and files from being scanned:
    <excludetvshowsfromscan action="append">

Finally, a tvmultipartmatching example.

Multiple episode numbers, separated by a + sign
Example: : \Lost\Lost.S01E23+24.Exodus.mkv
In this case we can simply add the + sign to the default symbols, thus preserving the defaults as well.

6 All advanced settings related to TV show/episode names

7 Troubleshooting