Filename regex fails
On the kodi wiki there is a section on using regexes for custom TV show matching. I've followed the instructions there, creating a file %APPDATA%\Kodi\userdata\advancedsettings.xml with the contents of the second example:
<tvshowmatching action="prepend">
<regexp>Season[\._ ]([0-9]+)[\\/]([0-9]+)([^\\/]*)$</regexp>
</tvshowmatching>
then I created a file in my TV show directory: S:\TV\Battlestar Galactica (2003)\Season 3\01 - Occupation.avi and ran Kodi with debug-logging and scan-on-startup enabled.
My log says:
DEBUG: VideoInfoScanner: Could not enumerate file S:\TV\Battlestar Galactica (2003)\Season 3\01 - Occupation.avi
and the file does not get scanned.
(I reached this stage while attempting to debug my own regex, matching S:\TV\[Name]\S##\E## - [Name].mkv. I made it more and more similar to the example to find my own flaw, and as a sanity check finally ran the example - which failed!)
How can I correctly specify a regex for Kodi to follow while scanning?
Posted Dec 23, 2019, 9:43 PM UTC · edited
https://kodi.wiki/view/Naming_video_files/TV_shows#Season_Folder
Your flaw is that kodi is only using the regex on the filename, it ignores the folder. There is no way around this. You'll have to rename your file so it contains the season number, or switch the scraper to tvdb and use absolute order (I wouldn't do that).
I'd strongly suggest using one of the default numbering forms
https://kodi.wiki/view/Naming_video_files/TV_shows#Single_Episodes S01E01 is supported by everything and if you use a bulk renamer it can be completed fairly quickly.
That section of the wiki page seems to be talking about the built-in regexes, which do indeed only act on the file name. (Looking at them, they appear to be checking that there are no slashes between the number and the end of the filename.)
Later on the page, where I took my example from, it says
Is this information no longer correct?
EDIT: Looking at the source here this appears to still be correct. So either the regex I've provided isn't getting to the matcher, or it's incorrect in some way.
I'm wrong, you're right. For custom filenames it's the entire path being passed to regex. I'm going to have to dig out my regex hat and have a much closer look at this.
I've had a closer look and I'm certain I understand how the regex is working. The good news is what you've posted ought to be working. So... there's a mistake elsewhere.
Are you sure the advancedsettings.xml is being loaded (you can see the line in a debug log)?
If it is being loaded you'll need to post the contents of your advancedsettings.xml and your entire debug log.
If your path to be matched is
Then the regex should be
The
Has a negation carat within the square brackets so it matches any character except a forward or backward slash (i.e. a folder), which means the preceding E([0-9]+) can only occur at the start of the filename.
You're right, I'm an idiot.
I didn't wrap the file in
<advancedsettings> </advancedsettings>. Fixing this makes the example work, and probably the regex I need too. Thank you anyway!Your regex is almost identical to my original regex, too... *sigh*
I would second sticking with normal naming conventions for the filename. Not only will it make scraping easier for Kodi, it would make things easier for other apps that want to use more standard naming. I have Kodi setup for at home use but also have Plex setup to share media with family & friends and to be able to watch stuff from my phone. IMO it just makes things simpler and more organized.
one of the main reasons I'm not using plex at the moment is because they don't support custom file naming. I'm looking to use Kodi as a supplement to browsing my media directly in explorer, and I'm not willing to rename my files and make that experience less clean. If I can't get this regex sorted, I'll put together a script to populate Kodi's database directly.