Kodi Community Forum

Full Version: File Stacking Regular Expressions - Change Default
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I do apologize in advance if there is a better place to post this, or if there is a similar thread for it which I was unable to locate.

This page (and this) detail how XBMC stacks files using regular expressions, e.g. movie-title-part1.mpg movie-title-part2.mpg becomes a single 'movie-title' in the XBMC interface when stacking is enabled.

Here's an example of the regular expression as it is documented (and I do not know if this documentation is up-to-date for v11):
Quote:<regexp>(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck]|d)[ _.-]*[0-9]+)(.*?)(\.[^.]+)$</regexp>

This expression (and the letter variant) does not handle file names which provide the stacking portion inside parenthesis such as this: Fight Club (1999) [Part 1].avi

Here's an example of an updated RegEx to handle all 3 types of parentheses, although personally I only wish to add ][ bracket matching.
Quote:<regexp>(.*?)([ _.-]*(?:[\(\[\{])?(?:cd|dvd|p(?:ar)?t|dis[ck]|d)[ _.-]*[0-9]+(?:[\)\]\}])?)(.*?)(\.[^.]+)$</regexp>

The change is relatively simple and I do not believe it will allow for any additional false-positives, since the parentheses delimit the 'field' nicely. I have been using this updated expression in my advancedsettings.xml file for a while now and it works well, so I was hoping it could be included in XBMC as the default so I don't have to keep sending people a subset of my xml file.
The example above stacks fine, just the parantheses stay appended, right? Once scanned, it wouldn't be a problem.
(2012-03-27, 07:15)jmarshall Wrote: [ -> ]The example above stacks fine, just the parentheses stay appended, right? Once scanned, it wouldn't be a problem.
I can test again to be sure, but I recall the problem being that the resulting scanned name wouldn't scrap correctly without manual intervention (which also happens for other reasons, which I am investigating now that v11 has renewed my interest in customizing or enhancing XBMC). I remember not all of my files stacking correctly too, but thinking about the RegEx now I am not confident why I am remembering this. Perhaps I will try a full rescan late tonight without my customizations and see what happens, perhaps it was a bug in an old version of XBMC.

As a small aside, is there a reason these RegEx don't use named captures or other RegExOptions to make them easier to read? I am not familiar with the XBMC dev stack but I assume all modern RegEx implementations provide these options.
Historical mainly. Our first regexp stuff didn't handle named expressions. Pretty sure the current one does, so certainly that would be an option - feel free to take a look.

Also, to be clear, I'm not averse at all to changing the default regexps - the better they are, er, the better. However, I will not accept a change without someone also making at least a token effort to generate test cases so we can be reasonably sure we don't have regressions when we go and change it again. This would be, for example, a list of filenames pairs in a text file (unstacked/stacked) along with a simple routine to run the test.

Cheers,
Jonathan
I've read the stacking stuff but truthfully do not understand it at all. I created an advancesettings.xml but it does not seem to cover files renamed by a program I use called YAMMM. Here is an example of what I'm trying to get stacked:

Wedding Crashers (2005) [1 of 2].avi
Wedding Crashers (2005) [2 of 2].avi

Anyone have any ideas?