Skip to content

GuessitException: FixParentFolderReplacingTitle corrupts rebulk when folder ends with codec digit (e.g. AC-3) #12241

Description

@Mika3578

Summary

Post-processing can abort with guessit.api.GuessitException / ValueError: list.remove(x): x not in list when a release folder name ends with a codec/quality suffix that looks like "separator + digits" (classic example: AC-3).

This is a Medusa custom-rules bug, not an upstream Guessit parser failure: stock Guessit parses the same string successfully.

Root cause (generic)

  1. FixParentFolderReplacingTitle treats any parent folder matching (_|\W)\d+$ as "folder ends with a number" (intended for cases like /Comedy 23/Show.S01E01.mkv).
  2. That regex also matches technical tails such as AC-3 (-3).
  3. The rule then mutates an existing match in place:
    episode_title[0].name = 'title'
    without properly removing/re-adding it in rebulk's indexes → _name_dict desync.
  4. A later rule (AvoidMultipleValuesRule, consequence RemoveMatch) calls matches.remove(match)ValueError: list.remove(x): x not in list → wrapped as GuessitException.
  5. NameParser / _analyze_name only catches InvalidNameException / InvalidShowException, so the exception bubbles up and kills the post-processor for that item.

Generic formula: in-place match.name mutation in Medusa rules + subsequent RemoveMatch = Guessit crash. Frequent trigger = false positive of ends_with_digit on codec/channel suffixes.

Reproduction

Path shape (folder + file both end with AC-3):

tv\Capital - Des vacances de rêve 30 % moins chères, oui, c'est vraiment possible ! 2023 French HDTV 720p AVC MKV AC-3\Capital - Des vacances de rêve 30 % moins chères, oui, c'est vraiment possible ! 2023 French HDTV 720p AVC MKV AC-3.mkv

Observed with Medusa's customized Guessit API (medusa.name_parser.rules); plain guessit.guessit(...) without Medusa rules does not crash.

Confirmed locally:

  • Enabling Medusa rules() → crash
  • Culprit interaction: FixParentFolderReplacingTitle then AvoidMultipleValuesRule
  • Skipping FixParentFolderReplacingTitle when the folder ends with a codec-like suffix → parse succeeds (title=Capital)

Suggested fix

In medusa/name_parser/rules/rules.py (FixParentFolderReplacingTitle):

  • Do not treat codec/channel tails as "ends with digit" (AC-3, EAC3, DDP5.1, H.264, x265, …).
  • Prefer not mutating match.name in place; use proper remove/append so rebulk indexes stay consistent.

Optional hardening:

  • Catch GuessitException in the name parser and map it to InvalidNameException so one bad name cannot abort the whole post-process run.

Environment

  • Guessit 3.4.2 (vendored)
  • Medusa custom rules in medusa/name_parser/rules/rules.py
  • Log excerpt: POSTPROCESSOR :: Exception generated: An internal error has occured in guessit. / ValueError: list.remove(x): x not in list in ext/rebulk/match.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions