-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix ReplayGain metaflac backend altering input files #6916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ludelafo
wants to merge
5
commits into
beetbox:master
Choose a base branch
from
ludelafo:fix-replaygain-metaflac-backend-altering-input-files
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−55
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dcea302
Fix ReplayGain metaflac backend altering input files
ludelafo 526e588
Implement GitHub Copilot feedback
ludelafo 1de1b69
Fix linting issues
ludelafo d36488b
Set issue number in changelog instead of PR number
ludelafo 2a6ada0
Fix unreal peak value in test
ludelafo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import pytest | ||
| from mediafile import MediaFile | ||
|
|
||
| from beets.library import Item | ||
| from beets.test.helper import ( | ||
| AsIsImporterMixin, | ||
| ImportHelper, | ||
|
|
@@ -14,6 +15,7 @@ | |
| FatalGstreamerPluginReplayGainError, | ||
| GStreamerBackend, | ||
| MetaflacBackend, | ||
| RgTask, | ||
| ) | ||
|
|
||
| try: | ||
|
|
@@ -406,16 +408,41 @@ def _add_album(self, *args, **kwargs): | |
| return super()._add_album(*args, **kwargs) | ||
|
|
||
|
|
||
| def test_metaflac_backend_parses_replaygain_tags(): | ||
| def test_metaflac_backend_parses_output(): | ||
| output = ( | ||
| b"REPLAYGAIN_TRACK_GAIN=-11.55 dB\nREPLAYGAIN_TRACK_PEAK=0.99998772\n" | ||
| "01.flac: -1.234567 0.123456 1.987654 0.456789\n" | ||
| "02.flac: -1.234567 0.123456 -1.987654 0.987654\n" | ||
| ) | ||
|
Comment on lines
412
to
415
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll fix this in my next commit. |
||
| tags = MetaflacBackend._parse_tags(output) | ||
| assert MetaflacBackend._parse_gain(tags["REPLAYGAIN_TRACK_GAIN"]) == ( | ||
| pytest.approx(-11.55) | ||
| ) | ||
| assert float(tags["REPLAYGAIN_TRACK_PEAK"]) == pytest.approx(0.99998772) | ||
| assert MetaflacBackend._parse_gain("+4.56 dB") == pytest.approx(4.56) | ||
|
|
||
| results = MetaflacBackend._parse_output(output) | ||
|
|
||
| assert set(results) == {"01.flac", "02.flac"} | ||
|
|
||
| album_gain_1, album_peak_1, track_gain_1, track_peak_1 = results["01.flac"] | ||
| album_gain_2, album_peak_2, track_gain_2, track_peak_2 = results["02.flac"] | ||
|
|
||
| # Album gain/peak is shared across every file in the batch... | ||
| assert album_gain_1 == pytest.approx(album_gain_2) | ||
| assert album_peak_1 == pytest.approx(album_peak_2) | ||
|
|
||
| # ...but each file keeps its own distinct track gain/peak. | ||
| assert track_gain_1 == pytest.approx(1.987654) | ||
| assert track_peak_1 == pytest.approx(0.456789) | ||
|
|
||
| assert track_gain_2 == pytest.approx(-1.987654) | ||
| assert track_peak_2 == pytest.approx(0.987654) | ||
|
|
||
|
|
||
| def test_metaflac_backend_cannot_compute_album_gain_with_mixed_formats(): | ||
| backend = MetaflacBackend.__new__(MetaflacBackend) | ||
|
|
||
| items = [Item(format="FLAC"), Item(format="MP3"), Item(format="FLAC")] | ||
| task = RgTask(items, None, 89.0, None, "metaflac", None) | ||
|
|
||
| result = backend.compute_album_gain(task) | ||
|
|
||
| assert result.track_gains is None | ||
| assert result.album_gain is None | ||
|
|
||
|
|
||
| class ImportTest(AsIsImporterMixin): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just occurred to me that my current implementation might not be the cleanest.
With the current implementation, if multiple tracks are passed to the
compute_track_gainfunction, it will calculate the album gain across all tracks, even though they are not in the same album (e.g. singletons).The next implementation partially reverts to the previous implementation, fixing this issue:
If my assumptions are correct, I can rebase with the main branch and push this new commit.