Skip to content

fix: do not delete .mp3 file remuxed from MPEGLAYER3 WAV - #6874

Open
Sanjays2402 wants to merge 1 commit into
beetbox:masterfrom
Sanjays2402:fix/remux-mp3-in-wav-self-delete
Open

fix: do not delete .mp3 file remuxed from MPEGLAYER3 WAV#6874
Sanjays2402 wants to merge 1 commit into
beetbox:masterfrom
Sanjays2402:fix/remux-mp3-in-wav-self-delete

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

Fixes #6748.

remux_mpeglayer3_wav() writes the extracted MP3 stream to path.with_suffix(".mp3") and then removes the source. When the source is already named .mp3 (a WAVE_FORMAT_MPEGLAYER3 file with an mp3 extension, which is exactly the case reported), both paths are identical, so the file it just wrote was immediately deleted and the track was lost. The source is now only removed when it is a distinct path from the remuxed output.

To Do

  • Documentation (no user-facing option changed)
  • Changelog.
  • Tests. (New test_remux_mpeglayer3_wav_mp3_extension fails on master with the file missing and passes with the fix.)

remux_mpeglayer3_wav() writes the extracted MP3 stream to
path.with_suffix('.mp3') and then removes the source. When the source
file is already named .mp3 (a WAVE_FORMAT_MPEGLAYER3 file with an mp3
extension), both paths are identical, so the freshly written file was
immediately deleted and the import silently lost the track.

Only remove the source when it is a distinct path from the remuxed
output. Adds a regression test covering the .mp3-named input.

Closes beetbox#6748
@Sanjays2402
Sanjays2402 requested a review from a team as a code owner July 25, 2026 06:59
Copilot AI review requested due to automatic review settings July 25, 2026 06:59

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

PR fix nasty bug in importer remux path. when WAV-with-MP3-stream file already end in .mp3, code write new bytes then delete same file. PR make delete only happen when output path not same as input. also add regression test + changelog note.

Changes:

  • Guard util.remove() so remux-in-place (.mp3 already) not delete output file
  • Add test case for MPEGLAYER3 WAV stored with .mp3 extension
  • Document fix in changelog (bug #6748)

Reviewed changes

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

File Description
beets/util/extension.py Avoid deleting remuxed output when input and output path are same
test/test_importer.py Add regression test for .mp3-extension MPEGLAYER3 WAV case
docs/changelog.rst Note bugfix in user-visible changelog

Comment thread beets/util/extension.py
Comment on lines +173 to +177
# When the source is already named `.mp3`, it has just been rewritten in
# place with the extracted stream, so there is no separate original left
# to remove.
if mp3_path != syspath:
util.remove(path)
Comment thread test/test_importer.py
Comment on lines +1897 to +1899
def test_remux_mpeglayer3_wav_mp3_extension(self):
"""A MPEGLAYER3 WAV named `.mp3` must not be deleted (#6748)."""
src = _common.RSRC / "mpeglayer3.wav"
Comment thread docs/changelog.rst
Comment on lines +98 to +100
- ``remux_mp3_in_wav`` no longer deletes the imported file when a
MPEGLAYER3 WAV is named ``.mp3``: the remuxed stream was written back to the
same path and then removed as if it were a leftover original. :bug:`6748`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File with .mp3 extension deleted by remux_mp3_in_wav

2 participants