Skip to content

Commit 84cf336

Browse files
committed
Refactored some regular expressions. Added changelog entry
Some more changes to the regular expressions in the "PATTERNS" list. Also allow "_" as a separator, where only "-" was allowed. Replaced similar regexps containing different combinations of \s, "-", "." with a single regexp using a set of characters [\s.\-_].
1 parent 7132ad0 commit 84cf336

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

beetsplug/fromfilename.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,20 @@
2828
# Filename field extraction patterns.
2929
PATTERNS = [
3030
# Useful patterns.
31-
r'^(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$',
32-
r'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$',
33-
r'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$',
34-
r'^(?P<artist>.+)-(?P<title>.+)$',
35-
r'^(?P<track>\d+)\.\s*(?P<artist>.+)-(?P<title>.+)$',
36-
r'^(?P<track>\d+)\s*-\s*(?P<artist>.+)-(?P<title>.+)$',
37-
r'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)$',
38-
r'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)$',
31+
r'^(?P<artist>.+)[\-_](?P<title>.+)[\-_](?P<tag>.*)$',
32+
r'^(?P<track>\d+)[\s.\-_]+(?P<artist>.+)[\-_](?P<title>.+)[\-_](?P<tag>.*)$',
33+
r'^(?P<artist>.+)[\-_](?P<title>.+)$',
34+
r'^(?P<track>\d+)[\s.\-_]+(?P<artist>.+)[\-_](?P<title>.+)$',
3935
r'^(?P<title>.+)$',
40-
r'^(?P<track>\d+)\.\s*(?P<title>.+)$',
41-
r'^(?P<track>\d+)\s*-\s*(?P<title>.+)$',
42-
r'^(?P<track>\d+)\s(?P<title>.+)$',
36+
r'^(?P<track>\d+)[\s.\-_]+(?P<title>.+)$',
37+
r'^(?P<track>\d+)\s+(?P<title>.+)$',
4338
r'^(?P<title>.+) by (?P<artist>.+)$',
4439
r'^(?P<track>\d+).*$',
4540
]
4641

4742
# Titles considered "empty" and in need of replacement.
4843
BAD_TITLE_PATTERNS = [
4944
r'^$',
50-
r'\d+?\s?-?\s*track\s*\d+',
5145
]
5246

5347

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Fixes:
8080
"Edit Candidates" option is used. :bug:`2734`
8181
* Fix a crash when numeric metadata fields contain just a minus or plus sign
8282
with no following numbers. Thanks to :user:`eigengrau`. :bug:`2741`
83+
* :doc:`/plugins/fromfilename`: Allow file names such as "01.mp3" to extract the track number.
84+
Also allow "_" as a separator. Refactor some regular expressions. :bug:`2738`
8385

8486
For developers:
8587

0 commit comments

Comments
 (0)