From 58df77e2cb6dc9bbaabea017d0b9b93809efbbd5 Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Thu, 14 Apr 2016 08:31:14 +0200 Subject: [PATCH] langdetect conditional import --- beetsplug/lyrics.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index b18e715d8..40154cefd 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -27,7 +27,6 @@ import unicodedata import urllib import warnings from HTMLParser import HTMLParseError -from langdetect import detect from beets import plugins from beets import ui @@ -673,12 +672,14 @@ class LyricsPlugin(plugins.BeetsPlugin): if lyrics: self._log.info(u'fetched lyrics: {0}', item) - lang_from = detect(lyrics) - if self.config['bing_client_secret'].get() and \ - self.config['bing_lang_to'].get() != lang_from: - if not self.config['bing_lang_from'] or ( + if self.config['bing_client_secret'].get(): + from langdetect import detect + + lang_from = detect(lyrics) + if self.config['bing_lang_to'].get() != lang_from and ( + not self.config['bing_lang_from'] or ( lang_from in self.config[ - 'bing_lang_from'].as_str_seq()): + 'bing_lang_from'].as_str_seq())): lyrics = self.append_translation( lyrics, self.config['bing_lang_to']) else: