diff --git a/NEWS b/NEWS index a5b5129c5..b8ab9cd62 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,7 @@ to the @listen decorator (Thanks again, Lugoues!) * In path formats, $albumartist now falls back to $artist (as well as the other way around). +* When autotagging, "and" is considered equal to "&". * Fix some crashes when deleting files that don't exist. * Fix adding individual tracks in BPD. * Fix crash when ~/.beetsconfig does not exist. diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 6a8705d62..14b827244 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -74,6 +74,10 @@ SD_PATTERNS = [ (r'\[.*?\]', 0.3), (r'(, )?(pt\.|part) .+', 0.2), ] +# Replacements to use before testing distance. +SD_REPLACE = [ + (r'&', 'and'), +] # Artist signals that indicate "various artists". VA_ARTISTS = (u'', u'various artists', u'va', u'unknown') @@ -134,6 +138,11 @@ def string_dist(str1, str2): str1 = '%s %s' % (word, str1[:-len(word)-2]) if str2.endswith(', %s' % word): str2 = '%s %s' % (word, str2[:-len(word)-2]) + + # Perform a couple of basic normalizing substitutions. + for pat, repl in SD_REPLACE: + str1 = re.sub(pat, repl, str1) + str2 = re.sub(pat, repl, str2) # Change the weight for certain string portions matched by a set # of regular expressions. We gradually change the strings and build diff --git a/test/test_autotag.py b/test/test_autotag.py index 5072337a0..1645af433 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -403,10 +403,14 @@ class ApplyCompilationTest(unittest.TestCase): def test_mb_albumartistid_applied(self): autotag.apply_metadata(self.items, self.info) - self.assertEqual(self.items[0].mb_albumartistid, '89ad4ac3-39f7-470e-963a-56509c546377') - self.assertEqual(self.items[1].mb_albumartistid, '89ad4ac3-39f7-470e-963a-56509c546377') - self.assertEqual(self.items[0].mb_artistid, 'a05686fc-9db2-4c23-b99e-77f5db3e5282') - self.assertEqual(self.items[1].mb_artistid, '80b3cf5e-18fe-4c59-98c7-e5bb87210710') + self.assertEqual(self.items[0].mb_albumartistid, + '89ad4ac3-39f7-470e-963a-56509c546377') + self.assertEqual(self.items[1].mb_albumartistid, + '89ad4ac3-39f7-470e-963a-56509c546377') + self.assertEqual(self.items[0].mb_artistid, + 'a05686fc-9db2-4c23-b99e-77f5db3e5282') + self.assertEqual(self.items[1].mb_artistid, + '80b3cf5e-18fe-4c59-98c7-e5bb87210710') def test_va_flag_cleared_does_not_set_comp(self): autotag.apply_metadata(self.items, self.info) @@ -487,6 +491,10 @@ class StringDistanceTest(unittest.TestCase): dist = autotag.string_dist('Untitled', '[Untitled]') self.assertEqual(dist, 0.0) + def test_ampersand_expansion(self): + dist = autotag.string_dist('And', '&') + self.assertEqual(dist, 0.0) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)