diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 8af29ae75..2ba5bcb7e 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -314,10 +314,7 @@ class CoverArtArchive(RemoteArtSource): class Amazon(RemoteArtSource): NAME = u"Amazon" - if util.SNI_SUPPORTED: - URL = 'https://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' - else: - URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' + URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' INDICES = (1, 2) def get(self, album, extra): @@ -331,10 +328,7 @@ class Amazon(RemoteArtSource): class AlbumArtOrg(RemoteArtSource): NAME = u"AlbumArt.org scraper" - if util.SNI_SUPPORTED: - URL = 'https://www.albumart.org/index_detail.php' - else: - URL = 'http://www.albumart.org/index_detail.php' + URL = 'http://www.albumart.org/index_detail.php' PAT = r'href\s*=\s*"([^>"]*)"[^>]*title\s*=\s*"View larger image"' def get(self, album, extra): diff --git a/test/test_art.py b/test/test_art.py index 393527eef..694d9a05c 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -67,42 +67,38 @@ class FetchImageHelper(_common.TestCase): class FetchImageTest(FetchImageHelper, UseThePlugin): - URL = 'http://example.com/test.jpg' - URL_HTTPS = 'https://example.com/test.jpg' + URL = '{0}example.com/test.jpg' def setUp(self): super(FetchImageTest, self).setUp() self.dpath = os.path.join(self.temp_dir, b'arttest') self.source = fetchart.RemoteArtSource(logger, self.plugin.config) self.extra = {'maxwidth': 0} - self.candidate = fetchart.Candidate(logger, url=self.URL) - self.candidate_https = fetchart.Candidate(logger, url=self.URL_HTTPS) + self.candidate = fetchart.Candidate(logger, url=self.URL.format('http://')) def test_invalid_type_returns_none(self): - self.mock_response(self.URL, 'image/watercolour') - self.mock_response(self.URL_HTTPS, 'image/watercolour') + self.mock_response(self.URL.format('http://'), 'image/watercolour') + self.mock_response(self.URL.format('https://'), 'image/watercolour') self.source.fetch_image(self.candidate, self.extra) - self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(self.candidate.path, None) def test_jpeg_type_returns_path(self): - self.mock_response(self.URL, 'image/jpeg') + self.mock_response(self.URL.format('http://'), 'image/jpeg') + self.mock_response(self.URL.format('https://')) self.source.fetch_image(self.candidate, self.extra) self.assertNotEqual(self.candidate.path, None) def test_extension_set_by_content_type(self): - self.mock_response(self.URL, 'image/png') - self.mock_response(self.URL_HTTPS, 'image/png') + self.mock_response(self.URL.format('http://'), 'image/png') + self.mock_response(self.URL.format('https://'), 'image/png') self.source.fetch_image(self.candidate, self.extra) - self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) def test_does_not_rely_on_server_content_type(self): - self.mock_response(self.URL, 'image/jpeg', 'image/png') - self.mock_response(self.URL_HTTPS, 'image/jpeg', 'imsge/png') + self.mock_response(self.URL.format('http://'), 'image/jpeg', 'image/png') + self.mock_response(self.URL.format('https://'), 'image/jpeg', 'imsge/png') self.source.fetch_image(self.candidate, self.extra) - self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) @@ -158,28 +154,20 @@ class FSArtTest(UseThePlugin): class CombinedTest(FetchImageHelper, UseThePlugin): ASIN = 'xxxx' MBID = 'releaseid' - AMAZON_URL = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ + AMAZON_URL = 'images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ .format(ASIN) - AAO_URL = 'http://www.albumart.org/index_detail.php?asin={0}' \ + AAO_URL = 'www.albumart.org/index_detail.php?asin={0}' \ .format(ASIN) - CAA_URL = 'http://coverartarchive.org/release/{0}/front' \ + CAA_URL = 'coverartarchive.org/release/{0}/front' \ .format(MBID) - AMAZON_URL_HTTPS = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ - .format(ASIN) - AAO_URL_HTTPS = 'http://www.albumart.org/index_detail.php?asin={0}' \ - .format(ASIN) - CAA_URL_HTTPS = 'http://coverartarchive.org/release/{0}/front' \ - .format(MBID) - def setUp(self): super(CombinedTest, self).setUp() self.dpath = os.path.join(self.temp_dir, b'arttest') os.mkdir(self.dpath) def test_main_interface_returns_amazon_art(self): - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) @@ -191,47 +179,44 @@ class CombinedTest(FetchImageHelper, UseThePlugin): def test_main_interface_gives_precedence_to_fs_art(self): _common.touch(os.path.join(self.dpath, b'art.jpg')) - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg')) def test_main_interface_falls_back_to_amazon(self): - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertFalse(candidate.path.startswith(self.dpath)) def test_main_interface_tries_amazon_before_aao(self): - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) self.assertEqual(len(responses.calls), 1) - self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL) - self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL_HTTPS) + self.assertEqual(responses.calls[0].request.url, "http://"+self.AMAZON_URL) def test_main_interface_falls_back_to_aao(self): - self.mock_response(self.AMAZON_URL, content_type='text/html') - self.mock_response(self.AMAZON_URL_HTTPS, content_type='text/html') + self.mock_response("http://"+self.AMAZON_URL, content_type='text/html') album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) - self.assertEqual(responses.calls[-1].request.url, self.AAO_URL) - self.assertEqual(responses.calls[-1].request.url, self.AAO_URL_HTTPS) + self.assertEqual(responses.calls[-1].request.url, "http://"+self.AAO_URL) def test_main_interface_uses_caa_when_mbid_available(self): - self.mock_response(self.CAA_URL) - self.mock_response(self.CAA_URL_HTTPS) + self.mock_response("http://"+self.CAA_URL) + self.mock_response("https://"+self.CAA_URL) album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) self.assertEqual(len(responses.calls), 1) - self.assertEqual(responses.calls[0].request.url, self.CAA_URL) - self.assertEqual(responses.calls[0].request.url, self.CAA_URL_HTTPS) + if util.SNI_SUPPORTED: + url = "https://"+self.CAA_URL + else: + url = "http://"+self.CAA_URL + self.assertEqual(responses.calls[0].request.url, url) def test_local_only_does_not_access_network(self): album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN)