Skip to content
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

Fix extension issue in convert plugin when exporting a playlist #5203

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
15 changes: 11 additions & 4 deletions beetsplug/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ def convert_func(self, lib, opts, args):
items,
)

# If the user supplied a playlist name, create a playlist containing
# all converted titles using this name.
if playlist:
# Playlist paths are understood as relative to the dest directory.
pl_normpath = util.normpath(playlist)
Expand All @@ -615,10 +617,15 @@ def convert_func(self, lib, opts, args):
items_paths = [
os.path.relpath(
util.bytestring_path(
item.destination(
basedir=dest,
path_formats=path_formats,
fragment=False,
# Substitute the before-conversion file extension by
# the after-conversion extension.
replace_ext(
item.destination(
basedir=dest,
path_formats=path_formats,
fragment=False,
),
get_format()[1],
)
),
pl_dir,
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ Bug fixes:
`requests` timeout.
* Fix cover art resizing logic to support multiple steps of resizing
:bug:`5151`
* :doc:`/plugins/convert`: Fix extension substitution inside path of the
exported playlist.

For plugin developers:

Expand Down
13 changes: 13 additions & 0 deletions test/plugins/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ def test_playlist_pretend(self):
m3u_created = os.path.join(self.convert_dest, b"playlist.m3u8")
assert not os.path.exists(m3u_created)

def test_playlist_ext(self):
"""Test correct extension of file inside the playlist when format
conversion occurs."""
# We expect a converted file with the MP3 extension.
self.config["convert"]["format"] = "mp3"
with control_stdin("y"):
self.run_convert("--playlist", "playlist.m3u8")
# Check playlist content.
m3u_created = os.path.join(self.convert_dest, b"playlist.m3u8")
with open(m3u_created, "r") as m3u_file:
assert m3u_file.readline() == "#EXTM3U\n"
assert m3u_file.readline() == "converted.mp3\n"


@_common.slow_test()
class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand):
Expand Down