igorcmoura / anitopy

Anime video filename parser in Python, based on Anitomy
Mozilla Public License 2.0
72 stars 19 forks source link

Anitopy throws `KeyError` when parsing filename #6

Closed mnabid closed 3 years ago

mnabid commented 3 years ago

When there's a filename in the following format —

ANIME_TITLE   Season X   ANIME_TYPE   [round, square or curly brackets]   EXACT_SAME_ANIME_TYPE   Episode Y

anitopy fails to parse it and throws an exception.

It only triggers when the same anime_type is repeated once or more and there's something (or nothing) in brackets between them. The error doesn't happen when I omit the season or episode number.

Example

>>> anitopy.parse("One-Punch Man Season 1 OVA [Judas] OVA - 05.mkv")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/anitopy/anitopy.py", line 48, in parse
    if not parser.parse():
  File "/usr/lib/python3.9/site-packages/anitopy/parser.py", line 33, in parse
    self.validate_elements()
  File "/usr/lib/python3.9/site-packages/anitopy/parser.py", line 302, in validate_elements
    Elements.erase(ElementCategory.EPISODE_TITLE)
  File "/usr/lib/python3.9/site-packages/anitopy/element.py", line 107, in erase
    del cls.instance()._elements[category.value]
KeyError: 'episode_title'
igorcmoura commented 3 years ago

Thank you for reporting this problem! Sorry for taking so long to look into it.

I fixed and released it at the version 2.0.2