Anime nerds, assemble!
#19
I've updated my regex filters for anime, cleaned them up, fixed some bugs, and am pretty happy with them. They're not simple, but they handle every naming scheme I've tested, whereas the above naive regex fails on several.

It captures season numbers when it's in a parent directory (including multiple levels up). It does not capture OP/ED entries as long as there's no spacing (EG: OP1, ED1; if entered as "OP 1" instead of "OP1", it will still be found as episode 1), but will capture stuff like SP1 or OVA1 (special episode 1, placed in season 0). It handles all sorts of variations in filename formatting, with or without CRC code anchors. It does not capture data from inside bracketed areas (resolution, 10-bit, etc). It avoids capturing numbers from the show name itself (eg: KoiKoi 7).

It still does not handle multi-episode naming (eg: Dokuro-chan 01-02), as I haven't been able to make any sense of how Kodi processes those.

It's rather complex (though it's now only 3 regexes each for CRC-anchored and non-anchored files), so I don't know if you want to include it in the wiki, but posting here for reference.

Complete version with comments explaining the design, and test file names to check against:

Code:
<advancedsettings>
    <tvshowmatching action="prepend">
        <!-- Regex info: -->
        <!-- First capturing match is assigned to the season.  Second capturing match is assigned to the episode. -->
        <!-- (?i) turns on case-insensitive matching -->
        <!-- (?:stuff) is a non-capturing group for 'stuff', so as not to interfere with season/episode numbers. -->

        <!-- Anime specific matching. -->
        
        <!--
        Building the regex from back to front:
        
        Closing checksum (optionally followed by random text, but we don't have to match that) contained in (), {} or [].
        Preceded by any number of bracketed items of any sort of content, with possible spacing, dashes or underscores in between
        Possibly preceded by unbracketed text. Make sure it doesn't find episode numbers inside brackets.
        Preceded by the episode number (optionally labelled), with possible version number
        Preceded by various combinations of dash, dot, underscore or space, to separate the title from the episode number
        Possibly preceded by a season number, or 'Special' or 'OVA'
        -->
        
        <!-- Regexes listed in order of match preference -->
        <!-- The regexes in the prepend set are anchored to checksums, so should be checked before normal Kodi defaults. -->
        
        <!-- For reference, this is the regex containing everything from the episode number onwards.  It will be the same for all regexes in this section. -->
        
        <!-- <regexp>(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?(?:[[({][\da-f]{8}[])}])</regexp> -->
        

        <!-- Anything with the filename marked as Special/OVA/OAV/etc goes to season 0, regardless of what the directory may say. -->
        
        <!-- EG: [SHiN-gx] Fight Ippatsu! Juuden-chan!! - Special 1 [DVD][720x480 AR h.264 FLAC][v2][FF09021F].mkv -->
        <!-- EG: [gleam] Kurenai OVA - 01 [OAD][0e73f000].mkv -->
        <!-- EG: [Jarzka] Saki Picture Drama 1 [480p 10bit DVD FLAC] [BA3CE364] -->
        <regexp>(?i)(Special|SP|OVA|OAV|Picture Drama)(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?(?:[[({][\da-f]{8}[])}])</regexp>

        <!-- Then check if we have an explicit season directory. -->
        
        <!-- Inside a directory that specifies the season.  May include any number of subdirectories.  Doesn't try to find season markers in the file name. -->
        <!-- EG: Saki/Season 1/Saki [Jarzka]/[Jarzka] Saki 01 - Encounter [480p 10bit DVD FLAC] [9EED32CB] -->
        <!-- EG: Saki/Season 3/[Underwater-FFF] Saki Zenkoku-hen - The Nationals - 01 (720p) [AF65724D] -->

        <regexp>(?i)[\\/](?:S(?:eason)?\s*(?=\d))?(Specials|\d{1,3})[\\/](?:[^\\/]+[\\/])*[^\\/]+(?:\b|_)(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?(?:[[({][\da-f]{8}[])}])</regexp>
        
        <!-- Include season marker in the filename. -->
        <!-- EG: [CoalGuys] K-ON!! S2 - 05 [4B19B10F] -->
        
        <regexp>(?i)[-._ ]+S(?:eason ?)?(\d{1,3})(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?(?:[[({][\da-f]{8}[])}])</regexp>


        <!-- Anything else gets the default blank first capture, which sets the file to season 1. -->
        
        <!-- EG: [avatar-nyanko] Koikoi 7 - 01 (DVD) [5E95FA4A] -->
        <!-- EG: [gg]_Chuunibyou_Demo_Koi_ga_Shitai!_-_01_[5B6EFD1F] -->
        <!-- EG: [Eclipse] Akane-iro ni Somaru Saka - 01 (1024x576 h264) [39920E63].mkv -->
        <!-- EG: [gg]_Bakemonogatari_-_01_[CC0CF5D2].mkv -->
        <!-- EG: [Doki]_Asobi_ni_Iku_yo!_-_03v2_(1280x720_h264_AAC)_[B5B9C6F3].mkv -->
        <!-- EG: [Coalgirls]_Yuru_Yuri_02_(1280x720_Blu-Ray_FLAC)_[43E5A6B4] -->
        <!-- EG: Touch 01(DVD) - (112ceb61) Central Anime  -->
        <!-- EG: Cross Game 02 - Central Anime (1280x720) [BF23052D].mp4 -->
        <!-- EG: [Taka]_Naruto_Shippuuden_135_[480p][9073B8C2] -->

        <regexp>(?i)((?=\b|_))(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?(?:[[({][\da-f]{8}[])}])</regexp>
        
        <!-- Multipart episode handling is still uncertain. (?:-(\d{1,3}))? -->
        <!-- EG: [Triad]_Dokuro-chan_-_01-02 [12345678].mkv -->

    </tvshowmatching>
    
    <tvshowmatching action="append">
        <!-- Alternate version that does not include checksums. Put this after normal XBMC patterns. -->
        <!-- Since it doesn't use the checksum anchor, need to make sure it's not a directory name. -->

        <!-- For reference, this is the regex containing everything from the episode number onwards.  It will be the same for all regexes in this section. -->
        
        <!-- <regexp>(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?[^][)(}{\\/]*$</regexp> -->


        <!-- Anything with the filename marked as Special/OVA/OAV/etc goes to season 0, regardless of what the directory may say. -->

        <regexp>(?i)(Special|SP|OVA|OAV|Picture Drama)(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?[^][)(}{\\/]*$</regexp>

        <!-- Inside a directory that specifies the season. -->
        <!-- EG: Saki/Season 2/[HorribleSubs] Saki Episode of Side A - 14 [720p] -->

        <regexp>(?i)[\\/](?:S(?:eason)?\s*(?=\d))?(Specials|\d{1,3})[\\/](?:[^\\/]+[\\/])*[^\\/]+(?:\b|_)[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?(?:\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?[^][)(}{\\/]*?$</regexp>

        <!-- Include season marker in the filename. -->
        <!-- EG: [DeadFish] Toaru Kagaku no Railgun S - S2 - 01 [720p][AAC].mp4 -->
      
        <regexp>(?i)[-._ ]+S(?:eason ?)?(\d{1,3})(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?[^][)(}{\\/]*$</regexp>

        
        <!-- EG: [a.f.k.] Lucky Star - 01.avi -->
        <!-- EG: Air Master - 04 [HQA&N!].avi -->
        <!-- EG: [ANE] Yosuga no Sora - Ep01v2 [BDRip 1080p x264 FLAC] -->
        <!-- EG: [DeadFish] Jinrui wa Suitai Shimashita - Special 01 [BD][720p][AAC].mp4 -->

        <regexp>(?i)((?=\b|_))(?:[ _.-]*(?:ep?[ .]?)?(\d{1,3})(?:[_ ]?v\d+)?)+(?=\b|_)[^])}]*?(?:[[({][^])}]+[])}][ _.-]*)*?[^][)(}{\\/]*$</regexp>

    </tvshowmatching>
</advancedsettings>

Edit: Fixed some issues in the regexes.
Reply


Messages In This Thread
Anime nerds, assemble! - by Ned Scott - 2013-08-07, 00:46
RE: Anime nerds, assemble! - by magao - 2013-08-07, 01:54
RE: Anime nerds, assemble! - by Ned Scott - 2013-08-07, 02:46
RE: Anime nerds, assemble! - by magao - 2013-08-07, 06:33
RE: Anime nerds, assemble! - by magao - 2013-08-08, 08:31
RE: Anime nerds, assemble! - by magao - 2013-08-18, 02:48
RE: Anime nerds, assemble! - by magao - 2013-08-31, 19:33
RE: Anime nerds, assemble! - by Ned Scott - 2013-09-01, 00:14
RE: Anime nerds, assemble! - by ronie - 2013-09-01, 00:28
RE: Anime nerds, assemble! - by Ned Scott - 2013-09-01, 00:48
RE: Anime nerds, assemble! - by magao - 2013-09-01, 02:26
RE: Anime nerds, assemble! - by Ned Scott - 2013-09-01, 04:41
RE: Anime nerds, assemble! - by Martijn - 2013-09-01, 11:36
RE: Anime nerds, assemble! - by borgmanjayce - 2014-06-14, 16:00
RE: Anime nerds, assemble! - by Ned Scott - 2014-06-15, 00:12
RE: Anime nerds, assemble! - by Ned Scott - 2014-07-21, 03:32
RE: Anime nerds, assemble! - by vrinek - 2014-10-26, 23:30
RE: Anime nerds, assemble! - by Ned Scott - 2014-10-26, 23:34
RE: Anime nerds, assemble! - by Kinematics - 2014-12-31, 06:46
RE: Anime nerds, assemble! - by Ned Scott - 2014-12-31, 12:12
RE: Anime nerds, assemble! - by Kinematics - 2014-12-31, 19:58
RE: Anime nerds, assemble! - by Kinematics - 2014-12-31, 23:11
RE: Anime nerds, assemble! - by anoth - 2015-01-11, 04:22
RE: Anime nerds, assemble! - by Ned Scott - 2015-01-11, 06:14
RE: Anime nerds, assemble! - by anoth - 2015-01-11, 22:58
RE: Anime nerds, assemble! - by Ned Scott - 2015-01-12, 02:24
RE: Anime nerds, assemble! - by anoth - 2015-01-21, 13:39
RE: Anime nerds, assemble! - by Uthred - 2015-01-22, 22:05
RE: Anime nerds, assemble! - by DJ_Izumi - 2015-01-22, 22:15
RE: Anime nerds, assemble! - by isamu.dragon - 2015-01-24, 07:35
RE: Anime nerds, assemble! - by giom - 2015-02-15, 19:52
RE: Anime nerds, assemble! - by eddman - 2015-02-15, 21:27
RE: Anime nerds, assemble! - by ilGimmy - 2016-03-13, 17:49
RE: Anime nerds, assemble! - by chibichiii - 2018-02-12, 11:32
RE: Anime nerds, assemble! - by Karellen - 2018-02-12, 11:43
Logout Mark Read Team Forum Stats Members Help
Anime nerds, assemble!1