Skip to content

Commit c9cee0d

Browse files
authored
fromfilename: Support 'track' prefix when parsing track number (#6557)
## `fromfilename`: Support `"track"` prefix in track number parsing The `fromfilename` plugin's filename-matching regex is extended to recognise filenames like `track01.m4a` or `track 2.m4a`, where a literal `"track"` prefix precedes the track number.
2 parents 44ffbdf + 2698044 commit c9cee0d

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

beetsplug/fromfilename.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
r"^(?P<artist>.+?)\s*-\s*(?P<title>.+?)(\s*-\s*(?P<tag>.*))?$",
3333
r"^(?P<track>\d+)\.?[\s_-]+(?P<title>.+)$",
3434
r"^(?P<title>.+) by (?P<artist>.+)$",
35-
r"^(?P<track>\d+).*$",
35+
r"^(track ?)?(?P<track>\d+).*$",
3636
r"^(?P<title>.+)$",
3737
]
3838

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ New features
2424
Archives are preserved if any file in the archive was not imported (e.g.
2525
skipped as a duplicate, or the import was aborted), and in non-move import
2626
modes.
27+
- :doc:`plugins/fromfilename`: Support ``track`` prefix when parsing the track
28+
number from the filename (e.g., ``track01.m4a``).
2729

2830
..
2931
Bug fixes

test/plugins/test_fromfilename.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def __init__(self, items):
7070
("/tmp/Song One.m4a", 0, "", "Song One"),
7171
("/tmp/Song Two.m4a", 0, "", "Song Two"),
7272
),
73+
(
74+
("/tmp/track01.m4a", 1, "", "track01"),
75+
("/tmp/track 2.m4a", 2, "", "track 2"),
76+
),
7377
],
7478
)
7579
def test_fromfilename(song1, song2):

0 commit comments

Comments
 (0)