Skip to content

Fix ReplayGain metaflac backend altering input files - #6916

Open
ludelafo wants to merge 5 commits into
beetbox:masterfrom
ludelafo:fix-replaygain-metaflac-backend-altering-input-files
Open

Fix ReplayGain metaflac backend altering input files#6916
ludelafo wants to merge 5 commits into
beetbox:masterfrom
ludelafo:fix-replaygain-metaflac-backend-altering-input-files

Conversation

@ludelafo

@ludelafo ludelafo commented Aug 8, 2026

Copy link
Copy Markdown

Description

Fixes #6915.

I was able to try out this PR and it works as expected. The ReplayGain tags are now only written to the copy of the file in the library, and not to the original file that was imported from.

To Do

  • Documentation.
  • Changelog.
  • Tests.

Remaining questions

As this is my first contribution to beets and that I do not consider myself very experienced with Python, I would like to ask for feedback on the following:

  • Should I have updated the documentation to indicate the minimum version required for metaflac? Would you like me to put it somewhere else/in another way?
  • Should I add a check if the --scan-replay-gain option is available and throw a FatalReplayGainError exception if not, or is it sufficient to mention it in the documentation? - GitHub Copilot seems to have answered my question.
  • Should I use more Pythonic code to create the track_gains list? I find the current implementation more readable, but I am not sure if it is the best practice.

Thank you for your time and for reviewing my PR.

AI disclaimer

I have used AI to help me write this PR.

Copilot AI lite review requested due to automatic review settings August 8, 2026 16:43
@ludelafo
ludelafo requested a review from a team as a code owner August 8, 2026 16:43
@github-actions github-actions Bot added the replaygain replaygain plugin label Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fix ReplayGain metaflac backend so it no longer write ReplayGain tags into input/source files during import. It switch to reading gain data via metaflac --scan-replay-gain output, then write tags only when beets later writes library file.

Changes:

  • Switch MetaflacBackend from --add-replay-gain + tag readback to --scan-replay-gain + stdout parsing.
  • Update docs to note FLAC tools version requirement for metaflac backend.
  • Update tests to cover new --scan-replay-gain output parsing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
beetsplug/replaygain.py Use --scan-replay-gain, parse its output, and compute album/track Gain without mutating files.
docs/plugins/replaygain.rst Document minimum FLAC tools version for metaflac backend.
test/plugins/test_replaygain.py Update unit test to validate new metaflac output parsing behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread beetsplug/replaygain.py Outdated
Comment on lines +685 to +689
track_gains = []
for item in filter(self.format_supported, task.items):
self._add_replay_gain([item])
track_gains.append(
self._read_gain(item, "TRACK", task.target_level)
)
result = self._read_gain([item], task.target_level)

track_gain_value = result[item][1]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll fix this in my next commit.

Comment thread beetsplug/replaygain.py Outdated
Comment on lines +719 to +723
"""Run ``metaflac --scan-replay-gain`` on the given files"""
paths = [str(item.filepath) for item in items]
call([self.command, "--add-replay-gain", *paths], self._log)
output = call(
[self.command, "--scan-replay-gain", *paths], self._log
).stdout.decode("utf-8", "ignore")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll fix this in my next commit.

Comment on lines 410 to 413
output = (
b"REPLAYGAIN_TRACK_GAIN=-11.55 dB\nREPLAYGAIN_TRACK_PEAK=0.99998772\n"
"01.flac: -1.234567 1.234567 1.987654 -1.987654\n"
"02.flac: -1.234567 1.234567 -1.987654 1.987654\n"
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll fix this in my next commit.

Comment thread beetsplug/replaygain.py
Comment on lines +728 to +732
for item in items:
path = str(item.filepath)

album_gain, album_peak, track_gain, track_peak = gain_by_path[path]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll fix this in my next commit.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.08696% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.68%. Comparing base (74c2d98) to head (2a6ada0).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/replaygain.py 76.08% 9 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6916      +/-   ##
==========================================
- Coverage   75.69%   75.68%   -0.01%     
==========================================
  Files         163      163              
  Lines       21412    21428      +16     
  Branches     3384     3387       +3     
==========================================
+ Hits        16208    16218      +10     
- Misses       4405     4410       +5     
- Partials      799      800       +1     
Files with missing lines Coverage Δ
beetsplug/replaygain.py 47.19% <76.08%> (+0.60%) ⬆️

... and 1 file 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

test/plugins/test_replaygain.py:414

  • grug see test use album_peak 1.234567, but code say peak part of full scale (FS is 1.0). peak > 1.0 not real and make reader confuse. grug want peak <= 1.0 in sample output.
        "01.flac: -1.234567 1.234567 1.987654 0.123456\n"
        "02.flac: -1.234567 1.234567 -1.987654 0.987654\n"

docs/changelog.rst:54

  • grug see changelog say 🐛6916 but PR say fix #6915. wrong bug number make release note point wrong place. grug want use 6915.
- :doc:`plugins/replaygain`: Fix ReplayGain metaflac backend altering input
  files. :bug:`6916`

@ludelafo

ludelafo commented Aug 8, 2026

Copy link
Copy Markdown
Author

I have fixed all elements raised by GitHub Copilot. I did try to stay consistent and to keep it simple.

Furthermore, I left the conversation opened by GitHub Copilot as-is so you can close them when reviewing the changes I made from its input.

Let me know if you need other changes.

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

Labels

replaygain replaygain plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReplayGain metaflac backend alters input files

2 participants