diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 311af4031..fb4eac5de 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -29,6 +29,11 @@ from beets import ui from beets import util from beets import config +try: + import itunes + HAVE_ITUNES = True +except ImportError: + HAVE_ITUNES = False IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg'] CONTENT_TYPES = ('image/jpeg',) @@ -290,11 +295,8 @@ def sanitize_sources(sources): if s in SOURCES_ALL + ['*']: if not (s in seen or seen.add(s)): res.extend(list(others_sources) if s == '*' else [s]) - if 'itunes' in res: - try: - import itunes - except ImportError: - res.remove('itunes') + if not HAVE_ITUNES and 'itunes' in res: + res.remove('itunes') return res # PLUGIN LOGIC ############################################################### diff --git a/test/test_fetchart.py b/test/test_fetchart.py index 399f43df5..8b77914d6 100644 --- a/test/test_fetchart.py +++ b/test/test_fetchart.py @@ -51,7 +51,7 @@ class FetchartCliTest(unittest.TestCase, TestHelper): res = fetchart.sanitize_sources(['google', '*', 'amazon']) # don't check strict egality on lengths as itunes source may be removed # by plugin - self.assertTrue(len(res) >= len(fetchart.SOURCES_ALL)-1 and + self.assertTrue(len(res) >= len(fetchart.SOURCES_ALL) - 1 and res[0] == 'google' and res[-1] == 'amazon')