Venturing Forth

# Specialist Filebot naming scheme for the best experience with Kodi

I eventually succeeded setting up Filebot to have almost zero errors when importing my video library into Kodi Leia.

Recently, Filebot has added a conventional naming scheme, called {kodi} to simplify as much as possible the process of importing files into Kodi and have it digest and classify them correctly. Recently, Filbot passed also to the dark side of commercial non free software but still remains in my opinion the best tool to get this kind of job done. The license I bought is just for this reason. I have no commercial affiliation with Filebot nor with any of its owners and this article is simply thought to help somebody spending a lot of time modifying scripts scattered all around the web.

Anyway, the {kodi} schema is not error free, there will always be movies that Internet Databases hardly digest and classify correctly, especially when the primary language of your media differs from the original movie language.

I surfed the internet a lot, Filebot and Kodi forums are full of good ideas on how to make the marriage of the two as simple as possible, but none has really given me the ultimate solution, so I spent some time on this topic to find the best fit for my case.

My requests were quite simple:

1) having a naming convention that Kodi can read easily;

2) as far as my collection exceeds the 8 Tb and I don’t use only Kodi in my house but I need to get my library prepared also to PCs and humans as well as to dlna enabled devices;

3) I want a catalogue that can survive the life expectancy of both Kodi and Filebot, i.e. the format of my movie library on the filesystem shall ship with as much metatada as feasible directly embedded into filenames.

If you are going to test my script, you will end up saying that it too baroque and complain for the excessive length of directories and filenames. You may be right, actually you can use it almost only in Linux as Windows file explorer does not allow to navigate paths longer than 255 characters (ATTENTION: Windows actually allows you, it is the standard File Explorer that is limited to 255 characters!). I know, but somehow there is a price for everything in life. My preamble included the assumption that you have a really huge databank and such a bulky archive will never reside on a normal PC. It will just find sufficient room into a NAS with no less than  4-bays. So that’s gonna be for sure a Linux box. Problem solved.

So this is the snippet. The explanation of each item follows just after the code.

/path/to/where/you/want/your/files/stored/
{az}/
{
norm =  {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " -  ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th| nd|rd)\b/, { it.lower() })}; norm(n)
}
({y})
{" ["+tmdbid+"]"}
{" ["+imdbid+"]"}/{
norm =  {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " -  ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th| nd|rd)\b/, { it.lower() })}; norm(n)
}
{
if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'
}
{
" ["+file.path.lower().replace(/dc/, 'director\'s cut').replaceAll('limited','limited release').replaceAll('directors','director\'s').replaceAll('-','').replaceAll(/director.s|theatrical/,'$0 Cut').matchAll(/(uncensored|uncut|unrated|remastered|ultimate|extended|director?s|theatrical|ultimate|final|bootleg|special|fan?edit?|limited|rifftrax|monstervision|youtube|hulu|netflix|vimeo|edited|edit|censored+)(?:.edition|.cut|.version|.edit|.release|.extended|.rip)?/)*.upperInitial()*.lowerTrail().sort().join('] [')+']' } { def map=['3d':'3D','hsbs':'Half-SBS','halfsbs':'Half-SBS','fsbs':'Full-SBS','fullsbs':'Full-SBS','sbs':'SBS','halfou':'Half-OU','fullou':'Full-OU','overunder':'OU','anaglyth':'Anaglyth']; " ("+ ((file.path.lower().contains(/3d/)) ? '' : '3D ')+ file.path.lower().replaceAll(/(?i)(?<=^|[^a-z])hou(?=$|[^a-z])/,'halfou').replaceAll(/(?i)(?<=^|[^a-z])fou(?=$|[^a-z])/,'fullou').replaceAll(/(?i)(?<=^|[^a-z])ou(?=$|[^a-z])/,'overunder').replaceAll(/[\W]/, "").matchAll(/3d(?!.*?3d)|hsbs(?!.*?hsbs)|halfsbs(?!.*?halfsbs)|fsbs(?!.*?fsbs)|fullsbs(?!.*?fullsbs)|sbs(?!.*?sbs)|halfou(?!.*?halfou)|fullou(?!.*?fullou)|overunder(?!.*?overunder)|anaglyth(?!.*?anaglyth)/).findResults{ map[it]}.sort().join(' ')+')'
}
{
any{" ("+d.format("yyyy")+")"}{y}
}
{" ["+rating+"★]"}
{" ["+tmdbid+"]"}
{
" [$vf -$vc] [\$ac "+af.replace('8ch', '7.1ch').replace('7ch', '6.1ch').replace('6ch', '5.1ch').replace('3ch', '2.1ch').replace('2ch','2.0ch')+"]"
}
{
" ("+actors.take(3).join(', ')+")"
}
{
any
{
" ("+omdb.genres.take(3).join(', ')+")"
}
{
" ("+genres.take(3).join(', ')+")"
}
}
{' (Part '+pi+')'}
{subt}


Now, let’s see some details on the implementation. You will likely see each piece of my snippet on a lot of other posts around the internet as all of its parts are really standard items used by a lot of people. However, reordering counts, somehow.

• First line is just the path where you want your newly renamed files to be stored. As you can see in my case it is a standard Linux absolute path but you can easily convert it into a Windows version like C:\path\to\Gates’s\house\video and the like.
• /{az}/ adds an additional sub-directory level (of just one character only) to separate the entire set of movies into max 27 directories:0-9, A, B…Z. This comes handy when you are on a TV scrolling movies on a samba share. If you have thousands of movies and you know the title you want, better you create some shortcuts to reach it. That’s the only reason why I added it. Feel free to remove it if you will never encounter such a use case.
• Then there is a normalization function to remove some odd characters and punctuation symbols that may corrupt file names. Exclamation marks will remain. The normalization function puts the multi word titles to camel case. This function is used to format the movie directory name using the movie in the primary language of the media being stored. Here an example

Getaway! (1972) [5916] [tt0068638]

• Getaway! Is the Italian name of the movie “The Getaway”. (as the primary language of the file is ITA)
• (1972) is the release year
• [5916] is the movie database number that refers to this movie
• [tt0068638] is the same record as above, using IMDB instead

That directory will contain the real media in the format you have choosen in the following format:

Getaway! (The Getaway) (1972) [7.1★] [5916] [360p – DivX] [MP3 1ch] (Steve McQueen, Ali MacGraw, Ben Johnson) (Action, Crime, Thriller) (Part 1)

Getaway! Is still your localized movie name

• (The Getaway) is the original movie name
• (1972) is the year of the movie
• [7.1★] is the rating given my IMDB
• [5916] is again TMDB movie record number
• [360p – DivX] This is the video format of the file
• [MP3 1ch] this is the main data related to the audio format of the file. If the media contains also language information (multi channel audio tracks) they will be shown as well.
• (Steve McQueen, Ali MacGraw, Ben Johnson) is a subset composed of the firtst three Actors appearing on TMDB
• (Action, Crime, Thriller) This is the movie genre and category
• (Part 1) if the entire movie is split into more than one file, this optional final tag will be added to correctly sequence the series. It will not appear if the file is one only.

I encountered no more than half a dozen cases where this schema brought to excessive length in pathnames.

For such a cases I removed some less useless parts of the schema, respectively, in order of least importance:

• the section related to genres,
• the IMDB tag in the directory name,
• the rating,
• audio tags,
• the section related to actors.

Depending on how you generally access your archive, having the main actors in the filenames can be handy sometime. Having the double language name on the file is also important if you are not English native.

Try it and tell me if it will be as good as it has been for me. I will be glad to hear from you.

Auf wiederloege

Alex