Skip to content

title_parser: preserve dots, inner hyphens, roman numerals, acronyms - #643

Open
molnara wants to merge 1 commit into
shane-mason:mainfrom
molnara:fix/title-parser-punctuation
Open

title_parser: preserve dots, inner hyphens, roman numerals, acronyms#643
molnara wants to merge 1 commit into
shane-mason:mainfrom
molnara:fix/title-parser-punctuation

Conversation

@molnara

@molnara molnara commented Jul 28, 2026

Copy link
Copy Markdown

Problem

TitleParser.parse_title calls Path(filename).stem, which splits at the last dot regardless of what follows. Callers in catalog_entry.py:21 and media_processor.py:112 already strip the extension via os.path.splitext, so parse_title receives a bare stem and strips a second time — consuming real title text.

>>> T.parse_title('G.I. Joe - S03E12.mkv')   # extension present
'G I Joe'
>>> T.parse_title('G.I. Joe - S03E12')       # same file, post-splitext
'G I'
>>> T.parse_title('C.O.P.S - E60 The Case of the Lawless Lady')
'C O P'

The same show renders inconsistently within a single schedule depending on which call path reached it. Custom title_patterns can't work around this — the user pattern captures G.I. Joe correctly and the damage happens downstream, in the cleanup applied to the matched group.

Four related issues in that same cleanup, all from the assumption that filenames are scene-style dot-delimited:

Input Before After
C.O.P.S - E60 ... C O P C.O.P.S
He-Man and the Masters of the Universe - S02E32.mkv He Man And The Masters... He-Man And The Masters...
The Godfather - Part III (1990).mp4 The Godfather Part Iii The Godfather Part III
UFC 12 Judgement Day.mp4 Ufc 12 Judgement Day UFC 12 Judgement Day

re.sub(r"[._-]", " ", title) flattens acronym dots and compound-name hyphens; str.capitalize() lowercases everything after the first character, which destroys both Roman numerals and all-caps show names.

Approach

  • Extension stripping matches only known video extensions, so it's idempotent — the existing double call becomes harmless and no caller needs changing.
  • Acronym and hyphen shielding substitutes sentinel characters before the separator cleanup, then restores them. The hyphen rule uses lookarounds requiring word characters on both sides, so - separators are unaffected.
  • Roman numerals use a strict form that rejects words merely composed of those letters (MID, DILL, CIVIL stay title-cased).
  • KEEP_UPPER preserves case for a small set of known acronyms. Happy to make this config-driven via main_config.json if an opinionated default isn't wanted — StationManager already loads arbitrary keys.

default_patterns is byte-identical to before; the diff is confined to the cleanup path.

Verification

Tested against a ~2,400 file library. Selected cases with custom patterns loaded:

'G.I. Joe - S03E12.mkv'                                    -> G.I. Joe
'G.I. Joe - S03E12'                                        -> G.I. Joe
'C.O.P.S - E48 The Case of the Lesser of Two Weevils.mp4'  -> C.O.P.S
'He-Man and the Masters of the Universe - S02E32.mkv'      -> He-Man And The Masters Of The Universe
'Spider-Man and His Amazing Friends - S01E03.mkv'          -> Spider-Man And His Amazing Friends
'The Godfather - Part III (1990).mp4'                      -> The Godfather Part III
'Menace II Society (1993).mp4'                             -> Menace II Society
'Mid (1999).mp4'                                           -> Mid
'Civil Action (1998).mp4'                                  -> Civil Action
'UFC 12 Judgement Day.mp4'                                 -> UFC 12 Judgement Day
'AVGN 042 Cheetahmen (nes).mp4'                            -> Cheetahmen (NES)
'Looney Tunes - S1952E12 Going! Going! Gosh!.mp4'          -> Looney Tunes
'Star Wars Ewoks - S01E09.mkv'                             -> Star Wars Ewoks

The last two confirm no regression on titles without punctuation.

This fix was created using Claude model Opus 5, so up to you if you want this change. It's been working well for me so far.

@shane-mason

Copy link
Copy Markdown
Owner

Starting review today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants