Skip to content

Commit

Permalink
Refactored some regular expressions. Added changelog entry
Browse files Browse the repository at this point in the history
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.\-_].
  • Loading branch information
Vrihub committed Dec 21, 2017
1 parent 7132ad0 commit 84cf336
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 6 additions & 12 deletions beetsplug/fromfilename.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,20 @@
# Filename field extraction patterns.
PATTERNS = [
# Useful patterns.
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<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<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<track>\d+)[\s.\-_]+(?P<title>.+)$',
r'^(?P<track>\d+)\s+(?P<title>.+)$',
r'^(?P<title>.+) by (?P<artist>.+)$',
r'^(?P<track>\d+).*$',
]

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


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

For developers:

Expand Down

0 comments on commit 84cf336

Please sign in to comment.