2020-03-18 19:33:54 +00:00
|
|
|
from logging import NullHandler, getLogger
|
|
|
|
|
2023-03-22 03:15:01 +00:00
|
|
|
from trakit.api import trakit
|
2020-03-18 19:33:54 +00:00
|
|
|
|
2022-01-24 04:07:52 +00:00
|
|
|
from knowit.core import Rule
|
2020-03-18 19:33:54 +00:00
|
|
|
|
|
|
|
logger = getLogger(__name__)
|
|
|
|
logger.addHandler(NullHandler())
|
|
|
|
|
|
|
|
|
2023-03-22 03:15:01 +00:00
|
|
|
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."""
|
2023-03-22 03:15:01 +00:00
|
|
|
if 'guessed' not in pv_props:
|
2020-03-18 19:33:54 +00:00
|
|
|
return
|
|
|
|
|
2023-03-22 03:15:01 +00:00
|
|
|
guess = pv_props['guessed']
|
|
|
|
if 'language' in guess:
|
|
|
|
return guess['language']
|