Skip to content

Commit 6c22501

Browse files
committed
Merge pull request #2759 from Vrihub/2738-filename-tracknumber
First tentative fix for issue 2738.
2 parents 15c701d + d0af7a7 commit 6c22501

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

beetsplug/fromfilename.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,21 @@
2727

2828
# Filename field extraction patterns.
2929
PATTERNS = [
30-
# "01 - Track 01" and "01": do nothing
31-
r'^(\d+)\s*-\s*track\s*\d$',
32-
r'^\d+$',
33-
34-
# Useful patterns.
35-
r'^(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$',
36-
r'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$',
37-
r'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)-(?P<tag>.*)$',
38-
r'^(?P<artist>.+)-(?P<title>.+)$',
39-
r'^(?P<track>\d+)\.\s*(?P<artist>.+)-(?P<title>.+)$',
40-
r'^(?P<track>\d+)\s*-\s*(?P<artist>.+)-(?P<title>.+)$',
41-
r'^(?P<track>\d+)\s*-(?P<artist>.+)-(?P<title>.+)$',
42-
r'^(?P<track>\d+)\s(?P<artist>.+)-(?P<title>.+)$',
43-
r'^(?P<title>.+)$',
44-
r'^(?P<track>\d+)\.\s*(?P<title>.+)$',
45-
r'^(?P<track>\d+)\s*-\s*(?P<title>.+)$',
46-
r'^(?P<track>\d+)\s(?P<title>.+)$',
47-
r'^(?P<title>.+) by (?P<artist>.+)$',
30+
# 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<artist>.+)[\-_](?P<title>.+)$',
34+
r'^(?P<track>\d+)[\s.\-_]+(?P<artist>.+)[\-_](?P<title>.+)$',
35+
r'^(?P<title>.+)$',
36+
r'^(?P<track>\d+)[\s.\-_]+(?P<title>.+)$',
37+
r'^(?P<track>\d+)\s+(?P<title>.+)$',
38+
r'^(?P<title>.+) by (?P<artist>.+)$',
39+
r'^(?P<track>\d+).*$',
4840
]
4941

5042
# Titles considered "empty" and in need of replacement.
5143
BAD_TITLE_PATTERNS = [
5244
r'^$',
53-
r'\d+?\s?-?\s*track\s*\d+',
5445
]
5546

5647

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ Fixes:
8888
"Edit Candidates" option is used. :bug:`2734`
8989
* Fix a crash when numeric metadata fields contain just a minus or plus sign
9090
with no following numbers. Thanks to :user:`eigengrau`. :bug:`2741`
91+
* :doc:`/plugins/fromfilename`: Allow file names such as "01.mp3" to extract the track number.
92+
Also allow "_" as a separator. Refactor some regular expressions. :bug:`2738`
9193
* Fixed an issue where images would be resized according to their longest edge,
9294
instead of their width. Thanks to :user:`sekjun9878`. :bug:`2729`
9395

96+
9497
For developers:
9598

9699
* Fixed fields in Album and Item objects are now more strict about translating

0 commit comments

Comments
 (0)