Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion beets/util/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ def remux_mpeglayer3_wav(path: AnyPath) -> AnyPath | None:
mp3_path = syspath.with_suffix(".mp3")
mp3_path.write_bytes(mp3_data)

util.remove(path)
# When the source already has an `.mp3` extension, it has just been
# rewritten in place with the extracted stream, so there is no separate
# original left to remove. Compare with `samefile` so that a case-only
# difference on a case-insensitive filesystem is caught too.
if not util.samefile(mp3_path, syspath):
util.remove(path)

if isinstance(path, str):
return str(mp3_path)
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Bug fixes
valid date/time string" error instead of crashing with an uncaught
``KeyError``. A ``|`` was being accepted as a relative-date unit due to a
regular expression character-class typo.
- ``remux_mp3_in_wav`` no longer deletes the imported file when a
MPEGLAYER3 WAV has an ``.mp3`` extension: the remuxed stream was written back
to the same path and then removed as if it were a leftover original.
:bug:`6748`

..
For plugin developers
Expand Down
26 changes: 26 additions & 0 deletions test/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,32 @@ def test_remux_mpeglayer3_wav(self):
assert mp3_path.exists()
assert not dest.exists()

def test_remux_mpeglayer3_wav_mp3_extension(self):
"""A MPEGLAYER3 WAV with an `.mp3` extension must not be deleted.

See #6748.
"""
src = _common.RSRC / "mpeglayer3.wav"
dest = self.temp_path / "mpeglayer3.mp3"
shutil.copy(syspath(src), syspath(dest))

mp3_path = remux_mpeglayer3_wav(dest)

assert mp3_path == dest
assert dest.exists()

def test_remux_mpeglayer3_wav_mp3_extension_uppercase(self):
"""The same holds when the extension differs only by case."""
src = _common.RSRC / "mpeglayer3.wav"
dest = self.temp_path / "mpeglayer3.MP3"
shutil.copy(syspath(src), syspath(dest))

mp3_path = remux_mpeglayer3_wav(dest)

assert dest.exists()
assert mp3_path is not None
assert mp3_path.exists()

def test_remux_mpeglayer3_wav_disabled(self):
"""When remux_mp3_in_wav is disabled, WAV file should not be remuxed."""
self.config["import"]["remux_mp3_in_wav"] = False
Expand Down
Loading