diff --git a/beetsplug/fromfilename.py b/beetsplug/fromfilename.py index 951af07c4..169c02ff6 100644 --- a/beetsplug/fromfilename.py +++ b/beetsplug/fromfilename.py @@ -27,29 +27,29 @@ import re # Filename field extraction patterns. PATTERNS = [ # "01 - Track 01" and "01": do nothing - ur'^(\d+)\s*-\s*track\s*\d$', - ur'^\d+$', + r'^(\d+)\s*-\s*track\s*\d$', + r'^\d+$', # Useful patterns. - ur'^(?P.+)-(?P.+)-(?P<tag>.*)$', - ur'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$', - ur'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$', - ur'^(?P<artist>.+)-(?P<title>.+)$', - ur'^(?P<track>\d+)\.\s*(?P<artist>.+)-(?P<title>.+)$', - ur'^(?P<track>\d+)\s*-\s*(?P<artist>.+)-(?P<title>.+)$', - ur'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)$', - ur'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)$', - ur'^(?P<title>.+)$', - ur'^(?P<track>\d+)\.\s*(?P<title>.+)$', - ur'^(?P<track>\d+)\s*-\s*(?P<title>.+)$', - ur'^(?P<track>\d+)\s(?P<title>.+)$', - ur'^(?P<title>.+) by (?P<artist>.+)$', + r'^(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$', + r'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$', + r'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$', + r'^(?P<artist>.+)-(?P<title>.+)$', + r'^(?P<track>\d+)\.\s*(?P<artist>.+)-(?P<title>.+)$', + r'^(?P<track>\d+)\s*-\s*(?P<artist>.+)-(?P<title>.+)$', + r'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)$', + r'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)$', + r'^(?P<title>.+)$', + r'^(?P<track>\d+)\.\s*(?P<title>.+)$', + r'^(?P<track>\d+)\s*-\s*(?P<title>.+)$', + r'^(?P<track>\d+)\s(?P<title>.+)$', + r'^(?P<title>.+) by (?P<artist>.+)$', ] # Titles considered "empty" and in need of replacement. BAD_TITLE_PATTERNS = [ - ur'^$', - ur'\d+?\s?-?\s*track\s*\d+', + r'^$', + r'\d+?\s?-?\s*track\s*\d+', ] diff --git a/test/test_library.py b/test/test_library.py index c34691acc..f39227a65 100644 --- a/test/test_library.py +++ b/test/test_library.py @@ -413,14 +413,14 @@ class DestinationTest(_common.TestCase): def test_sanitize_with_custom_replace_overrides_built_in_sub(self): with _common.platform_posix(): p = util.sanitize_path(u'a/.?/b', [ - (re.compile(ur'foo'), u'bar'), + (re.compile(r'foo'), u'bar'), ]) self.assertEqual(p, u'a/.?/b') def test_sanitize_with_custom_replace_adds_replacements(self): with _common.platform_posix(): p = util.sanitize_path(u'foo/bar', [ - (re.compile(ur'foo'), u'bar'), + (re.compile(r'foo'), u'bar'), ]) self.assertEqual(p, u'bar/bar') @@ -465,7 +465,7 @@ class DestinationTest(_common.TestCase): def test_destination_with_replacements(self): self.lib.directory = 'base' - self.lib.replacements = [(re.compile(ur'a'), u'e')] + self.lib.replacements = [(re.compile(r'a'), u'e')] self.lib.path_formats = [('default', '$album/$title')] self.i.title = 'foo' self.i.album = 'bar' @@ -476,14 +476,14 @@ class DestinationTest(_common.TestCase): def test_sanitize_empty_component(self): with _common.platform_posix(): p = util.sanitize_path(u'foo//bar', [ - (re.compile(ur'^$'), u'_'), + (re.compile(r'^$'), u'_'), ]) self.assertEqual(p, u'foo/_/bar') @unittest.skip('unimplemented: #359') def test_destination_with_empty_component(self): self.lib.directory = 'base' - self.lib.replacements = [(re.compile(ur'^$'), u'_')] + self.lib.replacements = [(re.compile(r'^$'), u'_')] self.lib.path_formats = [('default', '$album/$artist/$title')] self.i.title = 'three' self.i.artist = '' @@ -495,7 +495,7 @@ class DestinationTest(_common.TestCase): @unittest.skip('unimplemented: #359') def test_destination_with_empty_final_component(self): self.lib.directory = 'base' - self.lib.replacements = [(re.compile(ur'^$'), u'_')] + self.lib.replacements = [(re.compile(r'^$'), u'_')] self.lib.path_formats = [('default', '$album/$title')] self.i.title = '' self.i.album = 'one' diff --git a/test/test_player.py b/test/test_player.py index c1608e646..6115b92c2 100644 --- a/test/test_player.py +++ b/test/test_player.py @@ -23,42 +23,42 @@ from beetsplug import bpd class CommandParseTest(unittest.TestCase): def test_no_args(self): - s = ur'command' + s = r'command' c = bpd.Command(s) self.assertEqual(c.name, u'command') self.assertEqual(c.args, []) def test_one_unquoted_arg(self): - s = ur'command hello' + s = r'command hello' c = bpd.Command(s) self.assertEqual(c.name, u'command') self.assertEqual(c.args, [u'hello']) def test_two_unquoted_args(self): - s = ur'command hello there' + s = r'command hello there' c = bpd.Command(s) self.assertEqual(c.name, u'command') self.assertEqual(c.args, [u'hello', u'there']) def test_one_quoted_arg(self): - s = ur'command "hello there"' + s = r'command "hello there"' c = bpd.Command(s) self.assertEqual(c.name, u'command') self.assertEqual(c.args, [u'hello there']) def test_heterogenous_args(self): - s = ur'command "hello there" sir' + s = r'command "hello there" sir' c = bpd.Command(s) self.assertEqual(c.name, u'command') self.assertEqual(c.args, [u'hello there', u'sir']) def test_quote_in_arg(self): - s = ur'command "hello \" there"' + s = r'command "hello \" there"' c = bpd.Command(s) self.assertEqual(c.args, [u'hello " there']) def test_backslash_in_arg(self): - s = ur'command "hello \\ there"' + s = r'command "hello \\ there"' c = bpd.Command(s) self.assertEqual(c.args, [u'hello \ there'])