Repository navigation
fromfilename: refactor and type - #7130
henry-oberholtzer wants to merge 2 commits into
Conversation
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7130 +/- ##
==========================================
- Coverage 80.63% 80.54% -0.10%
==========================================
Files 149 149
Lines 21254 21267 +13
Branches 3284 3285 +1
==========================================
- Hits 17139 17129 -10
- Misses 3288 3306 +18
- Partials 827 832 +5
🚀 New features to boost your workflow:
|
snejus
left a comment
There was a problem hiding this comment.
Thanks for splitting #6259 up - this is much easier to follow! Given that most of the code here gets reworked further up the stack, I checked both this PR and the end of the stack (#7135) against a few filenames, and only commented on things that are still there at the end.
The [\.\-by] character class in this PR breaks 01. Hey Jude (artist He, title y Jude), 03 Abbey Road and 02 Baby, but I see #7131 fixes it. Would you mind to move that fix into this commit, so that each PR in the stack is correct by itself? Same for the title = 'None' issue with 1-01.mp3 + 1-02.mp3, which FilenameMatch sorts out later.
I'm also thinking it may be worth to merge all your PRs into a temporary master-like base branch, say fromfilename-refactor?
| # Copyright 2016, Jan-Erik Dahlin | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining | ||
| # a copy of this software and associated documentation files (the |
| RE_TRACK_INFO = re.compile( | ||
| r""" | ||
| (?P<disc>\d+(?=[\.\-_]\d))? | ||
| # a disc must be followed by punctuation and a digit | ||
| [\.\-]{,1} | ||
| # disc punctuation | ||
| (?P<track>\d+)? | ||
| # match the track number | ||
| [\.\-_\s]* | ||
| # artist separators | ||
| (?P<artist>.+?(?=[\s*_]?[\.\-by].+))? | ||
| # artist match depends on title existing | ||
| [\.\-_\s]* | ||
| (?P<by>by)? | ||
| # if 'by' is found, artist and title will need to be swapped | ||
| [\.\-_\s]* | ||
| # title separators | ||
| (?P<title>.+)? | ||
| # match the track title | ||
| """, | ||
| re.VERBOSE | re.IGNORECASE, | ||
| ) |
There was a problem hiding this comment.
Can we move the comments inline, like this?
| RE_TRACK_INFO = re.compile( | |
| r""" | |
| (?P<disc>\d+(?=[\.\-_]\d))? | |
| # a disc must be followed by punctuation and a digit | |
| [\.\-]{,1} | |
| # disc punctuation | |
| (?P<track>\d+)? | |
| # match the track number | |
| [\.\-_\s]* | |
| # artist separators | |
| (?P<artist>.+?(?=[\s*_]?[\.\-by].+))? | |
| # artist match depends on title existing | |
| [\.\-_\s]* | |
| (?P<by>by)? | |
| # if 'by' is found, artist and title will need to be swapped | |
| [\.\-_\s]* | |
| # title separators | |
| (?P<title>.+)? | |
| # match the track title | |
| """, | |
| re.VERBOSE | re.IGNORECASE, | |
| ) | |
| RE_TRACK_INFO = re.compile( | |
| r""" | |
| (?P<disc>\d+(?=[\.\-_]\d))? # a disc must be followed by punctuation and a digit | |
| [\.\-]{,1} # disc punctuation | |
| (?P<track>\d+)? # match the track number | |
| [\.\-_\s]* # artist separators | |
| (?P<artist>.+?(?=[\s*_]?[\.\-by].+))? # artist match depends on title existing | |
| [\.\-_\s]* | |
| (?P<by>by)? # if 'by' is found, artist and title will need to be swapped | |
| [\.\-_\s]* # title separators | |
| (?P<title>.+)? # match the track title | |
| """, # noqa: E501 | |
| re.VERBOSE | re.IGNORECASE, | |
| ) | |
| # match the track number | ||
| [\.\-_\s]* | ||
| # artist separators | ||
| (?P<artist>.+?(?=[\s*_]?[\.\-by].+))? |
There was a problem hiding this comment.
[\.\-by] is a character class, so this lookahead matches any b or y in the name, not the word by. This is why 01. Hey Jude turns into artist He and title y Jude. The (?P<by>by)? group below then swallows these letters as well (02 Baby -> Ba).
| ("/tmp/Song Two.m4a", 0, "", "Song Two"), | ||
| ), | ||
| ( | ||
| ("/tmp/track01.m4a", 1, "", "track01"), |
| keys = some_map.keys() | ||
|
|
||
| # Only proceed if the "tag" field is equal across all filenames. | ||
| if "tag" in keys and not equal_fields(d, "tag"): |
There was a problem hiding this comment.
Seems like the tag group is gone from the regex?
Description
Refactor the structure of the FromFilename plugin to class methods with full typing.
To Do
docs/to describe it.)docs/changelog.rstto the bottom of one of the lists near the top of the document.)Gemini was used to split this into a stack - but all code was written manually.
Stack created with GitHub Stacks CLI • Give Feedback 💬