Skip to content

fromfilename: refactor and type - #7130

Open
henry-oberholtzer wants to merge 2 commits into
masterfrom
fromfilename/1-refactor-and-type
Open

henry-oberholtzer wants to merge 2 commits into
masterfrom
fromfilename/1-refactor-and-type

Conversation

@henry-oberholtzer

Copy link
Copy Markdown
Member

Description

Refactor the structure of the FromFilename plugin to class methods with full typing.

To Do

  • Documentation. (If you've added a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

Gemini was used to split this into a stack - but all code was written manually.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@henry-oberholtzer
henry-oberholtzer requested a review from a team as a code owner October 31, 2026 00:34
@github-actions github-actions Bot added the fromfilename fromfilename plugin label Oct 31, 2026
@github-actions

Copy link
Copy Markdown

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

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.86207% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.54%. Comparing base (ab4bdfd) to head (ce96be1).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/fromfilename.py 75.86% 8 Missing and 6 partials ⚠️
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     
Files with missing lines Coverage Δ
beetsplug/fromfilename.py 72.28% <75.86%> (-20.57%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snejus snejus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread beetsplug/fromfilename.py
# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this header any more

Comment thread beetsplug/fromfilename.py
Comment on lines +32 to +53
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,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the comments inline, like this?

Suggested change
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,
)

Comment thread beetsplug/fromfilename.py
# match the track number
[\.\-_\s]*
# artist separators
(?P<artist>.+?(?=[\s*_]?[\.\-by].+))?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[\.\-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"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two removed?

Comment thread beetsplug/fromfilename.py
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"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the tag group is gone from the regex?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fromfilename fromfilename plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants