Merge branch 'feat/parser-phase-d'

This commit is contained in:
2026-05-20 23:30:36 +02:00
9 changed files with 133 additions and 58 deletions
+31
View File
@@ -15,6 +15,37 @@ callers).
## [Unreleased] ## [Unreleased]
### Fixed
- **Multi-episode chain (e.g. `S14E09E10E11`) now collapses to a full
range.** The parser previously captured `episode=9, episode_end=10`
and dropped E11+. It now returns `episode=first, episode_end=last`,
with intermediate values implied. Fixture
`shitty/archer_multi_episode/` updated from anti-regression-of-bug
to anti-regression-of-fix.
- **Apostrophes in titles no longer push the release through the AI
fallback.** `Honey.Don't.2025.2160p.WEBRip.DSNP.DV.HDR.x265-Amen`
previously parsed with `parse_path="ai"` and everything UNKNOWN
because `'` is in the forbidden-chars list. Apostrophes are now
pre-stripped before the well-formed check, so the parse completes
normally (`title=Honey.Dont, year=2025, quality=2160p, ...`); only
the title text loses its apostrophe. `parse_path` becomes
`sanitized` to surface the cleanup. Side win: PoP fixture
`the_prodigy_full_chaos/` also moves from total failure to a
partially-correct parse (year, source, codec extracted).
- **Season-range markers (`Sxx-yy`) are now recognized as
`tv_complete`.** `Der.Tatortreiniger.S01-06.GERMAN...` previously
parsed as `media_type=movie` with `S01-06` glued onto the title.
The parser now recognizes the range, sets `season=first`,
`media_type=tv_complete`, and removes the marker from the title.
`is_season_pack` flips to `true`.
- **Pure-punctuation TITLE tokens are dropped at assembly.** Releases
with surrounding ` - ` separators (`Vinyl - 1x01 - FHD`) previously
produced `title="Vinyl.-"`. Such tokens (a stray dash, a wide pipe
``, …) carry no title content and are now filtered out. Side
effect: PoP fixture `khruangbin_yt_wide_pipe/` also benefits — the
YouTube wide-pipe no longer leaks into the title.
### Added ### Added
- **`LanguageRepository` port** in `alfred.domain.shared.ports`. Structural - **`LanguageRepository` port** in `alfred.domain.shared.ports`. Structural
+39 -5
View File
@@ -91,14 +91,17 @@ def tokenize(name: str, kb: ReleaseKnowledge) -> tuple[list[Token], str | None]:
def _parse_season_episode(text: str) -> tuple[int, int | None, int | None] | None: def _parse_season_episode(text: str) -> tuple[int, int | None, int | None] | None:
"""Parse a single token as ``SxxExx`` / ``SxxExxExx`` / ``Sxx`` / ``NxNN``. """Parse a single token as ``SxxExx`` / ``SxxExxExx`` / ``Sxx`` /
``Sxx-yy`` (season range) / ``NxNN``.
Returns ``(season, episode, episode_end)`` or ``None`` if the token Returns ``(season, episode, episode_end)`` or ``None`` if the token
is not a season/episode marker. is not a season/episode marker. For ``Sxx-yy``, returns the first
season with no episode info — the caller is expected to detect the
range form and promote ``media_type`` to ``tv_complete`` separately.
""" """
upper = text.upper() upper = text.upper()
# SxxExx form # SxxExx form (and Sxx, Sxx-yy)
if len(upper) >= 3 and upper[0] == "S" and upper[1:3].isdigit(): if len(upper) >= 3 and upper[0] == "S" and upper[1:3].isdigit():
season = int(upper[1:3]) season = int(upper[1:3])
rest = upper[3:] rest = upper[3:]
@@ -106,6 +109,15 @@ def _parse_season_episode(text: str) -> tuple[int, int | None, int | None] | Non
if not rest: if not rest:
return season, None, None return season, None, None
# Sxx-yy season-range form: capture the first season, treat as a
# complete-series marker (no episode info).
if (
len(rest) == 3
and rest[0] == "-"
and rest[1:3].isdigit()
):
return season, None, None
episodes: list[int] = [] episodes: list[int] = []
while rest.startswith("E") and len(rest) >= 3 and rest[1:3].isdigit(): while rest.startswith("E") and len(rest) >= 3 and rest[1:3].isdigit():
episodes.append(int(rest[1:3])) episodes.append(int(rest[1:3]))
@@ -113,7 +125,9 @@ def _parse_season_episode(text: str) -> tuple[int, int | None, int | None] | Non
if not episodes: if not episodes:
return None return None
return season, episodes[0], episodes[1] if len(episodes) >= 2 else None # For chained multi-episode markers (E09E10E11), the range is the
# first → last episode. Intermediate values are implied.
return season, episodes[0], episodes[-1] if len(episodes) >= 2 else None
# NxNN form # NxNN form
if "X" in upper: if "X" in upper:
@@ -616,7 +630,14 @@ def assemble(
layer in additional fields (``parse_path``, ``raw``, …) before layer in additional fields (``parse_path``, ``raw``, …) before
instantiation. instantiation.
""" """
title_parts = [t.text for t in annotated if t.role is TokenRole.TITLE] # Pure-punctuation tokens (e.g. a stray "-" left by ` - ` separators in
# human-friendly release names) carry no title content and would leak
# into the joined title as ``"Show.-.Episode"``. Drop them here.
title_parts = [
t.text
for t in annotated
if t.role is TokenRole.TITLE and any(c.isalnum() for c in t.text)
]
title = ".".join(title_parts) if title_parts else ( title = ".".join(title_parts) if title_parts else (
annotated[0].text if annotated else raw_name annotated[0].text if annotated else raw_name
) )
@@ -636,6 +657,7 @@ def assemble(
edition: str | None = None edition: str | None = None
distributor: str | None = None distributor: str | None = None
languages: list[str] = [] languages: list[str] = []
is_season_range = False
for tok in annotated: for tok in annotated:
# Skip non-primary members of a multi-token sequence. # Skip non-primary members of a multi-token sequence.
@@ -649,6 +671,16 @@ def assemble(
parsed = _parse_season_episode(tok.text) parsed = _parse_season_episode(tok.text)
if parsed is not None: if parsed is not None:
season, episode, episode_end = parsed season, episode, episode_end = parsed
# Detect Sxx-yy range form to flag it as a multi-season pack.
upper = tok.text.upper()
if (
len(upper) == 6
and upper[0] == "S"
and upper[1:3].isdigit()
and upper[3] == "-"
and upper[4:6].isdigit()
):
is_season_range = True
elif role is TokenRole.RESOLUTION: elif role is TokenRole.RESOLUTION:
quality = tok.text quality = tok.text
elif role is TokenRole.SOURCE: elif role is TokenRole.SOURCE:
@@ -696,6 +728,8 @@ def assemble(
media_type = "documentary" media_type = "documentary"
elif upper_tokens & concert_tokens: elif upper_tokens & concert_tokens:
media_type = "concert" media_type = "concert"
elif is_season_range:
media_type = "tv_complete"
elif ( elif (
edition in {"COMPLETE", "INTEGRALE", "COLLECTION"} edition in {"COMPLETE", "INTEGRALE", "COLLECTION"}
or upper_tokens & integrale_tokens or upper_tokens & integrale_tokens
+11 -2
View File
@@ -46,7 +46,16 @@ def parse_release(
""" """
parse_path = ParsePath.DIRECT.value parse_path = ParsePath.DIRECT.value
clean, site_tag = _v2.strip_site_tag(name) # Apostrophes inside titles ("Don't", "L'avare") are common and should
# not push the release through the AI fallback. Strip them up front so
# both strip_site_tag and tokenize see "Dont" / "Lavare", which is good
# enough for token-level matching. The raw name is preserved on the VO.
working_name = name
if "'" in working_name:
working_name = working_name.replace("'", "")
parse_path = ParsePath.SANITIZED.value
clean, site_tag = _v2.strip_site_tag(working_name)
if site_tag is not None: if site_tag is not None:
parse_path = ParsePath.SANITIZED.value parse_path = ParsePath.SANITIZED.value
@@ -77,7 +86,7 @@ def parse_release(
) )
return parsed, report return parsed, report
tokens, v2_tag = _v2.tokenize(name, kb) tokens, v2_tag = _v2.tokenize(working_name, kb)
annotated = _v2.annotate(tokens, kb) annotated = _v2.annotate(tokens, kb)
fields = _v2.assemble(annotated, v2_tag, name, kb) fields = _v2.assemble(annotated, v2_tag, name, kb)
@@ -1,13 +1,15 @@
release_name: "Khruangbin Austin City Limits Music Festival 2024 Full Set [V_-7WWPPeBs].webm" release_name: "Khruangbin Austin City Limits Music Festival 2024 Full Set [V_-7WWPPeBs].webm"
# yt-dlp slug: UTF-8 wide pipe '' (U+FF5C, not the ASCII '|'), trailing # yt-dlp slug: UTF-8 wide pipe '' (U+FF5C, not the ASCII '|'), trailing
# YouTube video ID in brackets, .webm extension. Parser extracts the year # YouTube video ID in brackets, .webm extension. The wide pipe survives
# (2024) correctly but mistakes the YouTube ID '7WWPPeBs' for a release # the tokenizer (not a separator) but is now dropped at title assembly
# group, and the wide pipe survives the tokenizer (not a separator). # (pure-punctuation TITLE tokens carry no content). Year (2024) parses
# correctly; the YouTube ID '7WWPPeBs' is still mistaken for a release
# group (separate gap, see PoP backlog).
# This is a concert recording — closer to "live music" than "movie", but # This is a concert recording — closer to "live music" than "movie", but
# media_type=movie is the current degenerate best guess. # media_type=movie is the current degenerate best guess.
parsed: parsed:
title: "Khruangbin..Austin.City.Limits.Music.Festival" title: "Khruangbin.Austin.City.Limits.Music.Festival"
year: 2024 year: 2024
season: null season: null
episode: null episode: null
@@ -1,28 +1,26 @@
release_name: "The Prodigy World's on Fire 2011 Blu-ray Remux 1080i AVC DTS-HD MA 5.1 - KRaLiMaRKo.mkv" release_name: "The Prodigy World's on Fire 2011 Blu-ray Remux 1080i AVC DTS-HD MA 5.1 - KRaLiMaRKo.mkv"
# Apocalypse case combining every horror: # Apocalypse case combining every horror — partially tamed by the
# - Unescaped apostrophe ("World's") → forces parse_path="ai" fallback # apostrophe fix. Remaining gaps (still PoP-worthy):
# - Spaces AND dashes used as separators inconsistently # - "1080i" interlaced flag (not in quality KB)
# - "Blu-ray" with a dash (vs. canonical BluRay) # - "Blu-ray" with a dash (vs. canonical BluRay) — recognized as source
# - "1080i" interlaced flag (not 1080p) # but with the dash form
# - "DTS-HD MA 5.1" multi-word audio codec # - "DTS-HD MA 5.1" multi-word audio codec — the trailing "HD" leaks
# - " - GROUP.mkv" trailing format (space-dash-space before group) # into the group
# - Trailing .mkv extension survives in title # - Trailing .mkv extension survives in title
# Result: total degeneration — UNKNOWN across the board, title=raw input. # - " - GROUP" trailing format (space-dash-space before group)
# Once the apostrophe + multi-word-audio + 1080i are handled this fixture
# should be revisited. For now: anti-regression of the failure shape.
parsed: parsed:
title: "The Prodigy World's on Fire 2011 Blu-ray Remux 1080i AVC DTS-HD MA 5.1 - KRaLiMaRKo.mkv" title: "The.Prodigy.Worlds.on.Fire"
year: null year: 2011
season: null season: null
episode: null episode: null
quality: null quality: null
source: null source: "Blu-ray"
codec: null codec: "AVC"
group: "UNKNOWN" group: "HD"
tech_string: "" tech_string: "Blu-ray.AVC"
media_type: "unknown" media_type: "movie"
parse_path: "ai" parse_path: "sanitized"
is_season_pack: false is_season_pack: false
tree: tree:
@@ -1,14 +1,13 @@
release_name: "Archer.S14E09E10E11.1080p.WEB.h264-ETHEL" release_name: "Archer.S14E09E10E11.1080p.WEB.h264-ETHEL"
# Tech debt: triple-episode chain (E09E10E11) — current parser captures # Triple-episode chain (E09E10E11) — the parser collapses the chain to a
# episode=9 and episode_end=10, but E11 is lost. Anti-regression: lock in # range (episode=first, episode_end=last). Intermediate values are implied.
# the partial behavior so any future improvement is intentional.
parsed: parsed:
title: "Archer" title: "Archer"
year: null year: null
season: 14 season: 14
episode: 9 episode: 9
episode_end: 10 episode_end: 11
quality: "1080p" quality: "1080p"
source: "WEB" source: "WEB"
codec: "h264" codec: "h264"
+14 -13
View File
@@ -1,21 +1,22 @@
release_name: "Honey.Don't.2025.2160p.WEBRip.DSNP.DV.HDR.x265.EAC3.5.1-Amen" release_name: "Honey.Don't.2025.2160p.WEBRip.DSNP.DV.HDR.x265.EAC3.5.1-Amen"
# Tech debt: the unescaped apostrophe in "Don't" pushes the whole release # Apostrophes inside titles ("Don't", "L'avare") used to push the release
# through the AI fallback path (parse_path="ai") and the parse degenerates to # through the AI fallback (parse_path="ai", everything UNKNOWN). They are
# UNKNOWN across the board. Anti-regression here — once the tokenizer learns # now pre-stripped before well-formed check and tokenize, so the parse
# to handle apostrophes, this fixture should be revisited. # completes normally — only the title text loses its apostrophe
# ("Honey.Dont").
parsed: parsed:
title: "Honey.Don't.2025.2160p.WEBRip.DSNP.DV.HDR.x265.EAC3.5.1-Amen" title: "Honey.Dont"
year: null year: 2025
season: null season: null
episode: null episode: null
quality: null quality: "2160p"
source: null source: "WEBRip"
codec: null codec: "x265"
group: "UNKNOWN" group: "Amen"
tech_string: "" tech_string: "2160p.WEBRip.x265"
media_type: "unknown" media_type: "movie"
parse_path: "ai" parse_path: "sanitized"
is_season_pack: false is_season_pack: false
tree: tree:
@@ -1,22 +1,22 @@
release_name: "Der.Tatortreiniger.S01-06.GERMAN.1080p.WEB.x264-WAYNE" release_name: "Der.Tatortreiniger.S01-06.GERMAN.1080p.WEB.x264-WAYNE"
# Tech debt: range syntax 'S01-06' is not recognized as TV — falls through # Range syntax 'S01-06' is now recognized as a season-range marker:
# to media_type=movie with the range glued onto the title. Captured here so a # season=1 (first of the range), media_type=tv_complete, and the token
# future ranger-aware parser change is intentional. # no longer leaks into the title.
parsed: parsed:
title: "Der.Tatortreiniger.S01-06" title: "Der.Tatortreiniger"
year: null year: null
season: null season: 1
episode: null episode: null
quality: "1080p" quality: "1080p"
source: "WEB" source: "WEB"
codec: "x264" codec: "x264"
group: "WAYNE" group: "WAYNE"
tech_string: "1080p.WEB.x264" tech_string: "1080p.WEB.x264"
media_type: "movie" media_type: "tv_complete"
languages: ["GERMAN"] languages: ["GERMAN"]
parse_path: "direct" parse_path: "direct"
is_season_pack: false is_season_pack: true
tree: tree:
- "Der.Tatortreiniger.S01-06.GERMAN.1080p.WEB.x264-WAYNE/" - "Der.Tatortreiniger.S01-06.GERMAN.1080p.WEB.x264-WAYNE/"
@@ -1,11 +1,12 @@
release_name: "Vinyl - 1x01 - FHD" release_name: "Vinyl - 1x01 - FHD"
# Tech debt: surrounding ' - ' separators leave a stray '-' token attached # Surrounding ' - ' separators in human-friendly release names left stray
# to the title ("Vinyl.-"). NxNN form correctly identifies S01E01; everything # '-' tokens attached to the title. They are now dropped at assembly time
# tech-side empty (no quality token in KB — "FHD" not yet known). Anti-regression # (pure-punctuation TITLE tokens carry no content). NxNN form correctly
# the current degenerate title so a future fix is intentional. # identifies S01E01; tech-side stays empty (no quality token in KB — "FHD"
# not yet known).
parsed: parsed:
title: "Vinyl.-" title: "Vinyl"
year: null year: null
season: 1 season: 1
episode: 1 episode: 1