Extra REGEX for TV Show Episode matching

  Thread Rating:
  • 19 Vote(s) - 4.11 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Kinematics Offline
Junior Member
Posts: 41
Joined: Feb 2013
Reputation: 3
Post: #361
Been a while since I checked in on this. Just did the update to version 17.

Noticed that @crazygambit put up a new set of regexes and wanted to check how his worked, since mine were having some issues during the update. Unfortunately, I found that it failed almost immediately. For example:

Anime/[SHiN-gx] Fight Ippatsu! Juuden-chan!! - Special 1 [720x480 AR h.264 FLAC][v2][FF09021F].mkv

will get matched as episode 264. The problem is that it searches for the last number in the filename, but doesn't exclude areas that are bracketed, and likely to have meta-info instead.

On the other hand, I've also found that my own regexes can work without needing two separate sets — one for those with checksum tags, and one for those without. Making it an optional match seems to work just fine, as far as I can tell. I also pulled a little from crazygambit's regex to better ensure that the last number is used. (EG: "KoiKoi 7 - 01" should be episode 1, not episode 7) I also made use of the defaultseason attribute for the regex for "season 0" specials and such.

Here's the new version. It's huge because I put in tons of comments to explain what's being done, and why.

<tvshowmatching action="prepend">
        <!-- Regex info: -->
        <!-- (?i) turns on case-insensitive matching -->
        <!-- If there is only one capture group, kodi will assume that it refers to the episode number, and use the default season. -->

        <!-- Capture group 1: The season.  Season 0 for specials/OVAs/etc. -->
        <!-- Capture group 2: The episode number. -->
        <!-- Capture group 3: The 'part' for a multi-part episode.  EG: Episode 01.1, Episode 01.2, where episode 1 is in two parts. May use numbers 1-9, or letters a-i. -->

        <!-- (?:stuff) is a non-capturing group for 'stuff', so as not to interfere with the above capture groups. -->

        <!-- Anime specific matching. -->
        Building the regex conceptually 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. -->
        <!-- Check for explicit S01E01 values -->
        The regex components.
        (?i) -- Always case-insensitive
        (?:\bS(?:eason ?)?(\d{1,3})[\s_.-]*)?
          -- Season number identification.
        (?:(?:\b|_)(?:ep?[ .]?)?(\d{1,3})(-\d{1,3})?(?:[_ ]?v\d)?[\s_.-]+)
          -- An episode number (captured) (and possible number range), with optional version. Requires word break beforehand.
          -- Negative lookahead, so that the matched episode number is the last number in the name prior to any bracketed content.
          -- Any number of unbracketed words with separators.
          -- Any number of bracketed data, such as (DVD), [720p], {FLAC}, etc, with 0 or more spaces or underscores in between.  Brackets have to match.
          -- Closing checksum.
          -- Make sure this is not part of a directory.
        (Special|SP|OVA|OAV|Picture Drama)[\s_.-]*
          -- For season 0 instances.
        (?:(?:\b|_)(?:[ .]?)?(\d{1,3})(-\d{1,3})?(?:[_ ]?v\d)?[\s_.-]+)
          -- Episode number for season 0 instances.
        Seasons defined in the directory path:
        S(?:eason ?)?(\d{1,3})[\\/](?:[^\\/]+[\\/])+.+?

        <!-- Anything with the filename marked as Special/OVA/OAV/etc goes to season 0, regardless of what the directory may say. -->
        <!-- Examples:
            [SHiN-gx] Fight Ippatsu! Juuden-chan!! - Special 1 [720x480 AR h.264 FLAC][v2][FF09021F].mkv
            [gleam] Kurenai OVA - 01 [OAD][0e73f000].mkv
            [Jarzka] Saki Picture Drama 1 [480p 10bit DVD FLAC] [BA3CE364].mp4
            [MaverickSubs] Third Aerial Girls Squad - OVA 2 (Shirobako Vol.7 OVA) [1080p].mkv
            [MaverickSubs] Third Aerial Girls Squad - 02 - OVA (Shirobako Vol.7 OVA) [1080p].mkv
        <regexp defaultseason="0">(?i)(?:Special|SP|OVA|OAV|Picture Drama)(?:(?:\b|[\s_.-]*)(\d{1,3})(?:[_ ]?v\d)?[\s_.-]+)(?![^([{]*\b\d{1,3}(?:[_\s]?v\d+)?\b)(?:\w+[\s_.-]*)*?(?:(?:\[[^]]+\]|\([^)]+\)|\{[^}]+\})(?:[\s_]*))*(?:[[({][\da-f]{8}[])}])?(?:[^\\/]*$)</regexp>

        <regexp defaultseason="0">(?i)(?:(?:\b|[\s_.-]*)(\d{1,3})(?:[_ ]?v\d)?[\s_.-]+)(?:Special|SP|OVA|OAV|Picture Drama)(?![^([{]*\b\d{1,3}(?:[_\s]?v\d+)?\b)(?:\w+[\s_.-]*)*?(?:(?:\[[^]]+\]|\([^)]+\)|\{[^}]+\})(?:[\s_]*))*(?:[[({][\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. -->
        <!-- Examples:
            Saki/Season 1/Saki [Jarzka]/[Jarzka] Saki 01 - Encounter [480p 10bit DVD FLAC] [9EED32CB].mkv
            Saki/Season 3/[Underwater-FFF] Saki Zenkoku-hen - The Nationals - 01 (720p) [AF65724D].mkv
            No checksum:
            Saki/Season 2/[HorribleSubs] Saki Episode of Side A - 14 [720p].mp4
         <regexp>(?i)S(?:eason ?)?(\d{1,3})[\\/](?:[^\\/]+[\\/])+.+?(?:(?:\b|_)(?:ep?[ .]?)?(\d{1,3})(-\d{1,3})?(?:[_ ]?v\d)?[\s_.-]+)(?![^([{]*\b\d{1,3}(?:[_\s]?v\d+)?\b)(?:\w+[\s_.-]*)*?(?:(?:\[[^]]+\]|\([^)]+\)|\{[^}]+\})(?:[\s_]*))*(?:[[({][\da-f]{8}[])}])?(?:[^\\/]*$)</regexp>

        <!-- Include season marker in the filename. -->
        <!-- Examples:
            [CoalGuys] K-ON!! S2 - 05 [4B19B10F]
            No checksum:
            [DeadFish] Toaru Kagaku no Railgun S - S2 - 01 [720p][AAC].mp4
        <regexp>(?i)(?:\bS(?:eason ?)?(\d{1,3})[\s_.-]*)?(?:(?:\b|_)(?:ep?[ .]?)?(\d{1,3})(-\d{1,3})?(?:[_ ]?v\d)?[\s_.-]+)(?![^([{]*\b\d{1,3}(?:[_\s]?v\d+)?\b)(?:\w+[\s_.-]*)*?(?:(?:\[[^]]+\]|\([^)]+\)|\{[^}]+\})(?:[\s_]*))*(?:[[({][\da-f]{8}[])}])?(?:[^\\/]*$)</regexp>

        <!-- Anything else gets the blank first capture to cause a default season of 1. -->
        <!-- Examples:
            [avatar-nyanko] Koikoi 7 - 01 (DVD) [5E95FA4A]
            [Eclipse] Akane-iro ni Somaru Saka - 01 (1024x576 h264) [39920E63].mkv
            Touch 01(DVD) - (112ceb61) Central Anime
            Cross Game 02 - Central Anime (1280x720) [BF23052D].mp4
            [Triad]_Dokuro-chan_-_01.02v2 [12345678].mkv
            No checksum:
            [a.f.k.] Lucky Star - 01.avi
            Air Master - 04 [HQA&N!].avi
            [ANE] Yosuga no Sora - Ep01v2 [BDRip 1080p x264 FLAC]
            [DeadFish] Jinrui wa Suitai Shimashita - 01 [BD][720p][AAC].mp4

        <regexp>(?i)()(?:(?:\b|_)(?:ep?[ .]?)?(\d{1,3})(?:\.(0?[a-i1-9]))?(?:[_ ]?v\d)?[\s_.-]+)(?![^([{]*\b\d{1,3}(?:[_\s]?v\d+)?\b)(?:\w+[\s_.-]*)*?(?:(?:\[[^]]+\]|\([^)]+\)|\{[^}]+\})(?:[\s_]*))*(?:[[({][\da-f]{8}[])}])?(?:[^\\/]*$)</regexp>

The last regex should work fine for "absolute ordering" (ie: pure sequential numbering, all under season 1). It puts everything in season 1, and can match anything up to episode 999 (might need to extend that to four digits for One Piece soon, though). It also has no trouble with his example of "Eyeshield 21 124.avi".
(This post was last modified: 2017-02-11 01:16 by Kinematics.)
find quote
poul_l322 Offline
Junior Member
Posts: 9
Joined: May 2017
Reputation: 0
Post: #362
ive been searching for this for too long thanks!
find quote
Momin Offline
Junior Member
Posts: 2
Joined: Apr 2017
Reputation: 0
Location: Pakistan
Post: #363
What Is Extra Regex? Actually I m Using An Automatic Plugin For wordpress And There Is An Option for Extra Regex So Kindly If Someone Plz Guide Me.....

This Is Link For One oF My Site

@Karellen- Spam link removed
(This post was last modified: 2017-05-15 03:16 by Karellen.)
find quote
Karellen Offline
Super Moderator
Posts: 571
Joined: Apr 2017
Reputation: 11
Location: Melbourne, Australia
Post: #364
(2017-05-10 18:32)Momin Wrote:  What Is Extra Regex? Actually I m Using An Automatic Plugin For wordpress And There Is An Option for Extra Regex So Kindly If Someone Plz Guide Me.....

This Is Link For One oF My Site

@Karellen- Spam link removed

Hello Momin,

I am not understanding your links. I believe you are trying to redirect traffic to a site that hosts a large number of Indian movies.

I have deleted references in both your posts.

If I am in error, please post and explain.

My Signature
Links to : Banned Add-Ons | Debug Log | Free Movies/TV Shows |

find quote
Post Reply