guessit-io / guessit

GuessIt is a python library that extracts as much information as possible from a video filename.
https://guessit-io.github.io/guessit
GNU Lesser General Public License v3.0
814 stars 92 forks source link

Upgrade from guessit 3.1.1 to 3.3.1 breaks custom rebulk rules #692

Closed h3llrais3r closed 3 years ago

h3llrais3r commented 3 years ago

Guessit with custom rebulk rules are broken. I'm using guessit as mentioned below:

from guessit.api import default_api

from autosubliminal.parsers.guessit.rules import rules

# Add our custom rules to the default guessit api
default_api.configure({})
default_api.rebulk.rebulk(rules())

Afterwards I'm using the adapted default_api:

custom_options = dict(options) if options else dict()
custom_options.update(dict(expected_title=expected_titles, expected_group=expected_release_groups))
result = default_api.guessit(string, options=custom_options)

The default_api.guessit calls internally again the configure()

Within the configure() it compares if the advanced_config has changed and forces a rebuild of rebulk when different.

Commit https://github.com/guessit-io/guessit/commit/51e00217947d8b993bcfb091b012da803245f698#diff-66e80a71bd17399af0e8d250f0b561e30ca0090d84cd4b306ea13bfdfc90f842 has introduced a breaking change when guessit is extended with custom rebulk rules. Within this change, the pattern and regex are popped from the config options (really removed from the advanced_config) which breaks the comparison in the configure() in the GuessitApi class in api.py.

should_build_rebulk = force or not self.rebulk or not self.advanced_config or \
                              self.advanced_config != advanced_config

Because the advanced_config is no longer identical, rebulk is rebuild and my custom rebulk rules are lost... On 3.1.1 this was not the case...

Fix seems fairly easy and is tested by me:

This doesn't physically removes the items from the dict and ensures that the config is not changed, so the rebulk rules are not lost.

Can you please verify if my findings are correct and fix it in case you agree? Thanks!

Toilal commented 3 years ago

Your issue is with no doubt caused by those mutations. I'll try to find another solution though, as I don't want pattern and regex keywords to be passed to underlying function.

h3llrais3r commented 3 years ago

Let me know when you have a solution. I'm happy to test it. šŸ˜‰

Toilal commented 3 years ago

Could you give a try with develop branch ?

h3llrais3r commented 3 years ago

@Toilal I've just tried the develop branch on my local machine and I confirm that the issue is fixed. No rebuild is done now and my custom rules are still taken into account. šŸ‘