From 625e9253c03bc4f2c5cab6c54e014cfbe8bca49e Mon Sep 17 00:00:00 2001 From: Ashhar Hasan Date: Sun, 19 Apr 2020 19:05:55 +0530 Subject: [PATCH] Add tests for artist_sort as lyrics search fallback Adjust doc comment to highlight that artist_sort is used as a fallback --- beetsplug/lyrics.py | 3 +++ test/test_lyrics.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 0aebe9606..20e1c8858 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -187,6 +187,9 @@ def search_pairs(item): In addition to the artist and title obtained from the `item` the method tries to strip extra information like paranthesized suffixes and featured artists from the strings and add them as candidates. + The artist sort name is added as a fallback candidate to help in + cases where artist name includes special characters or is in a + non-latin script. The method also tries to split multiple titles separated with `/`. """ def generate_alternatives(string, patterns): diff --git a/test/test_lyrics.py b/test/test_lyrics.py index 83a229f62..81d62fea9 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -95,6 +95,27 @@ class LyricsPluginTest(unittest.TestCase): self.assertEqual(('Alice and Bob', ['song']), list(lyrics.search_pairs(item))[0]) + def test_search_artist_sort(self): + item = Item(artist='CHVRCHΞS', title='song', artist_sort='CHVRCHES') + self.assertIn(('CHVRCHΞS', ['song']), + lyrics.search_pairs(item)) + self.assertIn(('CHVRCHES', ['song']), + lyrics.search_pairs(item)) + + # Make sure that the original artist name is still the first entry + self.assertEqual(('CHVRCHΞS', ['song']), + list(lyrics.search_pairs(item))[0]) + + item = Item(artist='横山克', title='song', artist_sort='Masaru Yokoyama') + self.assertIn(('横山克', ['song']), + lyrics.search_pairs(item)) + self.assertIn(('Masaru Yokoyama', ['song']), + lyrics.search_pairs(item)) + + # Make sure that the original artist name is still the first entry + self.assertEqual(('横山克', ['song']), + list(lyrics.search_pairs(item))[0]) + def test_search_pairs_multi_titles(self): item = Item(title='1 / 2', artist='A') self.assertIn(('A', ['1 / 2']), lyrics.search_pairs(item))