diff options
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/indexer/title_parse.py')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/indexer/title_parse.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/indexer/title_parse.py b/packages/meshbay-node/src/meshbay_node/indexer/title_parse.py index 0baf34f..985bd7a 100644 --- a/packages/meshbay-node/src/meshbay_node/indexer/title_parse.py +++ b/packages/meshbay-node/src/meshbay_node/indexer/title_parse.py @@ -229,3 +229,20 @@ def parse_episode_filename(filename: str) -> ParsedName: display_title=title or None, naive_title=nt, season=season, episode=episode, confidence=confidence, ) + + +# A bare leading episode number, no show name attached (§3.4c) — the same +# shape as music's _TRACK_PREFIX_RE, capped at 3 digits for the same reason: +# a leading year ("2010 - Episode.mkv") is 4 digits and must not match. +# guessit's own `episode` is not a substitute here: given exactly 3 digits it +# tries to read them as a concatenated SxxE/SEE season+episode pair instead +# of a plain episode number — confirmed live, "100 Title.mkv" parses as +# season=1, episode=0, not episode=100 — silently wrong in a way nothing +# about its output distinguishes from a real 2-digit episode. This reads the +# whole leading number as one value instead. +_LEADING_NUMBER_RE = re.compile(r"^(\d{1,3})[\s._-]+(?=\S)") + + +def leading_episode_number(filename: str) -> int | None: + m = _LEADING_NUMBER_RE.match(filename) + return int(m.group(1)) if m else None |