fetchart: Pass config object to backends when initialized

This commit is contained in:
Lachlan Charlick 2015-12-29 01:37:53 +10:30
parent 03a41e82da
commit 2e10b8c284
2 changed files with 10 additions and 9 deletions

View file

@ -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):

View file

@ -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):