diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index a3b24b5693..d758c0255a 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -14,8 +14,8 @@ """Generates smart playlists based on beets queries.""" -import json import os +from urllib.parse import quote from urllib.request import pathname2url from beets import ui @@ -327,7 +327,8 @@ def update_playlists(self, lib, pretend=False): if extm3u: attr = [(k, entry.item[k]) for k in keys] al = [ - f" {a[0]}={json.dumps(str(a[1]))}" for a in attr + f" {key}=\"{quote(str(value), safe='/:')}\"" + for key, value in attr ] attrs = "".join(al) comment = "#EXTINF:{}{},{} - {}\n".format( diff --git a/docs/changelog.rst b/docs/changelog.rst index 54d0855990..bcb8135b87 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -81,6 +81,8 @@ Other changes: wrong (outdated) commit. Now the tag is created in the same workflow step right after committing the version update. :bug:`5539` +* :doc:`/plugins/smartplaylist`: URL-encode additional item `fields` within generated + EXTM3U playlists instead of JSON-encoding them. 2.2.0 (December 02, 2024) ------------------------- diff --git a/docs/plugins/smartplaylist.rst b/docs/plugins/smartplaylist.rst index af7a09f033..dd709955b7 100644 --- a/docs/plugins/smartplaylist.rst +++ b/docs/plugins/smartplaylist.rst @@ -97,23 +97,20 @@ In case you want to export additional fields from the beets database into the generated playlists, you can do so by specifying them within the ``fields`` configuration option and setting the ``output`` option to ``extm3u``. For instance the following configuration exports the ``id`` and ``genre`` -fields: +fields:: smartplaylist: playlist_dir: /data/playlists relative_to: /data/playlists output: extm3u fields: - - id - genre - playlists: - - name: all.m3u query: '' -A resulting ``all.m3u`` file could look as follows: +A resulting ``all.m3u`` file could look as follows:: #EXTM3U #EXTINF:805 id="1931" genre="Jazz",Miles Davis - Autumn Leaves diff --git a/test/plugins/test_smartplaylist.py b/test/plugins/test_smartplaylist.py index a50f3e6227..ade745c17d 100644 --- a/test/plugins/test_smartplaylist.py +++ b/test/plugins/test_smartplaylist.py @@ -283,7 +283,7 @@ def test_playlist_update_output_extm3u_fields(self): assert ( content == b"#EXTM3U\n" - + b'#EXTINF:300 id="456" genre="Fake Genre",Fake Artist - fake Title\n' + + b'#EXTINF:300 id="456" genre="Fake%20Genre",Fake Artist - fake Title\n' + b"/tagada.mp3\n" )