From 2e10b8c284c7577cff7542633d1d5db2dda05e02 Mon Sep 17 00:00:00 2001 From: Lachlan Charlick Date: Tue, 29 Dec 2015 01:37:53 +1030 Subject: [PATCH] fetchart: Pass config object to backends when initialized --- beetsplug/fetchart.py | 11 ++++++----- test/test_art.py | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 9d971a3fc..392db9e47 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -96,8 +96,9 @@ class RequestMixin(object): # ART SOURCES ################################################################ class ArtSource(RequestMixin): - def __init__(self, log): + def __init__(self, log, config): self._log = log + self._config = config def get(self, album): raise NotImplementedError() @@ -168,8 +169,8 @@ class GoogleImages(ArtSource): return search_string = (album.albumartist + ',' + album.album).encode('utf-8') response = self.request(self.URL, params={ - 'key': config['fetchart']['google_API_key'].get(), - 'cx': config['fetchart']['google_engine_ID'].get(), + 'key': self._config['google_API_key'].get(), + 'cx': self._config['google_engine_ID'].get(), 'q': search_string, 'searchType': 'image' }) @@ -443,8 +444,8 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): available_sources.remove(u'google') sources_name = plugins.sanitize_choices( self.config['sources'].as_str_seq(), available_sources) - self.sources = [ART_SOURCES[s](self._log) for s in sources_name] - self.fs_source = FileSystem(self._log) + self.sources = [ART_SOURCES[s](self._log, self.config) for s in sources_name] + self.fs_source = FileSystem(self._log, self.config) # Asynchronous; after music is added to the library. def fetch_art(self, session, task): diff --git a/test/test_art.py b/test/test_art.py index cb29f3769..324c3fbb0 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -65,13 +65,13 @@ class FetchImageTest(UseThePlugin): self.assertNotEqual(artpath, None) -class FSArtTest(_common.TestCase): +class FSArtTest(UseThePlugin): def setUp(self): super(FSArtTest, self).setUp() self.dpath = os.path.join(self.temp_dir, 'arttest') os.mkdir(self.dpath) - self.source = fetchart.FileSystem(logger) + self.source = fetchart.FileSystem(logger, self.plugin.config) def test_finds_jpg_in_directory(self): _common.touch(os.path.join(self.dpath, 'a.jpg')) @@ -190,13 +190,13 @@ class CombinedTest(UseThePlugin): self.assertEqual(len(responses.calls), 0) -class AAOTest(_common.TestCase): +class AAOTest(UseThePlugin): ASIN = 'xxxx' AAO_URL = 'http://www.albumart.org/index_detail.php?asin={0}'.format(ASIN) def setUp(self): super(AAOTest, self).setUp() - self.source = fetchart.AlbumArtOrg(logger) + self.source = fetchart.AlbumArtOrg(logger, self.plugin.config) @responses.activate def run(self, *args, **kwargs):