This commit is contained in:
Fabrice Laporte 2017-05-02 07:46:36 +02:00
parent 3e3ad6974c
commit 11eb90c758
2 changed files with 14 additions and 8 deletions

View file

@ -263,7 +263,8 @@ class MusiXmatch(SymbolsReplaced):
html = self.fetch_url(url)
if not html:
return
lyrics = extract_text_between(html, '<p class="mxm-lyrics__content" data-reactid="135">',
lyrics = extract_text_between(html,
'<p class="mxm-lyrics__content" data-reactid="135">',
'</p>')
return lyrics.strip(',"').replace('\\n', '\n')

View file

@ -235,14 +235,16 @@ class LyricsGoogleBaseTest(unittest.TestCase):
class LyricsPluginSourcesTest(LyricsGoogleBaseTest):
"""Check that beets google custom search engine sources are correctly scraped.
"""Check that beets google custom search engine sources are correctly
scraped.
"""
DEFAULT_SONG = dict(artist=u'The Beatles', title=u'Lady Madonna')
DEFAULT_SOURCES = [
dict(DEFAULT_SONG, backend=lyrics.LyricsWiki),
# dict(artist=u'Santana', title=u'Black magic woman', backend=lyrics.MusiXmatch),
# dict(artist=u'Santana', title=u'Black magic woman',
# backend=lyrics.MusiXmatch),
# dict(DEFAULT_SONG, backend=lyrics.Genius),
]
@ -295,19 +297,22 @@ class LyricsPluginSourcesTest(LyricsGoogleBaseTest):
LyricsGoogleBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()
@unittest.skipUnless(os.environ.get('BEETS_TEST_LYRICS_SOURCES', '0') == '1',
@unittest.skipUnless(os.environ.get(
'BEETS_TEST_LYRICS_SOURCES', '0') == '1',
'lyrics sources testing not enabled')
def test_backend_sources_ok(self):
"""Test default backends with songs known to exist in respective databases.
"""
errors = []
for s in self.DEFAULT_SOURCES:
res = s['backend'](self.plugin.config, self.plugin._log).fetch(s['artist'], s['title'])
res = s['backend'](self.plugin.config, self.plugin._log).fetch(
s['artist'], s['title'])
if not is_lyrics_content_ok(s['title'], res):
errors.append(s['backend'].__name__)
self.assertFalse(errors)
@unittest.skipUnless(os.environ.get('BEETS_TEST_LYRICS_SOURCES', '0') == '1',
@unittest.skipUnless(os.environ.get(
'BEETS_TEST_LYRICS_SOURCES', '0') == '1',
'lyrics sources testing not enabled')
def test_google_sources_ok(self):
"""Test if lyrics present on websites registered in beets google custom
@ -353,8 +358,8 @@ class LyricsGooglePluginMachineryTest(LyricsGoogleBaseTest):
html = raw_backend.fetch_url(url)
soup = BeautifulSoup(html, "html.parser",
parse_only=SoupStrainer('title'))
self.assertEqual(google.is_page_candidate(url, soup.title.string, s['title'], s['artist']),
True, url)
self.assertEqual(google.is_page_candidate(url, soup.title.string,
s['title'], s['artist']), True, url)
def test_is_page_candidate_fuzzy_match(self):
"""Test matching html page title with song infos -- when song infos are