bazarr/libs/knowit/rules/general.py

35 lines
904 B
Python
Raw Normal View History

2020-03-18 19:33:54 +00:00
from logging import NullHandler, getLogger
from trakit.api import trakit
2020-03-18 19:33:54 +00:00
from knowit.core import Rule
2020-03-18 19:33:54 +00:00
logger = getLogger(__name__)
logger.addHandler(NullHandler())
class GuessTitleRule(Rule):
"""Guess properties from track title."""
def execute(self, props, pv_props, context):
"""Language detection using name."""
if 'name' in props:
language = props.get('language')
options = {'expected_language': language} if language else {}
guessed = trakit(props['name'], options)
if guessed:
return guessed
2020-03-18 19:33:54 +00:00
class LanguageRule(Rule):
"""Language rules."""
def execute(self, props, pv_props, context):
"""Language detection using name."""
if 'guessed' not in pv_props:
2020-03-18 19:33:54 +00:00
return
guess = pv_props['guessed']
if 'language' in guess:
return guess['language']